Skip to content

Commit 7c5e96b

Browse files
committed
[py] Fix custom locator tests
1 parent fcc0932 commit 7c5e96b

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

py/test/selenium/webdriver/remote/custom_element_tests.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ def custom_method(self):
2929

3030
@pytest.fixture()
3131
def custom_element_driver(driver):
32-
driver._web_element_cls = MyCustomElement
33-
yield driver
34-
driver._web_element_cls = WebElement
32+
try:
33+
driver._web_element_cls = MyCustomElement
34+
yield driver
35+
finally:
36+
driver._web_element_cls = WebElement
3537

3638

3739
def test_find_element_with_custom_class(custom_element_driver, pages):

py/test/selenium/webdriver/remote/remote_custom_locator_tests.py

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
import pytest
1919

20+
from selenium import webdriver
21+
from selenium.webdriver.firefox.options import Options
2022
from selenium.webdriver.remote.locator_converter import LocatorConverter
2123

2224

@@ -28,18 +30,28 @@ def convert(self, by, value):
2830
return super().convert(by, value)
2931

3032

31-
@pytest.mark.skip(reason="Needs to be updated")
32-
def test_find_element_with_custom_locator(driver):
33-
driver.get("data:text/html,<div custom-attr='example'>Test</div>")
34-
element = driver.find_element("custom", "example")
33+
@pytest.fixture()
34+
def custom_locator_driver(headless):
35+
options = Options()
36+
if headless:
37+
options.add_argument("-headless")
38+
try:
39+
driver = webdriver.Remote(options=options, locator_converter=CustomLocatorConverter())
40+
yield driver
41+
finally:
42+
driver.quit()
43+
44+
45+
def test_find_element_with_custom_locator(custom_locator_driver):
46+
custom_locator_driver.get("data:text/html,<div custom-attr='example'>Test</div>")
47+
element = custom_locator_driver.find_element("custom", "example")
3548
assert element is not None
3649
assert element.text == "Test"
3750

3851

39-
@pytest.mark.skip(reason="Needs to be updated")
40-
def test_find_elements_with_custom_locator(driver):
41-
driver.get("data:text/html,<div custom-attr='example'>Test1</div><div custom-attr='example'>Test2</div>")
42-
elements = driver.find_elements("custom", "example")
52+
def test_find_elements_with_custom_locator(custom_locator_driver):
53+
custom_locator_driver.get("data:text/html,<div custom-attr='example'>Test1</div><div custom-attr='example'>Test2</div>")
54+
elements = custom_locator_driver.find_elements("custom", "example")
4355
assert len(elements) == 2
4456
assert elements[0].text == "Test1"
4557
assert elements[1].text == "Test2"

0 commit comments

Comments
 (0)