diff --git a/py/test/selenium/webdriver/chrome/chrome_execute_cdp_cmd_tests.py b/py/test/selenium/webdriver/chrome/chrome_execute_cdp_cmd_tests.py index e6bd5f26ea0d7..2400861ac0ff0 100644 --- a/py/test/selenium/webdriver/chrome/chrome_execute_cdp_cmd_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_execute_cdp_cmd_tests.py @@ -20,6 +20,6 @@ def test_execute_cdp_cmd(): driver = Chrome() - version_info = driver.execute_cdp_cmd('Browser.getVersion', {}) + version_info = driver.execute_cdp_cmd("Browser.getVersion", {}) assert isinstance(version_info, dict) - assert 'userAgent' in version_info + assert "userAgent" in version_info diff --git a/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py b/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py index d85298b1ca772..198c6232c31ae 100755 --- a/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py +++ b/py/test/selenium/webdriver/chrome/chrome_network_emulation_tests.py @@ -22,15 +22,12 @@ def test_network_conditions_emulation(): driver = Chrome() - driver.set_network_conditions( - offline=False, - latency=56, # additional latency (ms) - throughput=789) + driver.set_network_conditions(offline=False, latency=56, throughput=789) # additional latency (ms) conditions = driver.get_network_conditions() - assert conditions['offline'] is False - assert conditions['latency'] == 56 - assert conditions['download_throughput'] == 789 - assert conditions['upload_throughput'] == 789 + assert conditions["offline"] is False + assert conditions["latency"] == 56 + assert conditions["download_throughput"] == 789 + assert conditions["upload_throughput"] == 789 driver.delete_network_conditions() with pytest.raises(WebDriverException): driver.get_network_conditions() diff --git a/py/test/selenium/webdriver/chrome/conftest.py b/py/test/selenium/webdriver/chrome/conftest.py index 75670927e31e3..043b7df7e146f 100644 --- a/py/test/selenium/webdriver/chrome/conftest.py +++ b/py/test/selenium/webdriver/chrome/conftest.py @@ -17,5 +17,5 @@ def pytest_generate_tests(metafunc): - if 'driver' in metafunc.fixturenames and metafunc.config.option.drivers: - metafunc.parametrize('driver', metafunc.config.option.drivers, indirect=True) + if "driver" in metafunc.fixturenames and metafunc.config.option.drivers: + metafunc.parametrize("driver", metafunc.config.option.drivers, indirect=True) diff --git a/py/test/selenium/webdriver/chrome/options_tests.py b/py/test/selenium/webdriver/chrome/options_tests.py index a35ce80671de8..e3cdd0a85c932 100644 --- a/py/test/selenium/webdriver/chrome/options_tests.py +++ b/py/test/selenium/webdriver/chrome/options_tests.py @@ -24,7 +24,7 @@ def test_w3c_true(): options = webdriver.ChromeOptions() options.add_experimental_option("w3c", True) - chrome_kwargs = {'options': options} + chrome_kwargs = {"options": options} with pytest.warns(DeprecationWarning, match="Setting 'w3c: True' is redundant"): driver = webdriver.Chrome(**chrome_kwargs) @@ -36,7 +36,7 @@ def test_w3c_false(): options = webdriver.ChromeOptions() options.add_experimental_option("w3c", False) - chrome_kwargs = {'options': options} + chrome_kwargs = {"options": options} with pytest.raises(AttributeError): webdriver.Chrome(**chrome_kwargs) diff --git a/py/test/selenium/webdriver/chrome/proxy_tests.py b/py/test/selenium/webdriver/chrome/proxy_tests.py index f29684396e6ba..bdf8d463f5a3f 100644 --- a/py/test/selenium/webdriver/chrome/proxy_tests.py +++ b/py/test/selenium/webdriver/chrome/proxy_tests.py @@ -25,18 +25,18 @@ def test_bad_proxy_doesnt_interfere(): # these values should be ignored if ignore_local_proxy_environment_variables() is called. - os.environ['https_proxy'] = 'bad' - os.environ['http_proxy'] = 'bad' + os.environ["https_proxy"] = "bad" + os.environ["http_proxy"] = "bad" options = webdriver.ChromeOptions() options.ignore_local_proxy_environment_variables() - chrome_kwargs = {'options': options} + chrome_kwargs = {"options": options} driver = webdriver.Chrome(**chrome_kwargs) - assert hasattr(driver, 'command_executor') - assert hasattr(driver.command_executor, '_proxy_url') + assert hasattr(driver, "command_executor") + assert hasattr(driver.command_executor, "_proxy_url") assert type(driver.command_executor._conn) == urllib3.PoolManager - os.environ.pop('https_proxy') - os.environ.pop('http_proxy') + os.environ.pop("https_proxy") + os.environ.pop("http_proxy") driver.quit() diff --git a/py/test/selenium/webdriver/common/alerts_tests.py b/py/test/selenium/webdriver/common/alerts_tests.py index 876e74421d1bc..04dff8e029272 100644 --- a/py/test/selenium/webdriver/common/alerts_tests.py +++ b/py/test/selenium/webdriver/common/alerts_tests.py @@ -38,11 +38,10 @@ def close_alert(driver): def test_should_be_able_to_override_the_window_alert_method(driver, pages): pages.load("alerts.html") - driver.execute_script( - "window.alert = function(msg) { document.getElementById('text').innerHTML = msg; }") + driver.execute_script("window.alert = function(msg) { document.getElementById('text').innerHTML = msg; }") driver.find_element(by=By.ID, value="alert").click() try: - assert driver.find_element(By.ID, 'text').text == "cheese" + assert driver.find_element(By.ID, "text").text == "cheese" except Exception as e: # if we're here, likely the alert is displayed # not dismissing it will affect other tests @@ -140,13 +139,11 @@ def test_setting_the_value_of_an_alert_throws(driver, pages): @pytest.mark.xfail_chrome( - condition=sys.platform == 'darwin', - reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=26', - run=False) + condition=sys.platform == "darwin", reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=26", run=False +) @pytest.mark.xfail_chromiumedge( - condition=sys.platform == 'darwin', - reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=26', - run=False) + condition=sys.platform == "darwin", reason="https://bugs.chromium.org/p/chromedriver/issues/detail?id=26", run=False +) def test_alert_should_not_allow_additional_commands_if_dimissed(driver, pages): pages.load("alerts.html") driver.find_element(By.ID, "alert").click() @@ -158,8 +155,8 @@ def test_alert_should_not_allow_additional_commands_if_dimissed(driver, pages): alert.text -@pytest.mark.xfail_firefox(reason='Fails on travis') -@pytest.mark.xfail_remote(reason='Fails on travis') +@pytest.mark.xfail_firefox(reason="Fails on travis") +@pytest.mark.xfail_remote(reason="Fails on travis") @pytest.mark.xfail_safari def test_should_allow_users_to_accept_an_alert_in_aframe(driver, pages): pages.load("alerts.html") @@ -172,8 +169,8 @@ def test_should_allow_users_to_accept_an_alert_in_aframe(driver, pages): assert "Testing Alerts" == driver.title -@pytest.mark.xfail_firefox(reason='Fails on travis') -@pytest.mark.xfail_remote(reason='Fails on travis') +@pytest.mark.xfail_firefox(reason="Fails on travis") +@pytest.mark.xfail_remote(reason="Fails on travis") @pytest.mark.xfail_safari def test_should_allow_users_to_accept_an_alert_in_anested_frame(driver, pages): pages.load("alerts.html") @@ -247,11 +244,13 @@ def test_should_handle_alert_on_page_load_using_get(driver, pages): alert.accept() assert "onload" == value - WebDriverWait(driver, 3).until(EC.text_to_be_present_in_element((By.TAG_NAME, "p"), "Page with onload event handler")) + WebDriverWait(driver, 3).until( + EC.text_to_be_present_in_element((By.TAG_NAME, "p"), "Page with onload event handler") + ) -@pytest.mark.xfail_chrome(reason='Non W3C conformant') -@pytest.mark.xfail_chromiumedge(reason='Non W3C conformant') +@pytest.mark.xfail_chrome(reason="Non W3C conformant") +@pytest.mark.xfail_chromiumedge(reason="Non W3C conformant") def test_should_handle_alert_on_page_before_unload(driver, pages): pages.load("pageWithOnBeforeUnloadMessage.html") @@ -291,10 +290,8 @@ def test_alert_should_not_allow_additional_commands_if_dismissed(driver, pages): alert.text -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1279211') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1279211') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1279211") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1279211") @pytest.mark.xfail_chrome def test_unexpected_alert_present_exception_contains_alert_text(driver, pages): pages.load("alerts.html") diff --git a/py/test/selenium/webdriver/common/api_example_tests.py b/py/test/selenium/webdriver/common/api_example_tests.py index 48ebe27ce1514..48bb6fef4ccb2 100644 --- a/py/test/selenium/webdriver/common/api_example_tests.py +++ b/py/test/selenium/webdriver/common/api_example_tests.py @@ -34,7 +34,7 @@ def test_get_title(driver, pages): def test_get_current_url(driver, pages, webserver): pages.load("simpleTest.html") url = driver.current_url - assert webserver.where_is('simpleTest.html') == url + assert webserver.where_is("simpleTest.html") == url def test_find_element_by_xpath(driver, pages): @@ -161,11 +161,11 @@ def test_navigate(driver, pages): def test_get_attribute(driver, pages): - url = pages.url('xhtmlTest.html') + url = pages.url("xhtmlTest.html") driver.get(url) elem = driver.find_element(By.ID, "id1") attr = elem.get_attribute("href") - assert f'{url}#' == attr + assert f"{url}#" == attr def test_get_implicit_attribute(driver, pages): @@ -177,7 +177,7 @@ def test_get_implicit_attribute(driver, pages): def test_get_dom_attribute(driver, pages): - url = pages.url('formPage.html') + url = pages.url("formPage.html") driver.get(url) elem = driver.find_element(By.ID, "vsearchGadget") attr = elem.get_dom_attribute("accesskey") @@ -185,7 +185,7 @@ def test_get_dom_attribute(driver, pages): def test_get_property(driver, pages): - url = pages.url('formPage.html') + url = pages.url("formPage.html") driver.get(url) elem = driver.find_element(By.ID, "withText") prop = elem.get_property("value") @@ -212,15 +212,16 @@ def test_execute_script_with_args(driver, pages): def test_execute_script_with_multiple_args(driver, pages): pages.load("xhtmlTest.html") - result = driver.execute_script( - "return arguments[0] + arguments[1]", 1, 2) + result = driver.execute_script("return arguments[0] + arguments[1]", 1, 2) assert 3 == result def test_execute_script_with_element_args(driver, pages): pages.load("javascriptPage.html") button = driver.find_element(By.ID, "plainButton") - result = driver.execute_script("arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button) + result = driver.execute_script( + "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble'];", button + ) assert "plainButton" == result @@ -246,28 +247,28 @@ def test_move_window_position(driver, pages): # because of system toolbars new_x = 50 new_y = 50 - if loc['x'] == new_x: + if loc["x"] == new_x: new_x += 10 - if loc['y'] == new_y: + if loc["y"] == new_y: new_y += 10 driver.set_window_position(new_x, new_y) loc = driver.get_window_position() - assert loc['x'] == new_x - assert loc['y'] == new_y + assert loc["x"] == new_x + assert loc["y"] == new_y def test_change_window_size(driver, pages): pages.load("blank.html") size = driver.get_window_size() newSize = [600, 600] - if size['width'] == 600: + if size["width"] == 600: newSize[0] = 500 - if size['height'] == 600: + if size["height"] == 600: newSize[1] = 500 driver.set_window_size(newSize[0], newSize[1]) size = driver.get_window_size() - assert size['width'] == newSize[0] - assert size['height'] == newSize[1] + assert size["width"] == newSize[0] + assert size["height"] == newSize[1] @pytest.mark.xfail_firefox(raises=WebDriverException) diff --git a/py/test/selenium/webdriver/common/bidi_tests.py b/py/test/selenium/webdriver/common/bidi_tests.py index b44f48c11c494..a0c02cf8fc9ca 100644 --- a/py/test/selenium/webdriver/common/bidi_tests.py +++ b/py/test/selenium/webdriver/common/bidi_tests.py @@ -29,6 +29,7 @@ async def test_check_console_messages(driver, pages): log = Log(driver, session) pages.load("javascriptPage.html") from selenium.webdriver.common.bidi.console import Console + async with log.add_listener(Console.ALL) as messages: driver.execute_script("console.log('I love cheese')") assert messages["message"] == "I love cheese" @@ -40,8 +41,9 @@ async def test_check_error_console_messages(driver, pages): log = Log(driver, session) pages.load("javascriptPage.html") from selenium.webdriver.common.bidi.console import Console + async with log.add_listener(Console.ERROR) as messages: - driver.execute_script("console.error(\"I don't cheese\")") + driver.execute_script('console.error("I don\'t cheese")') driver.execute_script("console.log('I love cheese')") assert messages["message"] == "I don't cheese" @@ -68,8 +70,9 @@ async def test_collect_log_mutations(driver, pages): async with log.mutation_events() as event: pages.load("dynamic.html") driver.find_element(By.ID, "reveal").click() - WebDriverWait(driver, 5, ignored_exceptions=InvalidSelectorException)\ - .until(EC.visibility_of(driver.find_element(By.ID, "revealed"))) + WebDriverWait(driver, 5, ignored_exceptions=InvalidSelectorException).until( + EC.visibility_of(driver.find_element(By.ID, "revealed")) + ) assert event["attribute_name"] == "style" assert event["current_value"] == "" diff --git a/py/test/selenium/webdriver/common/click_scrolling_tests.py b/py/test/selenium/webdriver/common/click_scrolling_tests.py index 1c67f66094f16..5e20a5fc7ca53 100644 --- a/py/test/selenium/webdriver/common/click_scrolling_tests.py +++ b/py/test/selenium/webdriver/common/click_scrolling_tests.py @@ -110,10 +110,8 @@ def test_should_scroll_overflow_elements_if_click_point_is_out_of_view_but_eleme assert "clicked" == driver.find_element(By.ID, "clicked").text -@pytest.mark.xfail_firefox( - reason='https://github.com/w3c/webdriver/issues/408') -@pytest.mark.xfail_remote( - reason='https://github.com/w3c/webdriver/issues/408') +@pytest.mark.xfail_firefox(reason="https://github.com/w3c/webdriver/issues/408") +@pytest.mark.xfail_remote(reason="https://github.com/w3c/webdriver/issues/408") @pytest.mark.xfail_safari def test_should_be_able_to_click_element_in_aframe_that_is_out_of_view(driver, pages): pages.load("scrolling_tests/page_with_frame_out_of_view.html") diff --git a/py/test/selenium/webdriver/common/conftest.py b/py/test/selenium/webdriver/common/conftest.py index 75670927e31e3..043b7df7e146f 100644 --- a/py/test/selenium/webdriver/common/conftest.py +++ b/py/test/selenium/webdriver/common/conftest.py @@ -17,5 +17,5 @@ def pytest_generate_tests(metafunc): - if 'driver' in metafunc.fixturenames and metafunc.config.option.drivers: - metafunc.parametrize('driver', metafunc.config.option.drivers, indirect=True) + if "driver" in metafunc.fixturenames and metafunc.config.option.drivers: + metafunc.parametrize("driver", metafunc.config.option.drivers, indirect=True) diff --git a/py/test/selenium/webdriver/common/cookie_tests.py b/py/test/selenium/webdriver/common/cookie_tests.py index d593620b3c265..df67ed78536c7 100644 --- a/py/test/selenium/webdriver/common/cookie_tests.py +++ b/py/test/selenium/webdriver/common/cookie_tests.py @@ -24,84 +24,82 @@ @pytest.fixture def cookie(webserver): - cookie = { - 'name': 'foo', - 'value': 'bar', - 'domain': webserver.host, - 'path': '/', - 'secure': False} + cookie = {"name": "foo", "value": "bar", "domain": webserver.host, "path": "/", "secure": False} return cookie @pytest.fixture def same_site_cookie_strict(webserver): same_site_cookie_strict = { - 'name': 'foo', - 'value': 'bar', - 'path': '/', - 'domain': webserver.host, - 'sameSite': 'Strict', - 'secure': False} + "name": "foo", + "value": "bar", + "path": "/", + "domain": webserver.host, + "sameSite": "Strict", + "secure": False, + } return same_site_cookie_strict @pytest.fixture def same_site_cookie_lax(webserver): same_site_cookie_lax = { - 'name': 'foo', - 'value': 'bar', - 'path': '/', - 'domain': webserver.host, - 'sameSite': 'Lax', - 'secure': False} + "name": "foo", + "value": "bar", + "path": "/", + "domain": webserver.host, + "sameSite": "Lax", + "secure": False, + } return same_site_cookie_lax @pytest.fixture def same_site_cookie_none(webserver): same_site_cookie_none = { - 'name': 'foo', - 'value': 'bar', - 'path': '/', - 'domain': webserver.host, - 'sameSite': 'None', - 'secure': True} + "name": "foo", + "value": "bar", + "path": "/", + "domain": webserver.host, + "sameSite": "None", + "secure": True, + } return same_site_cookie_none @pytest.fixture(autouse=True) def pages(request, driver, pages): - pages.load('simpleTest.html') + pages.load("simpleTest.html") yield pages driver.delete_all_cookies() def test_add_cookie(cookie, driver): driver.add_cookie(cookie) - returned = driver.execute_script('return document.cookie') - assert cookie['name'] in returned + returned = driver.execute_script("return document.cookie") + assert cookie["name"] in returned -@pytest.mark.xfail_firefox(reason='sameSite cookie attribute not implemented') -@pytest.mark.xfail_remote(reason='sameSite cookie attribute not implemented') +@pytest.mark.xfail_firefox(reason="sameSite cookie attribute not implemented") +@pytest.mark.xfail_remote(reason="sameSite cookie attribute not implemented") @pytest.mark.xfail_safari def test_add_cookie_same_site_strict(same_site_cookie_strict, driver): driver.add_cookie(same_site_cookie_strict) - returned = driver.get_cookie('foo') - assert 'sameSite' in returned and returned['sameSite'] == 'Strict' + returned = driver.get_cookie("foo") + assert "sameSite" in returned and returned["sameSite"] == "Strict" -@pytest.mark.xfail_firefox(reason='sameSite cookie attribute not implemented') -@pytest.mark.xfail_remote(reason='sameSite cookie attribute not implemented') +@pytest.mark.xfail_firefox(reason="sameSite cookie attribute not implemented") +@pytest.mark.xfail_remote(reason="sameSite cookie attribute not implemented") @pytest.mark.xfail_safari def test_add_cookie_same_site_lax(same_site_cookie_lax, driver): driver.add_cookie(same_site_cookie_lax) - returned = driver.get_cookie('foo') - assert 'sameSite' in returned and returned['sameSite'] == 'Lax' + returned = driver.get_cookie("foo") + assert "sameSite" in returned and returned["sameSite"] == "Lax" -@pytest.mark.xfail_firefox(reason='sameSite cookie attribute not implemented') -@pytest.mark.xfail_remote(reason='sameSite cookie attribute not implemented') +@pytest.mark.xfail_firefox(reason="sameSite cookie attribute not implemented") +@pytest.mark.xfail_remote(reason="sameSite cookie attribute not implemented") @pytest.mark.xfail_safari def test_add_cookie_same_site_none(same_site_cookie_none, driver): driver.add_cookie(same_site_cookie_none) @@ -113,7 +111,7 @@ def test_add_cookie_same_site_none(same_site_cookie_none, driver): @pytest.mark.xfail_safari def test_adding_acookie_that_expired_in_the_past(cookie, driver): expired = cookie.copy() - expired['expiry'] = calendar.timegm(time.gmtime()) - 1 + expired["expiry"] = calendar.timegm(time.gmtime()) - 1 driver.add_cookie(expired) assert 0 == len(driver.get_cookies()) @@ -126,19 +124,19 @@ def test_delete_all_cookie(cookie, driver): def test_delete_cookie(cookie, driver): driver.add_cookie(cookie) - driver.delete_cookie('foo') + driver.delete_cookie("foo") assert not driver.get_cookies() def test_should_get_cookie_by_name(driver): - key = f'key_{int(random.random() * 10000000)}' + key = f"key_{int(random.random() * 10000000)}" driver.execute_script("document.cookie = arguments[0] + '=set';", key) cookie = driver.get_cookie(key) - assert 'set' == cookie['value'] + assert "set" == cookie["value"] def test_should_return_none_when_cookie_does_not_exist(driver): - key = f'key_{int(random.random() * 10000000)}' + key = f"key_{int(random.random() * 10000000)}" cookie = driver.get_cookie(key) assert cookie is None @@ -148,19 +146,19 @@ def test_get_all_cookies(cookie, driver, pages, webserver): count = len(cookies) for i in range(2): - cookie['name'] = f'key_{int(random.random() * 10000000)}' + cookie["name"] = f"key_{int(random.random() * 10000000)}" driver.add_cookie(cookie) - pages.load('simpleTest.html') + pages.load("simpleTest.html") assert count + 2 == len(driver.get_cookies()) def test_should_not_delete_cookies_with_asimilar_name(cookie, driver, webserver): cookie2 = cookie.copy() - cookie2['name'] = '{}x'.format(cookie['name']) + cookie2["name"] = "{}x".format(cookie["name"]) driver.add_cookie(cookie) driver.add_cookie(cookie2) - driver.delete_cookie(cookie['name']) + driver.delete_cookie(cookie["name"]) cookies = driver.get_cookies() - assert cookie['name'] != cookies[0]['name'] - assert cookie2['name'] == cookies[0]['name'] + assert cookie["name"] != cookies[0]["name"] + assert cookie2["name"] == cookies[0]["name"] diff --git a/py/test/selenium/webdriver/common/correct_event_firing_tests.py b/py/test/selenium/webdriver/common/correct_event_firing_tests.py index ae63df258a1d2..98a2b86a81624 100644 --- a/py/test/selenium/webdriver/common/correct_event_firing_tests.py +++ b/py/test/selenium/webdriver/common/correct_event_firing_tests.py @@ -76,8 +76,8 @@ def test_mouse_events_should_bubble_up_to_containing_elements(driver, pages): @pytest.mark.xfail_safari def test_should_emit_on_change_events_when_selecting_elements(driver, pages): pages.load("javascriptPage.html") - select = driver.find_element(By.ID, 'selector') - options = select.find_elements(By.TAG_NAME, 'option') + select = driver.find_element(By.ID, "selector") + options = select.find_elements(By.TAG_NAME, "option") initialTextValue = driver.find_element(By.ID, "result").text select.click() @@ -110,6 +110,7 @@ def test_clearing_an_element_should_cause_the_on_change_handler_to_fire(driver, result = driver.find_element(By.ID, "result") assert result.text == "Cleared" + # TODO Currently Failing and needs fixing # def test_sending_keys_to_another_element_should_cause_the_blur_event_to_fire(driver, pages): # pages.load("javascriptPage.html") diff --git a/py/test/selenium/webdriver/common/driver_element_finding_tests.py b/py/test/selenium/webdriver/common/driver_element_finding_tests.py index 9a3efd4b5a5c4..bed32581e4731 100755 --- a/py/test/selenium/webdriver/common/driver_element_finding_tests.py +++ b/py/test/selenium/webdriver/common/driver_element_finding_tests.py @@ -53,6 +53,7 @@ def test_should_be_able_to_find_multiple_elements_by_numeric_id(driver, pages): elements = driver.find_elements(By.ID, "2") assert len(elements) == 8 + # By.id negative @@ -91,6 +92,7 @@ def test_finding_multiple_elements_by_id_with_space_should_return_empty_list(dri elements = driver.find_elements(By.ID, "nonexistent button") assert len(elements) == 0 + # By.name positive @@ -111,6 +113,7 @@ def test_should_be_able_to_find_an_element_that_does_not_support_the_name_proper element = driver.find_element(By.NAME, "div1") assert element.get_attribute("name") == "div1" + # By.name negative @@ -149,6 +152,7 @@ def test_finding_multiple_elements_by_name_with_space_should_return_empty_list(d elements = driver.find_elements(By.NAME, "nonexistent button") assert len(elements) == 0 + # By.tag_Name positive @@ -163,6 +167,7 @@ def test_should_be_able_to_find_multiple_elements_by_tag_name(driver, pages): elements = driver.find_elements(By.TAG_NAME, "input") assert len(elements) > 1 + # By.tag_Name negative @@ -178,16 +183,16 @@ def test_should_not_be_able_to_locate_by_tag_name_multiple_elements_that_do_not_ assert len(elements) == 0 -@pytest.mark.xfail_firefox(reason='https://github.com/mozilla/geckodriver/issues/2007') -@pytest.mark.xfail_remote(reason='https://github.com/mozilla/geckodriver/issues/2007') +@pytest.mark.xfail_firefox(reason="https://github.com/mozilla/geckodriver/issues/2007") +@pytest.mark.xfail_remote(reason="https://github.com/mozilla/geckodriver/issues/2007") def test_finding_asingle_element_by_empty_tag_name_should_throw(driver, pages): pages.load("formPage.html") with pytest.raises(InvalidSelectorException): driver.find_element(By.TAG_NAME, "") -@pytest.mark.xfail_firefox(reason='https://github.com/mozilla/geckodriver/issues/2007') -@pytest.mark.xfail_remote(reason='https://github.com/mozilla/geckodriver/issues/2007') +@pytest.mark.xfail_firefox(reason="https://github.com/mozilla/geckodriver/issues/2007") +@pytest.mark.xfail_remote(reason="https://github.com/mozilla/geckodriver/issues/2007") def test_finding_multiple_elements_by_empty_tag_name_should_throw(driver, pages): pages.load("formPage.html") with pytest.raises(InvalidSelectorException): @@ -205,6 +210,7 @@ def test_finding_multiple_elements_by_tag_name_with_space_should_return_empty_li elements = driver.find_elements(By.TAG_NAME, "nonexistent button") assert len(elements) == 0 + # By.class_Name positive @@ -250,6 +256,7 @@ def test_should_find_elements_by_class_when_its_name_is_surrounded_by_whitespace assert len(elements) == 1 assert elements[0].text == "Spaced out" + # By.class_Name negative @@ -288,6 +295,7 @@ def test_finding_multiple_elements_by_invalid_class_name_should_throw(driver, pa with pytest.raises(InvalidSelectorException): driver.find_elements(By.CLASS_NAME, "!@#$%^&*") + # By.xpath positive @@ -320,8 +328,7 @@ def test_should_be_able_to_identify_elements_by_class(driver, pages): def test_should_be_able_to_find_an_element_by_xpath_with_multiple_attributes(driver, pages): pages.load("formPage.html") - element = driver.find_element( - By.XPATH, "//form[@name='optional']/input[@type='submit' and @value='Click!']") + element = driver.find_element(By.XPATH, "//form[@name='optional']/input[@type='submit' and @value='Click!']") assert element.tag_name.lower() == "input" assert element.get_attribute("value") == "Click!" @@ -355,6 +362,7 @@ def test_should_be_able_to_find_element_by_xpath_in_xml_document(driver, pages): element = driver.find_element(By.XPATH, "//foo") assert "baz" in element.text + # By.xpath negative @@ -364,26 +372,34 @@ def test_should_throw_an_exception_when_there_is_no_link_to_click(driver, pages) driver.find_element(By.XPATH, "//a[@id='Not here']") -def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_element(driver, pages): +def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_element( + driver, pages +): pages.load("formPage.html") with pytest.raises(InvalidSelectorException): driver.find_element(By.XPATH, "this][isnot][valid") -def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_elements(driver, pages): +def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_driver_find_elements( + driver, pages +): pages.load("formPage.html") with pytest.raises(InvalidSelectorException): driver.find_elements(By.XPATH, "this][isnot][valid") -def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_element(driver, pages): +def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_element( + driver, pages +): pages.load("formPage.html") body = driver.find_element(By.TAG_NAME, "body") with pytest.raises(InvalidSelectorException): body.find_element(By.XPATH, "this][isnot][valid") -def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_elements(driver, pages): +def test_should_throw_invalid_selector_exception_when_xpath_is_syntactically_invalid_in_element_find_elements( + driver, pages +): pages.load("formPage.html") body = driver.find_element(By.TAG_NAME, "body") with pytest.raises(InvalidSelectorException): @@ -415,6 +431,7 @@ def test_should_throw_invalid_selector_exception_when_xpath_returns_wrong_type_i with pytest.raises(InvalidSelectorException): body.find_elements(By.XPATH, "count(//input)") + # By.css_Selector positive @@ -463,6 +480,7 @@ def test_should_be_able_to_find_an_element_by_boolean_attribute_using_short_css_ element = driver.find_element(By.CSS_SELECTOR, "option[selected]") assert element.get_attribute("value") == "two" + # By.css_Selector negative @@ -501,6 +519,7 @@ def test_finding_multiple_elements_by_invalid_css_selector_should_throw(driver, with pytest.raises(InvalidSelectorException): driver.find_elements(By.CSS_SELECTOR, "//a/b/c[@id='1']") + # By.link_Text positive @@ -551,6 +570,7 @@ def test_driver_can_get_link_by_link_test_ignoring_trailing_whitespace(driver, p assert link.get_attribute("id") == "linkWithTrailingSpace" assert link.text == "link with trailing space" + # By.link_Text negative @@ -565,6 +585,7 @@ def test_should_not_be_able_to_locate_by_link_text_multiple_elements_that_do_not elements = driver.find_elements(By.LINK_TEXT, "Not here either") assert len(elements) == 0 + # By.partial_Link_Text positive @@ -592,6 +613,7 @@ def test_should_find_multiple_elements_by_partial_link_text_containing_equals_si assert len(elements) == 1 assert elements[0].get_attribute("id") == "linkWithEqualsSign" + # Misc tests @@ -601,6 +623,7 @@ def test_driver_should_be_able_to_find_elements_after_loading_more_than_one_page link = driver.find_element(By.LINK_TEXT, "click me") assert link.text == "click me" + # You don't want to ask why this is here diff --git a/py/test/selenium/webdriver/common/element_attribute_tests.py b/py/test/selenium/webdriver/common/element_attribute_tests.py index 836a6a10cceec..270b598c33502 100644 --- a/py/test/selenium/webdriver/common/element_attribute_tests.py +++ b/py/test/selenium/webdriver/common/element_attribute_tests.py @@ -165,6 +165,7 @@ def test_should_return_value_of_class_attribute_of_an_element(driver, pages): classname = heading.get_attribute("class") assert "header" == classname + # Disabled due to issues with Frames # def test_should_return_value_of_class_attribute_of_an_element_after_switching_iframe(driver, pages): # pages.load("iframes.html") @@ -275,7 +276,7 @@ def test_should_return_true_for_present_boolean_attributes(driver, pages): def test_should_get_unicode_chars_from_attribute(driver, pages): pages.load("formPage.html") title = driver.find_element(By.ID, "vsearchGadget").get_attribute("title") - assert 'Hvad s\xf8ger du?' == title + assert "Hvad s\xf8ger du?" == title @pytest.mark.xfail_chrome diff --git a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py index 1fd669c571690..a6e85bdf5fd08 100644 --- a/py/test/selenium/webdriver/common/executing_async_javascript_tests.py +++ b/py/test/selenium/webdriver/common/executing_async_javascript_tests.py @@ -70,8 +70,7 @@ def test_should_be_able_to_return_an_array_object_from_an_async_script(driver, p def test_should_be_able_to_return_arrays_of_primitives_from_async_scripts(driver, pages): pages.load("ajaxy_page.html") - result = driver.execute_async_script( - "arguments[arguments.length - 1]([null, 123, 'abc', true, false]);") + result = driver.execute_async_script("arguments[arguments.length - 1]([null, 123, 'abc', true, false]);") assert result is not None assert type(result) == list @@ -95,8 +94,7 @@ def test_should_be_able_to_return_web_elements_from_async_scripts(driver, pages) def test_should_be_able_to_return_arrays_of_web_elements_from_async_scripts(driver, pages): pages.load("ajaxy_page.html") - result = driver.execute_async_script( - "arguments[arguments.length - 1]([document.body, document.body]);") + result = driver.execute_async_script("arguments[arguments.length - 1]([document.body, document.body]);") assert result is not None assert type(result) == list @@ -125,7 +123,8 @@ def test_should_not_timeout_if_script_callsback_inside_azero_timeout(driver, pag pages.load("ajaxy_page.html") driver.execute_async_script( """var callback = arguments[arguments.length - 1]; - window.setTimeout(function() { callback(123); }, 0)""") + window.setTimeout(function() { callback(123); }, 0)""" + ) def test_should_timeout_if_script_does_not_invoke_callback_with_long_timeout(driver, pages): @@ -134,7 +133,8 @@ def test_should_timeout_if_script_does_not_invoke_callback_with_long_timeout(dri with pytest.raises(TimeoutException): driver.execute_async_script( """var callback = arguments[arguments.length - 1]; - window.setTimeout(callback, 1500);""") + window.setTimeout(callback, 1500);""" + ) def test_should_detect_page_loads_while_waiting_on_an_async_script_and_return_an_error(driver, pages): @@ -161,25 +161,33 @@ def test_should_be_able_to_execute_asynchronous_scripts(driver, pages): driver.find_element(by=By.ID, value="red").click() driver.find_element(by=By.NAME, value="submit").click() - assert 1 == len(driver.find_elements(by=By.TAG_NAME, value='div')), \ - "There should only be 1 DIV at this point, which is used for the butter message" + assert 1 == len( + driver.find_elements(by=By.TAG_NAME, value="div") + ), "There should only be 1 DIV at this point, which is used for the butter message" driver.set_script_timeout(10) text = driver.execute_async_script( """var callback = arguments[arguments.length - 1]; - window.registerListener(arguments[arguments.length - 1]);""") + window.registerListener(arguments[arguments.length - 1]);""" + ) assert "bob" == text assert "" == typer.get_attribute("value") - assert 2 == len(driver.find_elements(by=By.TAG_NAME, value='div')), \ - "There should be 1 DIV (for the butter message) + 1 DIV (for the new label)" + assert 2 == len( + driver.find_elements(by=By.TAG_NAME, value="div") + ), "There should be 1 DIV (for the butter message) + 1 DIV (for the new label)" def test_should_be_able_to_pass_multiple_arguments_to_async_scripts(driver, pages): pages.load("ajaxy_page.html") - result = driver.execute_async_script(""" - arguments[arguments.length - 1](arguments[0] + arguments[1]);""", 1, 2) + result = driver.execute_async_script( + """ + arguments[arguments.length - 1](arguments[0] + arguments[1]);""", + 1, + 2, + ) assert 3 == result + # TODO DavidBurns Disabled till Java WebServer is used # def test_should_be_able_to_make_xmlhttp_requests_and_wait_for_the_response(driver, pages): # script = """ diff --git a/py/test/selenium/webdriver/common/executing_javascript_tests.py b/py/test/selenium/webdriver/common/executing_javascript_tests.py index c29b8ea19e966..28d19b4bc97c6 100644 --- a/py/test/selenium/webdriver/common/executing_javascript_tests.py +++ b/py/test/selenium/webdriver/common/executing_javascript_tests.py @@ -62,7 +62,7 @@ def test_should_be_able_to_execute_simple_javascript_and_return_alist_of_web_ele assert result is not None assert isinstance(result, list) assert all(isinstance(item, WebElement) for item in result) - assert all('a' == item.tag_name.lower() for item in result) + assert all("a" == item.tag_name.lower() for item in result) def test_should_be_able_to_execute_simple_javascript_and_return_web_elements_inside_alist(driver, pages): @@ -93,19 +93,18 @@ def test_should_be_able_to_execute_simple_javascript_and_return_web_elements_ins assert result is not None assert isinstance(result, dict) - assert isinstance(result.get('el1'), WebElement) + assert isinstance(result.get("el1"), WebElement) def test_should_be_able_to_execute_simple_javascript_and_return_web_elements_inside_anested_dict(driver, pages): pages.load("xhtmlTest.html") - result = driver.execute_script("return {el1: document.body, " - "nested: {el2: document.getElementById('id1')}}") + result = driver.execute_script("return {el1: document.body, " "nested: {el2: document.getElementById('id1')}}") assert result is not None assert isinstance(result, dict) - assert isinstance(result.get('el1'), WebElement) - assert isinstance(result.get('nested').get('el2'), WebElement) + assert isinstance(result.get("el1"), WebElement) + assert isinstance(result.get("nested").get("el2"), WebElement) def test_should_be_able_to_execute_simple_javascript_and_return_web_elements_inside_alist_inside_adict(driver, pages): @@ -115,8 +114,8 @@ def test_should_be_able_to_execute_simple_javascript_and_return_web_elements_ins assert result is not None assert isinstance(result, dict) - assert isinstance(result.get('el1'), list) - assert isinstance(result.get('el1')[0], WebElement) + assert isinstance(result.get("el1"), list) + assert isinstance(result.get("el1")[0], WebElement) def test_should_be_able_to_execute_simple_javascript_and_return_aboolean(driver, pages): @@ -135,8 +134,7 @@ def test_should_be_able_to_execute_simple_javascript_and_astrings_array(driver, expectedResult.append("zero") expectedResult.append("one") expectedResult.append("two") - result = driver.execute_script( - "return ['zero', 'one', 'two']") + result = driver.execute_script("return ['zero', 'one', 'two']") assert expectedResult == result @@ -186,8 +184,7 @@ def test_should_be_able_to_call_functions_defined_on_the_page(driver, pages): def test_should_be_able_to_pass_astring_an_as_argument(driver, pages): pages.load("javascriptPage.html") - value = driver.execute_script( - "return arguments[0] == 'fish' ? 'fish' : 'not fish'", "fish") + value = driver.execute_script("return arguments[0] == 'fish' ? 'fish' : 'not fish'", "fish") assert "fish" == value @@ -207,8 +204,8 @@ def test_should_be_able_to_pass_aweb_element_as_argument(driver, pages): pages.load("javascriptPage.html") button = driver.find_element(By.ID, "plainButton") value = driver.execute_script( - "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble']", - button) + "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble']", button + ) assert "plainButton" == value diff --git a/py/test/selenium/webdriver/common/frame_switching_tests.py b/py/test/selenium/webdriver/common/frame_switching_tests.py index da482609f95e0..bbaac331112a5 100644 --- a/py/test/selenium/webdriver/common/frame_switching_tests.py +++ b/py/test/selenium/webdriver/common/frame_switching_tests.py @@ -57,6 +57,7 @@ def test_should_open_page_with_broken_frameset(driver, pages): frame2 = driver.find_element(By.ID, "second") driver.switch_to.frame(frame2) # IE9 can not switch to this broken frame - it has no window. + # ---------------------------------------------------------------------------------------------- # # Tests that WebDriver can switch to frames as expected. @@ -204,6 +205,7 @@ def test_should_be_able_to_switch_to_parent_from_an_iframe(driver, pages): driver.switch_to.parent_frame() driver.find_element(By.ID, "iframe_page_heading") + # ---------------------------------------------------------------------------------------------- # # General frame handling behavior tests @@ -221,13 +223,11 @@ def test_should_continue_to_refer_to_the_same_frame_once_it_has_been_selected(dr # TODO(simon): this should not be needed, and is only here because IE's submit returns too # soon. - WebDriverWait(driver, 3).until(EC.text_to_be_present_in_element((By.XPATH, '//p'), 'Success!')) + WebDriverWait(driver, 3).until(EC.text_to_be_present_in_element((By.XPATH, "//p"), "Success!")) -@pytest.mark.xfail_firefox(raises=WebDriverException, - reason='https://github.com/mozilla/geckodriver/issues/610') -@pytest.mark.xfail_remote(raises=WebDriverException, - reason='https://github.com/mozilla/geckodriver/issues/610') +@pytest.mark.xfail_firefox(raises=WebDriverException, reason="https://github.com/mozilla/geckodriver/issues/610") +@pytest.mark.xfail_remote(raises=WebDriverException, reason="https://github.com/mozilla/geckodriver/issues/610") @pytest.mark.xfail_safari def test_should_focus_on_the_replacement_when_aframe_follows_alink_to_a_top_targeted_page(driver, pages): pages.load("frameset.html") @@ -324,8 +324,7 @@ def test_should_be_able_to_switch_to_the_top_if_the_frame_is_deleted_from_under_ killIframe = driver.find_element(By.ID, "killIframe") killIframe.click() driver.switch_to.default_content() - WebDriverWait(driver, 3).until_not( - EC.presence_of_element_located((By.ID, "iframe1"))) + WebDriverWait(driver, 3).until_not(EC.presence_of_element_located((By.ID, "iframe1"))) addIFrame = driver.find_element(By.ID, "addBackFrame") addIFrame.click() @@ -427,13 +426,14 @@ def test_should_not_switch_magically_to_the_top_window(driver, pages): submit = WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.ID, "submitButton"))) input.clear() import random + input.send_keys("rand%s" % int(random.random())) submit.click() finally: url = driver.execute_script("return window.location.href") # IE6 and Chrome add "?"-symbol to the end of the URL if url.endswith("?"): - url = url[:len(url) - 1] + url = url[: len(url) - 1] assert pages.url("frame_switching_tests/bug4876_iframe.html") == url diff --git a/py/test/selenium/webdriver/common/interactions_tests.py b/py/test/selenium/webdriver/common/interactions_tests.py index 0e99f4c1b2587..c941a27eb3337 100644 --- a/py/test/selenium/webdriver/common/interactions_tests.py +++ b/py/test/selenium/webdriver/common/interactions_tests.py @@ -35,8 +35,7 @@ def perform_drag_and_drop_with_mouse(driver, pages): dragInto = driver.find_element(By.ID, "sortable1") holdItem = ActionChains(driver).click_and_hold(toDrag) - moveToSpecificItem = ActionChains(driver) \ - .move_to_element(driver.find_element(By.ID, "leftitem-4")) + moveToSpecificItem = ActionChains(driver).move_to_element(driver.find_element(By.ID, "leftitem-4")) moveToOtherList = ActionChains(driver).move_to_element(dragInto) drop = ActionChains(driver).release(dragInto) assert "Nothing happened." == dragReporter.text @@ -88,10 +87,8 @@ def test_drag_and_drop(driver, pages): toDrag = driver.find_element(By.ID, "draggable") dropInto = driver.find_element(By.ID, "droppable") - holdDrag = ActionChains(driver) \ - .click_and_hold(toDrag) - move = ActionChains(driver) \ - .move_to_element(dropInto) + holdDrag = ActionChains(driver).click_and_hold(toDrag) + move = ActionChains(driver).move_to_element(dropInto) drop = ActionChains(driver).release(dropInto) holdDrag.perform() @@ -109,11 +106,10 @@ def test_double_click(driver, pages): pages.load("javascriptPage.html") toDoubleClick = driver.find_element(By.ID, "doubleClickField") - dblClick = ActionChains(driver) \ - .double_click(toDoubleClick) + dblClick = ActionChains(driver).double_click(toDoubleClick) dblClick.perform() - assert "DoubleClicked" == toDoubleClick.get_attribute('value') + assert "DoubleClicked" == toDoubleClick.get_attribute("value") def test_context_click(driver, pages): @@ -121,11 +117,10 @@ def test_context_click(driver, pages): pages.load("javascriptPage.html") toContextClick = driver.find_element(By.ID, "doubleClickField") - contextClick = ActionChains(driver) \ - .context_click(toContextClick) + contextClick = ActionChains(driver).context_click(toContextClick) contextClick.perform() - assert "ContextClicked" == toContextClick.get_attribute('value') + assert "ContextClicked" == toContextClick.get_attribute("value") def test_move_and_click(driver, pages): @@ -133,12 +128,10 @@ def test_move_and_click(driver, pages): pages.load("javascriptPage.html") toClick = driver.find_element(By.ID, "clickField") - click = ActionChains(driver) \ - .move_to_element(toClick) \ - .click() + click = ActionChains(driver).move_to_element(toClick).click() click.perform() - assert "Clicked" == toClick.get_attribute('value') + assert "Clicked" == toClick.get_attribute("value") def test_cannot_move_to_anull_locator(driver, pages): @@ -146,8 +139,7 @@ def test_cannot_move_to_anull_locator(driver, pages): pages.load("javascriptPage.html") with pytest.raises(AttributeError): - move = ActionChains(driver) \ - .move_to_element(None) + move = ActionChains(driver).move_to_element(None) move.perform() @@ -156,11 +148,9 @@ def test_clicking_on_form_elements(driver, pages): """Copied from org.openqa.selenium.interactions.CombinedInputActionsTest.""" pages.load("formSelectionPage.html") options = driver.find_elements(By.TAG_NAME, "option") - selectThreeOptions = ActionChains(driver) \ - .click(options[1]) \ - .key_down(Keys.SHIFT) \ - .click(options[3]) \ - .key_up(Keys.SHIFT) + selectThreeOptions = ( + ActionChains(driver).click(options[1]).key_down(Keys.SHIFT).click(options[3]).key_up(Keys.SHIFT) + ) selectThreeOptions.perform() showButton = driver.find_element(By.NAME, "showselected") @@ -179,12 +169,14 @@ def test_selecting_multiple_items(driver, pages): assert "no info" == reportingElement.text listItems = driver.find_elements(By.TAG_NAME, "li") - selectThreeItems = ActionChains(driver) \ - .key_down(Keys.CONTROL) \ - .click(listItems[1]) \ - .click(listItems[3]) \ - .click(listItems[5]) \ + selectThreeItems = ( + ActionChains(driver) + .key_down(Keys.CONTROL) + .click(listItems[1]) + .click(listItems[3]) + .click(listItems[5]) .key_up(Keys.CONTROL) + ) selectThreeItems.perform() assert "#item2 #item4 #item6" == reportingElement.text @@ -201,22 +193,18 @@ def test_sending_keys_to_active_element_with_modifier(driver, pages): e = driver.find_element(By.ID, "working") e.click() - ActionChains(driver) \ - .key_down(Keys.SHIFT) \ - .send_keys("abc") \ - .key_up(Keys.SHIFT) \ - .perform() + ActionChains(driver).key_down(Keys.SHIFT).send_keys("abc").key_up(Keys.SHIFT).perform() - assert "ABC" == e.get_attribute('value') + assert "ABC" == e.get_attribute("value") def test_sending_keys_to_element(driver, pages): pages.load("formPage.html") e = driver.find_element(By.ID, "working") - ActionChains(driver).send_keys_to_element(e, 'abc').perform() + ActionChains(driver).send_keys_to_element(e, "abc").perform() - assert "abc" == e.get_attribute('value') + assert "abc" == e.get_attribute("value") def test_can_send_keys_between_clicks(driver, pages): @@ -224,18 +212,18 @@ def test_can_send_keys_between_clicks(driver, pages): For W3C, ensures that the correct number of pauses are given to the other input device. """ - pages.load('javascriptPage.html') + pages.load("javascriptPage.html") keyup = driver.find_element(By.ID, "keyUp") keydown = driver.find_element(By.ID, "keyDown") - ActionChains(driver).click(keyup).send_keys('foobar').click(keydown).perform() + ActionChains(driver).click(keyup).send_keys("foobar").click(keydown).perform() - assert 'foobar' == keyup.get_attribute('value') + assert "foobar" == keyup.get_attribute("value") def test_can_reset_interactions(driver): actions = ActionChains(driver) actions.click() - actions.key_down('A') + actions.key_down("A") assert all(len(device.actions) > 0 for device in actions.w3c_actions.devices if device.type != interaction.WHEEL) actions.reset_actions() @@ -245,6 +233,7 @@ def test_can_reset_interactions(driver): def test_can_pause(driver, pages): from time import time + pages.load("javascriptPage.html") pause_time = 2 @@ -258,8 +247,8 @@ def test_can_pause(driver, pages): end = time() assert pause_time < end - start - assert "Clicked" == toClick.get_attribute('value') - assert "Clicked" == toDoubleClick.get_attribute('value') + assert "Clicked" == toClick.get_attribute("value") + assert "Clicked" == toDoubleClick.get_attribute("value") @pytest.mark.xfail_firefox @@ -320,7 +309,7 @@ def test_errors_when_element_offset_not_in_viewport(driver, pages): def test_can_scroll_from_viewport_by_amount(driver, pages): pages.load("scrolling_tests/frame_with_nested_scrolling_frame_out_of_view.html") footer = driver.find_element(By.TAG_NAME, "footer") - delta_y = footer.rect['y'] + delta_y = footer.rect["y"] ActionChains(driver).scroll_by_amount(0, delta_y).pause(0.2).perform() @@ -360,7 +349,7 @@ def _get_events(driver): # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char) if "key" in e and e["key"].startswith("U+"): key = e["key"] - hex_suffix = key[key.index("+") + 1:] + hex_suffix = key[key.index("+") + 1 :] e["key"] = chr(int(hex_suffix, 16)) # WebKit sets code as 'Unidentified' for unidentified key codes, but diff --git a/py/test/selenium/webdriver/common/network.py b/py/test/selenium/webdriver/common/network.py index 223cefdc127b9..59306f086e475 100644 --- a/py/test/selenium/webdriver/common/network.py +++ b/py/test/selenium/webdriver/common/network.py @@ -31,24 +31,36 @@ def _bytes(value, encoding): return value # Python 2 sckt = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - return socket.inet_ntoa(fcntl.ioctl( - sckt.fileno(), - 0x8915, # SIOCGIFADDR - struct.pack('256s', _bytes(ifname[:15], 'utf-8')) - )[20:24]) + return socket.inet_ntoa( + fcntl.ioctl(sckt.fileno(), 0x8915, struct.pack("256s", _bytes(ifname[:15], "utf-8")))[20:24] # SIOCGIFADDR + ) def get_lan_ip(): - if os.environ.get('CI') == 'true': - return '0.0.0.0' + if os.environ.get("CI") == "true": + return "0.0.0.0" try: ip = socket.gethostbyname(socket.gethostname()) except Exception: - return '0.0.0.0' + return "0.0.0.0" if ip.startswith("127.") and os.name != "nt": - interfaces = ["eth0", "eth1", "eth2", "en0", "en1", "en2", "en3", - "en4", "wlan0", "wlan1", "wifi0", "ath0", "ath1", "ppp0"] + interfaces = [ + "eth0", + "eth1", + "eth2", + "en0", + "en1", + "en2", + "en3", + "en4", + "wlan0", + "wlan1", + "wifi0", + "ath0", + "ath1", + "ppp0", + ] for ifname in interfaces: try: ip = get_interface_ip(ifname) diff --git a/py/test/selenium/webdriver/common/opacity_tests.py b/py/test/selenium/webdriver/common/opacity_tests.py index 9b382d0ef7197..f22480e0609ae 100644 --- a/py/test/selenium/webdriver/common/opacity_tests.py +++ b/py/test/selenium/webdriver/common/opacity_tests.py @@ -24,11 +24,13 @@ def test_should_be_able_to_click_on_elements_with_opacity_zero(driver, pages): pages.load("click_jacker.html") element = driver.find_element(By.ID, "clickJacker") - assert '0' == element.value_of_css_property("opacity"), \ + assert "0" == element.value_of_css_property("opacity"), ( "Precondition failed: clickJacker should be transparent.\ - Value was %s" % element.value_of_css_property("opacity") + Value was %s" + % element.value_of_css_property("opacity") + ) element.click() - assert '1' == element.value_of_css_property("opacity") + assert "1" == element.value_of_css_property("opacity") @pytest.mark.xfail_ie diff --git a/py/test/selenium/webdriver/common/page_loader.py b/py/test/selenium/webdriver/common/page_loader.py index c339dbaf5eace..c6fe18d7ce177 100644 --- a/py/test/selenium/webdriver/common/page_loader.py +++ b/py/test/selenium/webdriver/common/page_loader.py @@ -29,4 +29,5 @@ def load_page(page, *params, **kwds): page.load() assert page.is_loaded(), "page should be loaded by now" return func(page, *params, **kwds) + return load_page diff --git a/py/test/selenium/webdriver/common/position_and_size_tests.py b/py/test/selenium/webdriver/common/position_and_size_tests.py index 369c453ee2589..446c185d3df35 100644 --- a/py/test/selenium/webdriver/common/position_and_size_tests.py +++ b/py/test/selenium/webdriver/common/position_and_size_tests.py @@ -27,12 +27,16 @@ def test_should_be_able_to_determine_the_location_of_an_element(driver, pages): assert location["y"] > 0 -@pytest.mark.parametrize('page', ( - 'coordinates_tests/simple_page.html', - 'coordinates_tests/page_with_empty_element.html', - 'coordinates_tests/page_with_transparent_element.html', - 'coordinates_tests/page_with_hidden_element.html'), - ids=('basic', 'empty', 'transparent', 'hidden')) +@pytest.mark.parametrize( + "page", + ( + "coordinates_tests/simple_page.html", + "coordinates_tests/page_with_empty_element.html", + "coordinates_tests/page_with_transparent_element.html", + "coordinates_tests/page_with_hidden_element.html", + ), + ids=("basic", "empty", "transparent", "hidden"), +) @pytest.mark.xfail_safari def test_should_get_coordinates_of_an_element(page, driver, pages): pages.load(page) diff --git a/py/test/selenium/webdriver/common/print_pdf_tests.py b/py/test/selenium/webdriver/common/print_pdf_tests.py index 9bb42ac6ea7f3..c40abe6058fb2 100644 --- a/py/test/selenium/webdriver/common/print_pdf_tests.py +++ b/py/test/selenium/webdriver/common/print_pdf_tests.py @@ -19,35 +19,35 @@ START_INDEX = 0 END_INDEX = 5 -PDF_MAGIC_NUMBER = 'JVBER' +PDF_MAGIC_NUMBER = "JVBER" def test_pdf_with_2_pages(driver, pages): print_options = PrintOptions() - print_options.page_ranges = ['1-2'] + print_options.page_ranges = ["1-2"] pages.load("printPage.html") base64code = driver.print_page(print_options) - assert base64code[START_INDEX: END_INDEX] == PDF_MAGIC_NUMBER + assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER def test_pdf_with_all_pages(driver, pages): pages.load("printPage.html") base64code = driver.print_page() - assert base64code[START_INDEX: END_INDEX] == PDF_MAGIC_NUMBER + assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER def test_valid_params(driver, pages): print_options = PrintOptions() - print_options.page_ranges = ['1-2'] - print_options.orientation = 'landscape' + print_options.page_ranges = ["1-2"] + print_options.orientation = "landscape" print_options.width = 30 pages.load("printPage.html") base64code = driver.print_page(print_options) - assert base64code[START_INDEX: END_INDEX] == PDF_MAGIC_NUMBER + assert base64code[START_INDEX:END_INDEX] == PDF_MAGIC_NUMBER diff --git a/py/test/selenium/webdriver/common/proxy_tests.py b/py/test/selenium/webdriver/common/proxy_tests.py index ee1caccdf699c..6c7034003369b 100755 --- a/py/test/selenium/webdriver/common/proxy_tests.py +++ b/py/test/selenium/webdriver/common/proxy_tests.py @@ -21,77 +21,77 @@ from selenium.webdriver.common.proxy import ProxyType MANUAL_PROXY = { - 'httpProxy': 'some.url:1234', - 'ftpProxy': 'ftp.proxy', - 'noProxy': 'localhost, foo.localhost', - 'sslProxy': 'ssl.proxy:1234', - 'socksProxy': 'socks.proxy:65555', - 'socksUsername': 'test', - 'socksPassword': 'test', - 'socksVersion': 5, + "httpProxy": "some.url:1234", + "ftpProxy": "ftp.proxy", + "noProxy": "localhost, foo.localhost", + "sslProxy": "ssl.proxy:1234", + "socksProxy": "socks.proxy:65555", + "socksUsername": "test", + "socksPassword": "test", + "socksVersion": 5, } PAC_PROXY = { - 'proxyAutoconfigUrl': 'http://pac.url:1234', + "proxyAutoconfigUrl": "http://pac.url:1234", } AUTODETECT_PROXY = { - 'autodetect': True, + "autodetect": True, } def test_can_add_manual_proxy_to_desired_capabilities(): proxy = Proxy() - proxy.http_proxy = MANUAL_PROXY['httpProxy'] - proxy.ftp_proxy = MANUAL_PROXY['ftpProxy'] - proxy.no_proxy = MANUAL_PROXY['noProxy'] - proxy.sslProxy = MANUAL_PROXY['sslProxy'] - proxy.socksProxy = MANUAL_PROXY['socksProxy'] - proxy.socksUsername = MANUAL_PROXY['socksUsername'] - proxy.socksPassword = MANUAL_PROXY['socksPassword'] - proxy.socksVersion = MANUAL_PROXY['socksVersion'] + proxy.http_proxy = MANUAL_PROXY["httpProxy"] + proxy.ftp_proxy = MANUAL_PROXY["ftpProxy"] + proxy.no_proxy = MANUAL_PROXY["noProxy"] + proxy.sslProxy = MANUAL_PROXY["sslProxy"] + proxy.socksProxy = MANUAL_PROXY["socksProxy"] + proxy.socksUsername = MANUAL_PROXY["socksUsername"] + proxy.socksPassword = MANUAL_PROXY["socksPassword"] + proxy.socksVersion = MANUAL_PROXY["socksVersion"] desired_capabilities = {} proxy.add_to_capabilities(desired_capabilities) proxy_capabilities = MANUAL_PROXY.copy() - proxy_capabilities['proxyType'] = 'MANUAL' - expected_capabilities = {'proxy': proxy_capabilities} + proxy_capabilities["proxyType"] = "MANUAL" + expected_capabilities = {"proxy": proxy_capabilities} assert expected_capabilities == desired_capabilities def test_can_add_autodetect_proxy_to_desired_capabilities(): proxy = Proxy() - proxy.auto_detect = AUTODETECT_PROXY['autodetect'] + proxy.auto_detect = AUTODETECT_PROXY["autodetect"] desired_capabilities = {} proxy.add_to_capabilities(desired_capabilities) proxy_capabilities = AUTODETECT_PROXY.copy() - proxy_capabilities['proxyType'] = 'AUTODETECT' - expected_capabilities = {'proxy': proxy_capabilities} + proxy_capabilities["proxyType"] = "AUTODETECT" + expected_capabilities = {"proxy": proxy_capabilities} assert expected_capabilities == desired_capabilities def test_can_add_pacproxy_to_desired_capabilities(): proxy = Proxy() - proxy.proxy_autoconfig_url = PAC_PROXY['proxyAutoconfigUrl'] + proxy.proxy_autoconfig_url = PAC_PROXY["proxyAutoconfigUrl"] desired_capabilities = {} proxy.add_to_capabilities(desired_capabilities) proxy_capabilities = PAC_PROXY.copy() - proxy_capabilities['proxyType'] = 'PAC' - expected_capabilities = {'proxy': proxy_capabilities} + proxy_capabilities["proxyType"] = "PAC" + expected_capabilities = {"proxy": proxy_capabilities} assert expected_capabilities == desired_capabilities def test_can_not_change_initialized_proxy_type(): - proxy = Proxy(raw={'proxyType': 'direct'}) + proxy = Proxy(raw={"proxyType": "direct"}) with pytest.raises(Exception): proxy.proxy_type = ProxyType.SYSTEM - proxy = Proxy(raw={'proxyType': ProxyType.DIRECT}) + proxy = Proxy(raw={"proxyType": ProxyType.DIRECT}) with pytest.raises(Exception): proxy.proxy_type = ProxyType.SYSTEM @@ -100,46 +100,46 @@ def test_can_init_manual_proxy(): proxy = Proxy(raw=MANUAL_PROXY) assert ProxyType.MANUAL == proxy.proxy_type - assert MANUAL_PROXY['httpProxy'] == proxy.http_proxy - assert MANUAL_PROXY['ftpProxy'] == proxy.ftp_proxy - assert MANUAL_PROXY['noProxy'] == proxy.no_proxy - assert MANUAL_PROXY['sslProxy'] == proxy.sslProxy - assert MANUAL_PROXY['socksProxy'] == proxy.socksProxy - assert MANUAL_PROXY['socksUsername'] == proxy.socksUsername - assert MANUAL_PROXY['socksPassword'] == proxy.socksPassword - assert MANUAL_PROXY['socksVersion'] == proxy.socksVersion + assert MANUAL_PROXY["httpProxy"] == proxy.http_proxy + assert MANUAL_PROXY["ftpProxy"] == proxy.ftp_proxy + assert MANUAL_PROXY["noProxy"] == proxy.no_proxy + assert MANUAL_PROXY["sslProxy"] == proxy.sslProxy + assert MANUAL_PROXY["socksProxy"] == proxy.socksProxy + assert MANUAL_PROXY["socksUsername"] == proxy.socksUsername + assert MANUAL_PROXY["socksPassword"] == proxy.socksPassword + assert MANUAL_PROXY["socksVersion"] == proxy.socksVersion def test_can_init_autodetect_proxy(): proxy = Proxy(raw=AUTODETECT_PROXY) assert ProxyType.AUTODETECT == proxy.proxy_type - assert AUTODETECT_PROXY['autodetect'] == proxy.auto_detect + assert AUTODETECT_PROXY["autodetect"] == proxy.auto_detect def test_can_init_pacproxy(): proxy = Proxy(raw=PAC_PROXY) assert ProxyType.PAC == proxy.proxy_type - assert PAC_PROXY['proxyAutoconfigUrl'] == proxy.proxy_autoconfig_url + assert PAC_PROXY["proxyAutoconfigUrl"] == proxy.proxy_autoconfig_url def test_can_init_empty_proxy(): proxy = Proxy() assert ProxyType.UNSPECIFIED == proxy.proxy_type - assert '' == proxy.http_proxy - assert '' == proxy.ftp_proxy - assert '' == proxy.no_proxy - assert '' == proxy.sslProxy - assert '' == proxy.socksProxy - assert '' == proxy.socksUsername - assert '' == proxy.socksPassword + assert "" == proxy.http_proxy + assert "" == proxy.ftp_proxy + assert "" == proxy.no_proxy + assert "" == proxy.sslProxy + assert "" == proxy.socksProxy + assert "" == proxy.socksUsername + assert "" == proxy.socksPassword assert proxy.auto_detect is False - assert '' == proxy.proxy_autoconfig_url + assert "" == proxy.proxy_autoconfig_url assert proxy.socks_version is None desired_capabilities = {} proxy.add_to_capabilities(desired_capabilities) proxy_capabilities = {} - proxy_capabilities['proxyType'] = 'UNSPECIFIED' - expected_capabilities = {'proxy': proxy_capabilities} + proxy_capabilities["proxyType"] = "UNSPECIFIED" + expected_capabilities = {"proxy": proxy_capabilities} assert expected_capabilities == desired_capabilities diff --git a/py/test/selenium/webdriver/common/quit_tests.py b/py/test/selenium/webdriver/common/quit_tests.py index 2faac42598270..fc198cbad1950 100644 --- a/py/test/selenium/webdriver/common/quit_tests.py +++ b/py/test/selenium/webdriver/common/quit_tests.py @@ -22,4 +22,4 @@ def test_quit(driver, pages): driver.quit() with pytest.raises(Exception): - pages.load('simpleTest.html') + pages.load("simpleTest.html") diff --git a/py/test/selenium/webdriver/common/rendered_webelement_tests.py b/py/test/selenium/webdriver/common/rendered_webelement_tests.py index 98343248dada7..96fcf38fa8092 100644 --- a/py/test/selenium/webdriver/common/rendered_webelement_tests.py +++ b/py/test/selenium/webdriver/common/rendered_webelement_tests.py @@ -50,9 +50,7 @@ def test_should_correctly_identify_that_an_element_has_width(driver, pages): assert size["height"] > 0 -@pytest.mark.xfail_safari( - reason='Get Element Rect command not implemented', - raises=WebDriverException) +@pytest.mark.xfail_safari(reason="Get Element Rect command not implemented", raises=WebDriverException) def test_should_be_able_to_determine_the_rect_of_an_element(driver, pages): pages.load("xhtmlTest.html") diff --git a/py/test/selenium/webdriver/common/repr_tests.py b/py/test/selenium/webdriver/common/repr_tests.py index 2b0e1e4c82bd6..734e4b4e438d1 100644 --- a/py/test/selenium/webdriver/common/repr_tests.py +++ b/py/test/selenium/webdriver/common/repr_tests.py @@ -27,7 +27,7 @@ def test_should_implement_repr_for_web_driver(driver): def test_should_implement_repr_for_web_element(driver, pages): - pages.load('simpleTest.html') + pages.load("simpleTest.html") elem = driver.find_element(By.ID, "validImgTag") elem_repr = repr(elem) assert type(elem).__name__ in elem_repr diff --git a/py/test/selenium/webdriver/common/script_pinning_tests.py b/py/test/selenium/webdriver/common/script_pinning_tests.py index 2857ccc6644e4..26d7d210f7e32 100644 --- a/py/test/selenium/webdriver/common/script_pinning_tests.py +++ b/py/test/selenium/webdriver/common/script_pinning_tests.py @@ -29,7 +29,7 @@ def test_should_allow_script_pinning(driver, pages): result = driver.execute_script(script_key) - assert result == 'i like cheese' + assert result == "i like cheese" def test_should_allow_pinned_scripts_to_take_arguments(driver, pages): diff --git a/py/test/selenium/webdriver/common/select_class_tests.py b/py/test/selenium/webdriver/common/select_class_tests.py index f69f5f946a2aa..4e807fbf3aaba 100644 --- a/py/test/selenium/webdriver/common/select_class_tests.py +++ b/py/test/selenium/webdriver/common/select_class_tests.py @@ -22,29 +22,35 @@ from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select -disabledSelect = {'name': 'no-select', 'values': ['Foo']} -disabledSingleSelect = {'name': 'single_disabled', 'values': ['Enabled', 'Disabled']} -disabledMultiSelect = {'name': 'multi_disabled', 'values': ['Enabled', 'Disabled']} -singleSelectValues1 = {'name': 'selectomatic', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']} -singleSelectValues2 = {'name': 'redirect', 'values': ['One', 'Two']} -singleSelectValuesWithSpaces = {'name': 'select_with_spaces', 'values': ['One', 'Two', 'Four', 'Still learning how to count, apparently']} -multiSelectValues1 = {'name': 'multi', 'values': ['Eggs', 'Ham', 'Sausages', 'Onion gravy']} -multiSelectValues2 = {'name': 'select_empty_multiple', 'values': ['select_1', 'select_2', 'select_3', 'select_4']} +disabledSelect = {"name": "no-select", "values": ["Foo"]} +disabledSingleSelect = {"name": "single_disabled", "values": ["Enabled", "Disabled"]} +disabledMultiSelect = {"name": "multi_disabled", "values": ["Enabled", "Disabled"]} +singleSelectValues1 = { + "name": "selectomatic", + "values": ["One", "Two", "Four", "Still learning how to count, apparently"], +} +singleSelectValues2 = {"name": "redirect", "values": ["One", "Two"]} +singleSelectValuesWithSpaces = { + "name": "select_with_spaces", + "values": ["One", "Two", "Four", "Still learning how to count, apparently"], +} +multiSelectValues1 = {"name": "multi", "values": ["Eggs", "Ham", "Sausages", "Onion gravy"]} +multiSelectValues2 = {"name": "select_empty_multiple", "values": ["select_1", "select_2", "select_3", "select_4"]} def test_select_by_index_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1]: - sel = Select(driver.find_element(By.NAME, select['name'])) - for x in range(len(select['values'])): + sel = Select(driver.find_element(By.NAME, select["name"])) + for x in range(len(select["values"])): sel.select_by_index(x) - assert sel.first_selected_option.text == select['values'][x] + assert sel.first_selected_option.text == select["values"][x] def test_raises_exception_select_by_index_single_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledSingleSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"])) with pytest.raises(NotImplementedError): sel.select_by_index(1) @@ -52,55 +58,55 @@ def test_raises_exception_select_by_index_single_disabled(driver, pages): def test_select_by_value_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1]: - sel = Select(driver.find_element(By.NAME, select['name'])) - for x in range(len(select['values'])): - sel.select_by_value(select['values'][x].lower()) - assert sel.first_selected_option.text == select['values'][x] + sel = Select(driver.find_element(By.NAME, select["name"])) + for x in range(len(select["values"])): + sel.select_by_value(select["values"][x].lower()) + assert sel.first_selected_option.text == select["values"][x] def test_raises_exception_select_by_value_single_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledSingleSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"])) with pytest.raises(NotImplementedError): - sel.select_by_value(disabledSingleSelect['values'][1].lower()) + sel.select_by_value(disabledSingleSelect["values"][1].lower()) def test_select_by_visible_text_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1]: - sel = Select(driver.find_element(By.NAME, select['name'])) - for x in range(len(select['values'])): - print(select['values'][x]) - sel.select_by_visible_text(select['values'][x]) - assert sel.first_selected_option.text == select['values'][x] + sel = Select(driver.find_element(By.NAME, select["name"])) + for x in range(len(select["values"])): + print(select["values"][x]) + sel.select_by_visible_text(select["values"][x]) + assert sel.first_selected_option.text == select["values"][x] def test_raises_exception_select_by_text_single_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledSingleSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledSingleSelect["name"])) with pytest.raises(NotImplementedError): - sel.select_by_visible_text(disabledSingleSelect['values'][1]) + sel.select_by_visible_text(disabledSingleSelect["values"][1]) def test_select_by_index_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() - for x in range(len(select['values'])): + for x in range(len(select["values"])): sel.select_by_index(x) selected = sel.all_selected_options assert len(selected) == x + 1 for j in range(len(selected)): - assert selected[j].text == select['values'][j] + assert selected[j].text == select["values"][j] def test_raises_exception_select_by_index_multiple_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledMultiSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledMultiSelect["name"])) with pytest.raises(NotImplementedError): sel.select_by_index(1) @@ -109,57 +115,57 @@ def test_select_by_value_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() - for x in range(len(select['values'])): - sel.select_by_value(select['values'][x].lower()) + for x in range(len(select["values"])): + sel.select_by_value(select["values"][x].lower()) selected = sel.all_selected_options assert len(selected) == x + 1 for j in range(len(selected)): - assert selected[j].text == select['values'][j] + assert selected[j].text == select["values"][j] def test_raises_exception_select_by_value_multiple_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledMultiSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledMultiSelect["name"])) with pytest.raises(NotImplementedError): - sel.select_by_value(disabledMultiSelect['values'][1].lower()) + sel.select_by_value(disabledMultiSelect["values"][1].lower()) def test_select_by_visible_text_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() - for x in range(len(select['values'])): - sel.select_by_visible_text(select['values'][x]) + for x in range(len(select["values"])): + sel.select_by_visible_text(select["values"][x]) selected = sel.all_selected_options assert len(selected) == x + 1 for j in range(len(selected)): - assert selected[j].text == select['values'][j] + assert selected[j].text == select["values"][j] def test_raises_exception_select_by_text_multiple_disabled(driver, pages): pages.load("formPage.html") - sel = Select(driver.find_element(By.NAME, disabledMultiSelect['name'])) + sel = Select(driver.find_element(By.NAME, disabledMultiSelect["name"])) with pytest.raises(NotImplementedError): - sel.select_by_visible_text(disabledMultiSelect['values'][1]) + sel.select_by_visible_text(disabledMultiSelect["values"][1]) def test_deselect_all_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: with pytest.raises(NotImplementedError): - Select(driver.find_element(By.NAME, select['name'])).deselect_all() + Select(driver.find_element(By.NAME, select["name"])).deselect_all() def test_deselect_all_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() assert len(sel.all_selected_options) == 0 @@ -168,27 +174,27 @@ def test_deselect_by_index_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: with pytest.raises(NotImplementedError): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_index(0) + Select(driver.find_element(By.NAME, select["name"])).deselect_by_index(0) def test_deselect_by_value_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: with pytest.raises(NotImplementedError): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_value(select['values'][0].lower()) + Select(driver.find_element(By.NAME, select["name"])).deselect_by_value(select["values"][0].lower()) def test_deselect_by_visible_text_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: with pytest.raises(NotImplementedError): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_visible_text(select['values'][0]) + Select(driver.find_element(By.NAME, select["name"])).deselect_by_visible_text(select["values"][0]) def test_deselect_by_index_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() sel.select_by_index(0) sel.select_by_index(1) @@ -198,83 +204,83 @@ def test_deselect_by_index_multiple(driver, pages): sel.deselect_by_index(3) selected = sel.all_selected_options assert len(selected) == 2 - assert selected[0].text == select['values'][0] - assert selected[1].text == select['values'][2] + assert selected[0].text == select["values"][0] + assert selected[1].text == select["values"][2] def test_deselect_by_value_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() sel.select_by_index(0) sel.select_by_index(1) sel.select_by_index(2) sel.select_by_index(3) - sel.deselect_by_value(select['values'][1].lower()) - sel.deselect_by_value(select['values'][3].lower()) + sel.deselect_by_value(select["values"][1].lower()) + sel.deselect_by_value(select["values"][3].lower()) selected = sel.all_selected_options assert len(selected) == 2 - assert selected[0].text == select['values'][0] - assert selected[1].text == select['values'][2] + assert selected[0].text == select["values"][0] + assert selected[1].text == select["values"][2] def test_deselect_by_visible_text_multiple(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: - sel = Select(driver.find_element(By.NAME, select['name'])) + sel = Select(driver.find_element(By.NAME, select["name"])) sel.deselect_all() sel.select_by_index(0) sel.select_by_index(1) sel.select_by_index(2) sel.select_by_index(3) - sel.deselect_by_visible_text(select['values'][1]) - sel.deselect_by_visible_text(select['values'][3]) + sel.deselect_by_visible_text(select["values"][1]) + sel.deselect_by_visible_text(select["values"][3]) selected = sel.all_selected_options assert len(selected) == 2 - assert selected[0].text == select['values'][0] - assert selected[1].text == select['values'][2] + assert selected[0].text == select["values"][0] + assert selected[1].text == select["values"][2] def test_get_options(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2, multiSelectValues1, multiSelectValues2]: - opts = Select(driver.find_element(By.NAME, select['name'])).options - assert len(opts) == len(select['values']) + opts = Select(driver.find_element(By.NAME, select["name"])).options + assert len(opts) == len(select["values"]) for i in range(len(opts)): - assert opts[i].text == select['values'][i] + assert opts[i].text == select["values"][i] def test_get_all_selected_options_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: - opts = Select(driver.find_element(By.NAME, select['name'])).all_selected_options + opts = Select(driver.find_element(By.NAME, select["name"])).all_selected_options assert len(opts) == 1 - assert opts[0].text == select['values'][0] + assert opts[0].text == select["values"][0] def test_get_all_selected_options_multiple(driver, pages): pages.load("formPage.html") - opts = Select(driver.find_element(By.NAME, multiSelectValues1['name'])).all_selected_options + opts = Select(driver.find_element(By.NAME, multiSelectValues1["name"])).all_selected_options assert len(opts) == 2 - assert opts[0].text, multiSelectValues1['values'][0] - assert opts[1].text, multiSelectValues1['values'][2] - opts = Select(driver.find_element(By.NAME, multiSelectValues2['name'])).all_selected_options + assert opts[0].text, multiSelectValues1["values"][0] + assert opts[1].text, multiSelectValues1["values"][2] + opts = Select(driver.find_element(By.NAME, multiSelectValues2["name"])).all_selected_options assert len(opts) == 0 def test_get_first_selected_option_single(driver, pages): pages.load("formPage.html") for select in [singleSelectValues1, singleSelectValues2]: - opt = Select(driver.find_element(By.NAME, select['name'])).first_selected_option - assert opt.text == select['values'][0] + opt = Select(driver.find_element(By.NAME, select["name"])).first_selected_option + assert opt.text == select["values"][0] def test_get_first_selected_option_multiple(driver, pages): pages.load("formPage.html") - opt = Select(driver.find_element(By.NAME, multiSelectValues1['name'])).first_selected_option - assert opt.text == multiSelectValues1['values'][0] - opt = Select(driver.find_element(By.NAME, multiSelectValues2['name'])).all_selected_options + opt = Select(driver.find_element(By.NAME, multiSelectValues1["name"])).first_selected_option + assert opt.text == multiSelectValues1["values"][0] + opt = Select(driver.find_element(By.NAME, multiSelectValues2["name"])).all_selected_options assert len(opt) == 0 @@ -294,18 +300,18 @@ def test_deselect_by_index_non_existent(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: with pytest.raises(NoSuchElementException): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_index(10) + Select(driver.find_element(By.NAME, select["name"])).deselect_by_index(10) def test_deselect_by_value_non_existent(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: with pytest.raises(NoSuchElementException): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_value('not there') + Select(driver.find_element(By.NAME, select["name"])).deselect_by_value("not there") def test_deselect_by_text_non_existent(driver, pages): pages.load("formPage.html") for select in [multiSelectValues1, multiSelectValues2]: with pytest.raises(NoSuchElementException): - Select(driver.find_element(By.NAME, select['name'])).deselect_by_visible_text('not there') + Select(driver.find_element(By.NAME, select["name"])).deselect_by_visible_text("not there") diff --git a/py/test/selenium/webdriver/common/takes_screenshots_tests.py b/py/test/selenium/webdriver/common/takes_screenshots_tests.py index 094c30d754f68..a889503491d8b 100644 --- a/py/test/selenium/webdriver/common/takes_screenshots_tests.py +++ b/py/test/selenium/webdriver/common/takes_screenshots_tests.py @@ -26,13 +26,13 @@ def test_get_screenshot_as_base64(driver, pages): pages.load("simpleTest.html") result = base64.b64decode(driver.get_screenshot_as_base64()) - assert imghdr.what('', result) == 'png' + assert imghdr.what("", result) == "png" def test_get_screenshot_as_png(driver, pages): pages.load("simpleTest.html") result = driver.get_screenshot_as_png() - assert imghdr.what('', result) == 'png' + assert imghdr.what("", result) == "png" @pytest.mark.xfail_firefox @@ -41,4 +41,4 @@ def test_get_element_screenshot(driver, pages): pages.load("simpleTest.html") element = driver.find_element(By.ID, "multiline") result = base64.b64decode(element.screenshot_as_base64) - assert imghdr.what('', result) == 'png' + assert imghdr.what("", result) == "png" diff --git a/py/test/selenium/webdriver/common/text_handling_tests.py b/py/test/selenium/webdriver/common/text_handling_tests.py index e31d522305190..1721b3fec57ea 100644 --- a/py/test/selenium/webdriver/common/text_handling_tests.py +++ b/py/test/selenium/webdriver/common/text_handling_tests.py @@ -205,7 +205,7 @@ def test_should_get_text_from_table_cells(driver, pages): def test_should_get_text_which_is_avalid_jsonobject(driver, pages): pages.load("simpleTest.html") element = driver.find_element(by=By.ID, value="simpleJsonText") - assert "{a=\"b\", c=1, d=true}" == element.text + assert '{a="b", c=1, d=true}' == element.text # assert "{a=\"b\", \"c\"=d, e=true, f=\\123\\\\g\\\\\"\"\"\\\'}", element.text) diff --git a/py/test/selenium/webdriver/common/typing_tests.py b/py/test/selenium/webdriver/common/typing_tests.py index 62744a1798963..7114586e44a53 100644 --- a/py/test/selenium/webdriver/common/typing_tests.py +++ b/py/test/selenium/webdriver/common/typing_tests.py @@ -62,8 +62,8 @@ def test_should_be_able_to_type_capital_letters(driver, pages): def test_should_be_able_to_type_quote_marks(driver, pages): pages.load("javascriptPage.html") keyReporter = driver.find_element(by=By.ID, value="keyReporter") - keyReporter.send_keys("\"") - assert keyReporter.get_attribute("value") == "\"" + keyReporter.send_keys('"') + assert keyReporter.get_attribute("value") == '"' def test_should_be_able_to_type_the_at_character(driver, pages): @@ -195,15 +195,13 @@ def test_numeric_non_shift_keys(driver, pages): assert element.get_attribute("value") == numericLineCharsNonShifted -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") def test_numeric_shift_keys(driver, pages): pages.load("javascriptPage.html") result = driver.find_element(by=By.ID, value="result") element = driver.find_element(by=By.ID, value="keyReporter") - numericShiftsEtc = "~!@#$%^&*()_+{}:i\"<>?|END~" + numericShiftsEtc = '~!@#$%^&*()_+{}:i"<>?|END~' element.send_keys(numericShiftsEtc) assert element.get_attribute("value") == numericShiftsEtc assert "up: 16" in result.text.strip() @@ -217,10 +215,8 @@ def test_lower_case_alpha_keys(driver, pages): assert element.get_attribute("value") == lowerAlphas -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") def test_uppercase_alpha_keys(driver, pages): pages.load("javascriptPage.html") result = driver.find_element(by=By.ID, value="result") @@ -231,10 +227,8 @@ def test_uppercase_alpha_keys(driver, pages): assert "up: 16" in result.text.strip() -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") def test_all_printable_keys(driver, pages): pages.load("javascriptPage.html") result = driver.find_element(by=By.ID, value="result") @@ -249,10 +243,7 @@ def test_all_printable_keys(driver, pages): def test_arrow_keys_and_page_up_and_down(driver, pages): pages.load("javascriptPage.html") element = driver.find_element(by=By.ID, value="keyReporter") - element.send_keys( - "a{}b{}{}{}{}{}1" - .format(Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN, Keys.PAGE_UP, Keys.PAGE_DOWN) - ) + element.send_keys("a{}b{}{}{}{}{}1".format(Keys.LEFT, Keys.RIGHT, Keys.UP, Keys.DOWN, Keys.PAGE_UP, Keys.PAGE_DOWN)) assert element.get_attribute("value") == "ba1" @@ -285,10 +276,8 @@ def test_delete_and_backspace_keys(driver, pages): assert element.get_attribute("value") == "abcdfgi" -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") def test_special_space_keys(driver, pages): pages.load("javascriptPage.html") element = driver.find_element(by=By.ID, value="keyReporter") @@ -296,20 +285,26 @@ def test_special_space_keys(driver, pages): assert element.get_attribute("value") == "abcd fgh ij" -@pytest.mark.xfail_firefox( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') -@pytest.mark.xfail_remote( - reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1255258') +@pytest.mark.xfail_firefox(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") +@pytest.mark.xfail_remote(reason="https://bugzilla.mozilla.org/show_bug.cgi?id=1255258") @pytest.mark.xfail_safari def test_numberpad_and_function_keys(driver, pages): pages.load("javascriptPage.html") element = driver.find_element(by=By.ID, value="keyReporter") element.send_keys( - "abcd{}{}{}{}{}{}{}{}{}{}{}{}abcd" - .format( - Keys.MULTIPLY, Keys.SUBTRACT, Keys.ADD, Keys.DECIMAL, Keys.SEPARATOR, - Keys.NUMPAD0, Keys.NUMPAD9, Keys.ADD, Keys.SEMICOLON, Keys.EQUALS, Keys.DIVIDE, - Keys.NUMPAD3 + "abcd{}{}{}{}{}{}{}{}{}{}{}{}abcd".format( + Keys.MULTIPLY, + Keys.SUBTRACT, + Keys.ADD, + Keys.DECIMAL, + Keys.SEPARATOR, + Keys.NUMPAD0, + Keys.NUMPAD9, + Keys.ADD, + Keys.SEMICOLON, + Keys.EQUALS, + Keys.DIVIDE, + Keys.NUMPAD3, ) ) assert element.get_attribute("value") == "abcd*-+.,09+;=/3abcd" diff --git a/py/test/selenium/webdriver/common/upload_tests.py b/py/test/selenium/webdriver/common/upload_tests.py index 59fa95d760430..bd29306dfa200 100644 --- a/py/test/selenium/webdriver/common/upload_tests.py +++ b/py/test/selenium/webdriver/common/upload_tests.py @@ -37,8 +37,8 @@ def test_can_upload_file(driver, pages, get_local_path): pages.load("upload.html") - driver.find_element(By.ID, 'upload').send_keys(get_local_path("test_file.txt")) - driver.find_element(By.ID, 'go').click() + driver.find_element(By.ID, "upload").send_keys(get_local_path("test_file.txt")) + driver.find_element(By.ID, "go").click() driver.switch_to.frame(driver.find_element(By.ID, "upload_target")) body = driver.find_element(By.CSS_SELECTOR, "body").text @@ -49,8 +49,8 @@ def test_can_upload_two_files(driver, pages, get_local_path): pages.load("upload.html") two_file_paths = get_local_path("test_file.txt") + "\n" + get_local_path("test_file2.txt") - driver.find_element(By.ID, 'upload').send_keys(two_file_paths) - driver.find_element(By.ID, 'go').click() + driver.find_element(By.ID, "upload").send_keys(two_file_paths) + driver.find_element(By.ID, "go").click() driver.switch_to.frame(driver.find_element(By.ID, "upload_target")) body = driver.find_element(By.CSS_SELECTOR, "body").text @@ -74,7 +74,7 @@ def mocked_upload_func(self, filename): try: pages.load("upload.html") two_file_paths = get_local_path("test_file.txt") + "\n" + get_local_path("test_file2.txt") - driver.find_element(By.ID, 'upload').send_keys(two_file_paths) + driver.find_element(By.ID, "upload").send_keys(two_file_paths) assert len(uploaded_files) == 2 assert uploaded_files[0] == get_local_path("test_file.txt") assert uploaded_files[1] == get_local_path("test_file2.txt") diff --git a/py/test/selenium/webdriver/common/virtual_authenticator_tests.py b/py/test/selenium/webdriver/common/virtual_authenticator_tests.py index 3d3faba64b99a..74f6187f47b61 100644 --- a/py/test/selenium/webdriver/common/virtual_authenticator_tests.py +++ b/py/test/selenium/webdriver/common/virtual_authenticator_tests.py @@ -28,7 +28,7 @@ from selenium.webdriver.remote.webdriver import WebDriver # working Key -BASE64__ENCODED_PK = ''' +BASE64__ENCODED_PK = """ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbBOu5Lhs4vpowbCnmCyLUpIE7JM9sm9QXzye2G+jr+Kr MsinWohEce47BFPJlTaDzHSvOW2eeunBO89ZcvvVc8RLz4qyQ8rO98xS1jtgqi1NcBPETDrtzthODu/gd0sjB2Tk3TLuBGV oPXt54a+Oo4JbBJ6h3s0+5eAfGplCbSNq6hN3Jh9YOTw5ZA6GCEy5l8zBaOgjXytd2v2OdSVoEDNiNQRkjJd2rmS2oi9AyQ @@ -47,13 +47,13 @@ 9QulbC3C/qgGFNrcWgcT9kCgYAZTa1P9bFCDU7hJc2mHwJwAW7/FQKEJg8SL33KINpLwcR8fqaYOdAHWWz636osVEqosRrH zJOGpf9x2RSWzQJ+dq8+6fACgfFZOVpN644+sAHfNPAI/gnNKU5OfUv+eav8fBnzlf1A3y3GIkyMyzFN3DE7e0n/lyqxE4H BYGpI8g== -''' +""" REGISTER_CREDENTIAL = "registerCredential().then(arguments[arguments.length - 1]);" -GET_CREDENTIAL = '''getCredential([{ +GET_CREDENTIAL = """getCredential([{ "type": "public-key", "id": Int8Array.from(arguments[0]), - }]).then(arguments[arguments.length - 1]);''' + }]).then(arguments[arguments.length - 1]);""" def create_rk_enabled_u2f_authenticator(driver) -> WebDriver: @@ -119,9 +119,9 @@ def test_add_and_remove_virtual_authenticator(driver, pages): driver.get(pages.url("virtual-authenticator.html", localhost=True)) result = driver.execute_async_script(REGISTER_CREDENTIAL) - assert result.get('status', '') == 'OK' + assert result.get("status", "") == "OK" - assert get_assertion_for(driver, result["credential"]["rawId"]).get('status', '') == 'OK' + assert get_assertion_for(driver, result["credential"]["rawId"]).get("status", "") == "OK" assert driver.virtual_authenticator_id is not None @@ -147,7 +147,7 @@ def test_add_and_remove_non_resident_credentials(driver, pages): ) driver.add_credential(credential) - assert get_assertion_for(driver, [1, 2, 3, 4]).get('status', '') == 'OK' + assert get_assertion_for(driver, [1, 2, 3, 4]).get("status", "") == "OK" driver.remove_virtual_authenticator() assert driver.virtual_authenticator_id is None @@ -160,11 +160,11 @@ def test_add_non_resident_credential_when_authenticator_uses_u2f_protocol(driver driver = create_rk_disabled_u2f_authenticator(driver) driver.get(pages.url("virtual-authenticator.html", localhost=True)) - base64_pk = ''' + base64_pk = """ MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8_zMDQDYAxlU-Q hk1Dwkf0v18GZca1DMF3SaJ9HPdmShRANCAASNYX5lyVCOZLzFZzrIKmeZ2jwU RmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB - ''' + """ credential = Credential.create_non_resident_credential( bytearray({1, 2, 3, 4}), @@ -173,7 +173,7 @@ def test_add_non_resident_credential_when_authenticator_uses_u2f_protocol(driver 0, ) driver.add_credential(credential) - assert get_assertion_for(driver, [1, 2, 3, 4]).get('status', '') == 'OK' + assert get_assertion_for(driver, [1, 2, 3, 4]).get("status", "") == "OK" driver.remove_virtual_authenticator() @@ -185,11 +185,11 @@ def test_add_resident_credential_not_supported_when_authenticator_uses_u2f_proto driver = create_rk_enabled_u2f_authenticator(driver) driver.get(pages.url("virtual-authenticator.html", localhost=True)) - base64_pk = ''' + base64_pk = """ MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQg8_zMDQDYAxlU-Q hk1Dwkf0v18GZca1DMF3SaJ9HPdmShRANCAASNYX5lyVCOZLzFZzrIKmeZ2jwU RmgsJYxGP__fWN_S-j5sN4tT15XEpN_7QZnt14YvI6uvAgO0uJEboFaZlOEB - ''' + """ credential = Credential.create_resident_credential( bytearray({1, 2, 3, 4}), @@ -212,15 +212,17 @@ def test_get_credentials(driver, pages): driver.get(pages.url("virtual-authenticator.html", localhost=True)) # Register a Resident Credential - response1 = driver.execute_async_script(''' + response1 = driver.execute_async_script( + """ registerCredential({authenticatorSelection: {requireResidentKey: true}}) .then(arguments[arguments.length - 1]); - ''') - assert response1.get('status', '') == 'OK' + """ + ) + assert response1.get("status", "") == "OK" # Register a Non-Resident Credential response2 = driver.execute_async_script(REGISTER_CREDENTIAL) - assert response2.get('status', '') == 'OK' + assert response2.get("status", "") == "OK" assert extract_id(response1) != extract_id(response2) @@ -249,7 +251,9 @@ def test_get_credentials(driver, pages): assert credential2.private_key is not None, "Credential2 should have private key" # Non-resident credentials don't save RP ID assert credential2.rp_id is None, "Credential2 should not have RP ID. Since it's not resident credential" - assert credential2.user_handle is None, "Credential2 should not have user handle. Since it's not resident credential" + assert ( + credential2.user_handle is None + ), "Credential2 should not have user handle. Since it's not resident credential" assert credential2.sign_count == 1 driver.remove_virtual_authenticator() @@ -264,7 +268,7 @@ def test_remove_credential_by_raw_Id(driver, pages): # register a credential response = driver.execute_async_script(REGISTER_CREDENTIAL) - assert response.get('status', '') == 'OK' + assert response.get("status", "") == "OK" # remove the credential using array of bytes: rawId raw_id = extract_raw_id(response) @@ -285,7 +289,7 @@ def test_remove_credential_by_b64_urlId(driver, pages): # register a credential response = driver.execute_async_script(REGISTER_CREDENTIAL) - assert response.get('status', '') == 'OK' + assert response.get("status", "") == "OK" # remove the credential using array of bytes: rawId raw_id = extract_raw_id(response) @@ -316,7 +320,7 @@ def test_remove_all_credentials(driver, pages): driver.remove_all_credentials() response = driver.execute_async_script( - ''' + """ getCredential([{ "type": "public-key", "id": Int8Array.from(arguments[0]), @@ -324,7 +328,7 @@ def test_remove_all_credentials(driver, pages): "type": "public-key", "id": Int8Array.from(arguments[1]), }]).then(arguments[arguments.length - 1]); - ''', + """, raw_id1, raw_id2, ) @@ -344,12 +348,12 @@ def test_set_user_verified(driver, pages): response = driver.execute_async_script( "registerCredential({authenticatorSelection: {userVerification: 'required'}}).then(arguments[arguments.length - 1]);" ) - assert response.get('status', '') == 'OK' + assert response.get("status", "") == "OK" raw_id = response["credential"]["rawId"] # Getting an assertion requiring user verification should succeed. response = driver.execute_async_script(GET_CREDENTIAL, raw_id) - assert response.get('status', '') == 'OK' + assert response.get("status", "") == "OK" # Disable user verified. driver.set_user_verified(False) diff --git a/py/test/selenium/webdriver/common/visibility_tests.py b/py/test/selenium/webdriver/common/visibility_tests.py index 1e5ea6f44a8be..458bc7c2681a7 100644 --- a/py/test/selenium/webdriver/common/visibility_tests.py +++ b/py/test/selenium/webdriver/common/visibility_tests.py @@ -106,40 +106,40 @@ def test_should_not_be_able_to_type_an_element_that_is_not_displayed(driver, pag def test_should_say_elements_with_negative_transform_are_not_displayed(driver, pages): - pages.load('cssTransform.html') - elementX = driver.find_element(By.ID, value='parentX') + pages.load("cssTransform.html") + elementX = driver.find_element(By.ID, value="parentX") assert elementX.is_displayed() is False - elementY = driver.find_element(By.ID, value='parentY') + elementY = driver.find_element(By.ID, value="parentY") assert elementY.is_displayed() is False def test_should_say_elements_with_parent_with_negative_transform_are_not_displayed(driver, pages): - pages.load('cssTransform.html') - elementX = driver.find_element(By.ID, value='childX') + pages.load("cssTransform.html") + elementX = driver.find_element(By.ID, value="childX") assert elementX.is_displayed() is False - elementY = driver.find_element(By.ID, value='childY') + elementY = driver.find_element(By.ID, value="childY") assert elementY.is_displayed() is False def test_should_say_element_with_zero_transform_is_visible(driver, pages): - pages.load('cssTransform.html') - zero_tranform = driver.find_element(By.ID, 'zero-tranform') + pages.load("cssTransform.html") + zero_tranform = driver.find_element(By.ID, "zero-tranform") assert zero_tranform.is_displayed() is True def test_should_say_element_is_visible_when_it_has_negative_transform_but_elementisnt_in_anegative_space(driver, pages): - pages.load('cssTransform2.html') - zero_tranform = driver.find_element(By.ID, 'negative-percentage-transformY') + pages.load("cssTransform2.html") + zero_tranform = driver.find_element(By.ID, "negative-percentage-transformY") assert zero_tranform.is_displayed() is True def test_should_show_element_not_visible_with_hidden_attribute(driver, pages): - pages.load('hidden.html') - singleHidden = driver.find_element(By.ID, 'singleHidden') + pages.load("hidden.html") + singleHidden = driver.find_element(By.ID, "singleHidden") assert singleHidden.is_displayed() is False def test_should_show_element_not_visible_when_parent_element_has_hidden_attribute(driver, pages): - pages.load('hidden.html') - child = driver.find_element(By.ID, 'child') + pages.load("hidden.html") + child = driver.find_element(By.ID, "child") assert child.is_displayed() is False diff --git a/py/test/selenium/webdriver/common/w3c_interaction_tests.py b/py/test/selenium/webdriver/common/w3c_interaction_tests.py index 0bf9d65bdbcc6..4ce7920c7ca77 100644 --- a/py/test/selenium/webdriver/common/w3c_interaction_tests.py +++ b/py/test/selenium/webdriver/common/w3c_interaction_tests.py @@ -44,13 +44,11 @@ def test_sending_keys_to_active_element_with_modifier(driver, pages): actions = ActionBuilder(driver) key_action = actions.key_action - key_action.key_down(Keys.SHIFT) \ - .send_keys("abc") \ - .key_up(Keys.SHIFT) + key_action.key_down(Keys.SHIFT).send_keys("abc").key_up(Keys.SHIFT) actions.perform() - assert "ABC" == e.get_attribute('value') + assert "ABC" == e.get_attribute("value") @pytest.mark.xfail_firefox @@ -58,6 +56,7 @@ def test_sending_keys_to_active_element_with_modifier(driver, pages): def test_can_create_pause_action_on_keyboard(driver, pages): # If we don't get an error and takes less than 3 seconds to run, we are good import datetime + start = datetime.datetime.now() actions1 = ActionBuilder(driver) key_actions = actions1.key_action @@ -76,6 +75,7 @@ def test_can_create_pause_action_on_keyboard(driver, pages): def test_can_create_pause_action_on_pointer(driver, pages): # If we don't get an error and takes less than 3 seconds to run, we are good import datetime + start = datetime.datetime.now() actions1 = ActionBuilder(driver) key_actions = actions1.pointer_action @@ -103,11 +103,10 @@ def test_move_and_click(driver, pages): actions = ActionBuilder(driver) pointer = actions.pointer_action - pointer.move_to(toClick) \ - .click() + pointer.move_to(toClick).click() actions.perform() - assert "Clicked" == toClick.get_attribute('value') + assert "Clicked" == toClick.get_attribute("value") def test_drag_and_drop(driver, pages): @@ -124,9 +123,7 @@ def test_drag_and_drop(driver, pages): dropInto = driver.find_element(By.ID, "droppable") actions = ActionBuilder(driver) pointer = actions.pointer_action - pointer.click_and_hold(toDrag) \ - .move_to(dropInto)\ - .release() + pointer.click_and_hold(toDrag).move_to(dropInto).release() actions.perform() @@ -145,7 +142,7 @@ def test_context_click(driver, pages): pointer.context_click(toContextClick) actions.perform() - assert "ContextClicked" == toContextClick.get_attribute('value') + assert "ContextClicked" == toContextClick.get_attribute("value") @pytest.mark.xfail_firefox @@ -163,7 +160,7 @@ def test_double_click(driver, pages): pointer.double_click(toDoubleClick) actions.perform() - assert "DoubleClicked" == toDoubleClick.get_attribute('value') + assert "DoubleClicked" == toDoubleClick.get_attribute("value") def test_dragging_element_with_mouse_moves_it_to_another_list(driver, pages): @@ -186,11 +183,9 @@ def test_pen_pointer_properties(driver, pages): pointer_input = PointerInput(interaction.POINTER_PEN, "pen") actions = ActionBuilder(driver, mouse=pointer_input) center = _get_inview_center(pointerArea.rect, _get_viewport_rect(driver)) - actions.pointer_action.move_to(pointerArea) \ - .pointer_down(pressure=0.36, tilt_x=-72, tilt_y=9, twist=86) \ - .move_to(pointerArea, x=5, y=10) \ - .pointer_up() \ - .move_to(pointerArea, x=5, y=10) + actions.pointer_action.move_to(pointerArea).pointer_down(pressure=0.36, tilt_x=-72, tilt_y=9, twist=86).move_to( + pointerArea, x=5, y=10 + ).pointer_up().move_to(pointerArea, x=5, y=10) actions.perform() events = _get_events(driver) assert events[3]["type"] == "pointerdown" @@ -225,17 +220,26 @@ def test_touch_pointer_properties(driver, pages): center = _get_inview_center(pointerArea.rect, _get_viewport_rect(driver)) touch_input = PointerInput(interaction.POINTER_TOUCH, "touch") touch_chain = ActionBuilder(driver, mouse=touch_input) - touch_chain.pointer_action.move_to(pointerArea) \ - .pointer_down(width=23, height=31, pressure=0.78, tilt_x=21, tilt_y=-8, twist=355) \ - .move_to(pointerArea, x=10, y=10, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345) \ - .pointer_up() \ - .move_to(pointerArea, x=15, y=15) + touch_chain.pointer_action.move_to(pointerArea).pointer_down( + width=23, height=31, pressure=0.78, tilt_x=21, tilt_y=-8, twist=355 + ).move_to( + pointerArea, x=10, y=10, width=39, height=35, pressure=0.91, tilt_x=-19, tilt_y=62, twist=345 + ).pointer_up().move_to( + pointerArea, x=15, y=15 + ) touch_chain.perform() events = _get_events(driver) assert len(events) == 7 event_types = [e["type"] for e in events] - assert ["pointerover", "pointerenter", "pointerdown", "pointermove", - "pointerup", "pointerout", "pointerleave"] == event_types + assert [ + "pointerover", + "pointerenter", + "pointerdown", + "pointermove", + "pointerup", + "pointerout", + "pointerleave", + ] == event_types assert events[2]["type"] == "pointerdown" assert events[2]["pageX"] == pytest.approx(center["x"], abs=1.0) assert events[2]["pageY"] == pytest.approx(center["y"], abs=1.0) @@ -290,10 +294,7 @@ def _perform_drag_and_drop_with_mouse(driver, pages): actions = ActionBuilder(driver) pointer = actions.pointer_action - pointer.click_and_hold(toDrag) \ - .move_to(driver.find_element(By.ID, "leftitem-4")) \ - .move_to(dragInto) \ - .release() + pointer.click_and_hold(toDrag).move_to(driver.find_element(By.ID, "leftitem-4")).move_to(dragInto).release() assert "Nothing happened." == dragReporter.text @@ -319,7 +320,7 @@ def _get_events(driver): # example: turn "U+d83d" (6 chars) into u"\ud83d" (1 char) if "key" in e and e["key"].startswith("U+"): key = e["key"] - hex_suffix = key[key.index("+") + 1:] + hex_suffix = key[key.index("+") + 1 :] e["key"] = chr(int(hex_suffix, 16)) # WebKit sets code as 'Unidentified' for unidentified key codes, but @@ -332,14 +333,12 @@ def _get_events(driver): def _get_inview_center(elem_rect, viewport_rect): x = { "left": max(0, min(elem_rect["x"], elem_rect["x"] + elem_rect["width"])), - "right": min(viewport_rect["width"], max(elem_rect["x"], - elem_rect["x"] + elem_rect["width"])), + "right": min(viewport_rect["width"], max(elem_rect["x"], elem_rect["x"] + elem_rect["width"])), } y = { "top": max(0, min(elem_rect["y"], elem_rect["y"] + elem_rect["height"])), - "bottom": min(viewport_rect["height"], max(elem_rect["y"], - elem_rect["y"] + elem_rect["height"])), + "bottom": min(viewport_rect["height"], max(elem_rect["y"], elem_rect["y"] + elem_rect["height"])), } return { @@ -349,9 +348,11 @@ def _get_inview_center(elem_rect, viewport_rect): def _get_viewport_rect(driver): - return driver.execute_script(""" + return driver.execute_script( + """ return { height: window.innerHeight || document.documentElement.clientHeight, width: window.innerWidth || document.documentElement.clientWidth, }; - """) + """ + ) diff --git a/py/test/selenium/webdriver/common/webdriverwait_tests.py b/py/test/selenium/webdriver/common/webdriverwait_tests.py index 4b68587d31766..82adbab05e163 100644 --- a/py/test/selenium/webdriver/common/webdriverwait_tests.py +++ b/py/test/selenium/webdriver/common/webdriverwait_tests.py @@ -43,7 +43,9 @@ def test_should_explicitly_wait_for_a_single_element(driver, pages): pages.load("dynamic.html") add = driver.find_element(By.ID, "adder") add.click() - WebDriverWait(driver, 3).until(EC.presence_of_element_located((By.ID, "box0"))) # All is well if this doesn't throw. + WebDriverWait(driver, 3).until( + EC.presence_of_element_located((By.ID, "box0")) + ) # All is well if this doesn't throw. def test_should_still_fail_to_find_an_element_with_explicit_wait(driver, pages): @@ -79,7 +81,6 @@ def test_should_wait_until_at_least_one_visible_elements_is_found_when_searching add_hidden.click() class wait_for_two_elements: - def __init__(self, locator): self.locator = locator @@ -130,7 +131,7 @@ def test_should_wait_only_as_long_as_timeout_specified_when_implicit_waits_are_s def test_should_wait_at_least_once(driver, pages): pages.load("simpleTest.html") - elements = WebDriverWait(driver, 0).until(lambda d: d.find_elements(By.TAG_NAME, 'h1')) + elements = WebDriverWait(driver, 0).until(lambda d: d.find_elements(By.TAG_NAME, "h1")) assert len(elements) >= 1 @@ -145,7 +146,7 @@ def test_wait_should_still_fail_if_produce_ignored_exception(driver, pages): def test_wait_should_still_fail_if_produce_child_of_ignored_exception(driver, pages): - ignored = (WebDriverException) + ignored = WebDriverException with pytest.raises(TimeoutException): WebDriverWait(driver, 1, 0.7, ignored_exceptions=ignored).until(throw_sere) @@ -160,7 +161,7 @@ def test_expected_condition_title_is(driver, pages): WebDriverWait(driver, 1).until(EC.title_is("blank")) driver.execute_script("setTimeout(function(){document.title='not blank'}, 200)") WebDriverWait(driver, 2).until(EC.title_is("not blank")) - assert driver.title == 'not blank' + assert driver.title == "not blank" with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.title_is("blank")) @@ -169,7 +170,7 @@ def test_expected_condition_title_contains(driver, pages): pages.load("blank.html") driver.execute_script("setTimeout(function(){document.title='not blank'}, 200)") WebDriverWait(driver, 2).until(EC.title_contains("not")) - assert driver.title == 'not blank' + assert driver.title == "not blank" with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.title_contains("blanket")) @@ -178,62 +179,76 @@ def test_expected_condition_title_contains(driver, pages): def test_expected_condition_visibility_of_element_located(driver, pages): pages.load("javascriptPage.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.visibility_of_element_located((By.ID, 'clickToHide'))) - driver.find_element(By.ID, 'clickToShow').click() - element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.ID, 'clickToHide'))) + WebDriverWait(driver, 0.7).until(EC.visibility_of_element_located((By.ID, "clickToHide"))) + driver.find_element(By.ID, "clickToShow").click() + element = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.ID, "clickToHide"))) assert element.is_displayed() is True @pytest.mark.xfail_safari def test_expected_condition_visibility_of(driver, pages): pages.load("javascriptPage.html") - hidden = driver.find_element(By.ID, 'clickToHide') + hidden = driver.find_element(By.ID, "clickToHide") with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.visibility_of(hidden)) - driver.find_element(By.ID, 'clickToShow').click() + driver.find_element(By.ID, "clickToShow").click() element = WebDriverWait(driver, 5).until(EC.visibility_of(hidden)) assert element.is_displayed() is True def test_expected_condition_text_to_be_present_in_element(driver, pages): - pages.load('booleanAttributes.html') + pages.load("booleanAttributes.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.text_to_be_present_in_element((By.ID, 'unwrappable'), 'Expected')) - driver.execute_script("setTimeout(function(){var el = document.getElementById('unwrappable'); el.textContent = el.innerText = 'Unwrappable Expected text'}, 200)") - WebDriverWait(driver, 2).until(EC.text_to_be_present_in_element((By.ID, 'unwrappable'), 'Expected')) - assert 'Unwrappable Expected text' == driver.find_element(By.ID, 'unwrappable').text + WebDriverWait(driver, 0.7).until(EC.text_to_be_present_in_element((By.ID, "unwrappable"), "Expected")) + driver.execute_script( + "setTimeout(function(){var el = document.getElementById('unwrappable'); el.textContent = el.innerText = 'Unwrappable Expected text'}, 200)" + ) + WebDriverWait(driver, 2).until(EC.text_to_be_present_in_element((By.ID, "unwrappable"), "Expected")) + assert "Unwrappable Expected text" == driver.find_element(By.ID, "unwrappable").text def test_expected_condition_text_to_be_present_in_element_value(driver, pages): - pages.load('booleanAttributes.html') + pages.load("booleanAttributes.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected')) - driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)") - WebDriverWait(driver, 2).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected')) - assert 'Example Expected text' == driver.find_element(By.ID, 'inputRequired').get_attribute('value') + WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, "inputRequired"), "Expected")) + driver.execute_script( + "setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)" + ) + WebDriverWait(driver, 2).until(EC.text_to_be_present_in_element_value((By.ID, "inputRequired"), "Expected")) + assert "Example Expected text" == driver.find_element(By.ID, "inputRequired").get_attribute("value") def test_expected_condition_text_to_be_present_in_element_attribute(driver, pages): - pages.load('booleanAttributes.html') + pages.load("booleanAttributes.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_attribute((By.ID, 'inputRequired'), 'value', 'Expected')) - driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)") - WebDriverWait(driver, 2).until(EC.text_to_be_present_in_element_attribute((By.ID, 'inputRequired'), 'value', 'Expected')) - assert 'Example Expected text' == driver.find_element(By.ID, 'inputRequired').get_attribute('value') + WebDriverWait(driver, 1).until( + EC.text_to_be_present_in_element_attribute((By.ID, "inputRequired"), "value", "Expected") + ) + driver.execute_script( + "setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)" + ) + WebDriverWait(driver, 2).until( + EC.text_to_be_present_in_element_attribute((By.ID, "inputRequired"), "value", "Expected") + ) + assert "Example Expected text" == driver.find_element(By.ID, "inputRequired").get_attribute("value") def test_expected_condition_frame_to_be_available_and_switch_to_it_by_locator(driver, pages): pages.load("blank.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame'))) - driver.execute_script("setTimeout(function(){var f = document.createElement('iframe'); f.id='myFrame'; f.src = '" + pages.url('iframeWithAlert.html') + "'; document.body.appendChild(f)}, 200)") - WebDriverWait(driver, 2).until(EC.frame_to_be_available_and_switch_to_it((By.ID, 'myFrame'))) - assert 'click me' == driver.find_element(By.ID, 'alertInFrame').text + WebDriverWait(driver, 1).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "myFrame"))) + driver.execute_script( + "setTimeout(function(){var f = document.createElement('iframe'); f.id='myFrame'; f.src = '" + + pages.url("iframeWithAlert.html") + + "'; document.body.appendChild(f)}, 200)" + ) + WebDriverWait(driver, 2).until(EC.frame_to_be_available_and_switch_to_it((By.ID, "myFrame"))) + assert "click me" == driver.find_element(By.ID, "alertInFrame").text def test_expected_condition_invisiblity_of_element(driver, pages): pages.load("javascriptPage.html") - target = driver.find_element(By.ID, 'clickToHide') + target = driver.find_element(By.ID, "clickToHide") driver.execute_script("delayedShowHide(0, true)") with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.invisibility_of_element(target)) @@ -247,9 +262,9 @@ def test_expected_condition_invisiblity_of_element_located(driver, pages): pages.load("javascriptPage.html") driver.execute_script("delayedShowHide(0, true)") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.invisibility_of_element_located((By.ID, 'clickToHide'))) + WebDriverWait(driver, 0.7).until(EC.invisibility_of_element_located((By.ID, "clickToHide"))) driver.execute_script("delayedShowHide(200, false)") - element = WebDriverWait(driver, 2).until(EC.invisibility_of_element_located((By.ID, 'clickToHide'))) + element = WebDriverWait(driver, 2).until(EC.invisibility_of_element_located((By.ID, "clickToHide"))) assert element.is_displayed() is False @@ -257,22 +272,22 @@ def test_expected_condition_invisiblity_of_element_located(driver, pages): def test_expected_condition_element_to_be_clickable(driver, pages): pages.load("javascriptPage.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.element_to_be_clickable((By.ID, 'clickToHide'))) + WebDriverWait(driver, 0.7).until(EC.element_to_be_clickable((By.ID, "clickToHide"))) driver.execute_script("delayedShowHide(200, true)") - WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.ID, 'clickToHide'))) - element = driver.find_element(By.ID, 'clickToHide') + WebDriverWait(driver, 2).until(EC.element_to_be_clickable((By.ID, "clickToHide"))) + element = driver.find_element(By.ID, "clickToHide") element.click() - WebDriverWait(driver, 4.5).until(EC.invisibility_of_element_located((By.ID, 'clickToHide'))) + WebDriverWait(driver, 4.5).until(EC.invisibility_of_element_located((By.ID, "clickToHide"))) assert element.is_displayed() is False def test_expected_condition_staleness_of(driver, pages): - pages.load('dynamicallyModifiedPage.html') - element = driver.find_element(By.ID, 'element-to-remove') + pages.load("dynamicallyModifiedPage.html") + element = driver.find_element(By.ID, "element-to-remove") with pytest.raises(TimeoutException): - WebDriverWait(driver, .7).until(EC.staleness_of(element)) - driver.find_element(By.ID, 'buttonDelete').click() - assert 'element' == element.text + WebDriverWait(driver, 0.7).until(EC.staleness_of(element)) + driver.find_element(By.ID, "buttonDelete").click() + assert "element" == element.text WebDriverWait(driver, 2).until(EC.staleness_of(element)) with pytest.raises(StaleElementReferenceException): element.text @@ -280,7 +295,7 @@ def test_expected_condition_staleness_of(driver, pages): def test_expected_condition_element_to_be_selected(driver, pages): pages.load("formPage.html") - element = driver.find_element(By.ID, 'checky') + element = driver.find_element(By.ID, "checky") with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.element_to_be_selected(element)) driver.execute_script("setTimeout(function(){document.getElementById('checky').checked = true}, 200)") @@ -290,17 +305,17 @@ def test_expected_condition_element_to_be_selected(driver, pages): def test_expected_condition_element_located_to_be_selected(driver, pages): pages.load("formPage.html") - element = driver.find_element(By.ID, 'checky') + element = driver.find_element(By.ID, "checky") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.element_located_to_be_selected((By.ID, 'checky'))) + WebDriverWait(driver, 0.7).until(EC.element_located_to_be_selected((By.ID, "checky"))) driver.execute_script("setTimeout(function(){document.getElementById('checky').checked = true}, 200)") - WebDriverWait(driver, 2).until(EC.element_located_to_be_selected((By.ID, 'checky'))) + WebDriverWait(driver, 2).until(EC.element_located_to_be_selected((By.ID, "checky"))) assert element.is_selected() is True def test_expected_condition_element_selection_state_to_be(driver, pages): pages.load("formPage.html") - element = driver.find_element(By.ID, 'checky') + element = driver.find_element(By.ID, "checky") WebDriverWait(driver, 0.7).until(EC.element_selection_state_to_be(element, False)) assert element.is_selected() is False with pytest.raises(TimeoutException): @@ -312,30 +327,30 @@ def test_expected_condition_element_selection_state_to_be(driver, pages): def test_expected_condition_element_located_selection_state_to_be(driver, pages): pages.load("formPage.html") - element = driver.find_element(By.ID, 'checky') - WebDriverWait(driver, 0.7).until(EC.element_located_selection_state_to_be((By.ID, 'checky'), False)) + element = driver.find_element(By.ID, "checky") + WebDriverWait(driver, 0.7).until(EC.element_located_selection_state_to_be((By.ID, "checky"), False)) assert element.is_selected() is False with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.7).until(EC.element_located_selection_state_to_be((By.ID, 'checky'), True)) + WebDriverWait(driver, 0.7).until(EC.element_located_selection_state_to_be((By.ID, "checky"), True)) driver.execute_script("setTimeout(function(){document.getElementById('checky').checked = true}, 200)") - WebDriverWait(driver, 2).until(EC.element_located_selection_state_to_be((By.ID, 'checky'), True)) + WebDriverWait(driver, 2).until(EC.element_located_selection_state_to_be((By.ID, "checky"), True)) assert element.is_selected() is True def test_expected_condition_alert_is_present(driver, pages): - pages.load('blank.html') + pages.load("blank.html") with pytest.raises(TimeoutException): WebDriverWait(driver, 0.7).until(EC.alert_is_present()) driver.execute_script("setTimeout(function(){alert('alerty')}, 200)") WebDriverWait(driver, 2).until(EC.alert_is_present()) alert = driver.switch_to.alert - assert 'alerty' == alert.text + assert "alerty" == alert.text alert.dismiss() def test_expected_condition_attribute_to_be_include_in_element(driver, pages): - pages.load('booleanAttributes.html') + pages.load("booleanAttributes.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 1).until(EC.element_attribute_to_include((By.ID, 'inputRequired'), 'test')) - value = WebDriverWait(driver, 2).until(EC.element_attribute_to_include((By.ID, 'inputRequired'), 'value')) + WebDriverWait(driver, 1).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "test")) + value = WebDriverWait(driver, 2).until(EC.element_attribute_to_include((By.ID, "inputRequired"), "value")) assert value is not None diff --git a/py/test/selenium/webdriver/common/webserver.py b/py/test/selenium/webdriver/common/webserver.py index c84cfa1276be9..2c68b5ec8285f 100644 --- a/py/test/selenium/webdriver/common/webserver.py +++ b/py/test/selenium/webdriver/common/webserver.py @@ -46,8 +46,10 @@ def updir(): WEBDRIVER = os.environ.get("WEBDRIVER", updir()) HTML_ROOT = os.path.join(WEBDRIVER, "../../../../common/src/web") if not os.path.isdir(HTML_ROOT): - message = ("Can't find 'common_web' directory, try setting WEBDRIVER" - " environment variable WEBDRIVER:" + WEBDRIVER + " HTML_ROOT:" + HTML_ROOT) + message = ( + "Can't find 'common_web' directory, try setting WEBDRIVER" + " environment variable WEBDRIVER:" + WEBDRIVER + " HTML_ROOT:" + HTML_ROOT + ) LOGGER.error(message) assert 0, message @@ -62,18 +64,20 @@ class HtmlOnlyHandler(BaseHTTPRequestHandler): def do_GET(self): """GET method handler.""" try: - path = self.path[1:].split('?')[0] + path = self.path[1:].split("?")[0] if path[:5] == "page/": html = """Page{page_number} Page number {page_number}

top - """.format(page_number=path[5:]) - html = html.encode('utf-8') + """.format( + page_number=path[5:] + ) + html = html.encode("utf-8") else: - with open(os.path.join(HTML_ROOT, path), encoding='latin-1') as f: - html = f.read().encode('utf-8') + with open(os.path.join(HTML_ROOT, path), encoding="latin-1") as f: + html = f.read().encode("utf-8") self.send_response(200) - self.send_header('Content-type', 'text/html') + self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write(html) except OSError: @@ -82,7 +86,7 @@ def do_GET(self): def do_POST(self): """POST method handler.""" try: - remaining_bytes = int(self.headers['content-length']) + remaining_bytes = int(self.headers["content-length"]) contents = "" line = self.rfile.readline() contents += line.decode("utf-8") @@ -108,7 +112,7 @@ def do_POST(self): contents += line.decode("utf-8") self.send_response(200) - self.send_header('Content-type', 'text/html') + self.send_header("Content-type", "text/html") self.end_headers() self.wfile.write( @@ -178,12 +182,13 @@ def main(argv=None): if argv is None: import sys + argv = sys.argv parser = OptionParser("%prog [options]") - parser.add_option("-p", "--port", dest="port", type="int", - help=f"port to listen (default: {DEFAULT_PORT})", - default=DEFAULT_PORT) + parser.add_option( + "-p", "--port", dest="port", type="int", help=f"port to listen (default: {DEFAULT_PORT})", default=DEFAULT_PORT + ) opts, args = parser.parse_args(argv[1:]) if args: diff --git a/py/test/selenium/webdriver/common/window_switching_tests.py b/py/test/selenium/webdriver/common/window_switching_tests.py index 6b7949da81ddc..1e2359cd52b36 100644 --- a/py/test/selenium/webdriver/common/window_switching_tests.py +++ b/py/test/selenium/webdriver/common/window_switching_tests.py @@ -30,6 +30,7 @@ def close_windows(driver): main_windows_handle = driver.current_window_handle yield from urllib import request as url_request + URLError = url_request.URLError try: diff --git a/py/test/selenium/webdriver/common/window_tests.py b/py/test/selenium/webdriver/common/window_tests.py index bd1a6e66ec3af..d30f3ffcf3acd 100644 --- a/py/test/selenium/webdriver/common/window_tests.py +++ b/py/test/selenium/webdriver/common/window_tests.py @@ -41,80 +41,81 @@ def test_should_get_the_size_of_the_current_window(driver): size = driver.get_window_size() - assert size.get('width') > 0 - assert size.get('height') > 0 + assert size.get("width") > 0 + assert size.get("height") > 0 def test_should_set_the_size_of_the_current_window(driver): size = driver.get_window_size() - target_width = size.get('width') - 20 - target_height = size.get('height') - 20 + target_width = size.get("width") - 20 + target_height = size.get("height") - 20 driver.set_window_size(width=target_width, height=target_height) new_size = driver.get_window_size() - assert new_size.get('width') == target_width - assert new_size.get('height') == target_height + assert new_size.get("width") == target_width + assert new_size.get("height") == target_height @pytest.mark.xfail_chrome def test_should_get_the_position_of_the_current_window(driver): position = driver.get_window_position() - assert position.get('x') >= 0 - assert position.get('y') >= 0 + assert position.get("x") >= 0 + assert position.get("y") >= 0 def test_should_set_the_position_of_the_current_window(driver): position = driver.get_window_position() - target_x = position.get('x') + 10 - target_y = position.get('y') + 10 + target_x = position.get("x") + 10 + target_y = position.get("y") + 10 driver.set_window_position(x=target_x, y=target_y) - WebDriverWait(driver, 2)\ - .until(lambda d: d.get_window_position()['x'] != position['x'] and d.get_window_position()['y'] != position['y']) + WebDriverWait(driver, 2).until( + lambda d: d.get_window_position()["x"] != position["x"] and d.get_window_position()["y"] != position["y"] + ) new_position = driver.get_window_position() - assert new_position.get('x') == target_x - assert new_position.get('y') == target_y + assert new_position.get("x") == target_x + assert new_position.get("y") == target_y -@pytest.mark.xfail_safari(raises=WebDriverException, - reason='Get Window Rect command not implemented') +@pytest.mark.xfail_safari(raises=WebDriverException, reason="Get Window Rect command not implemented") @pytest.mark.xfail_chrome def test_should_get_the_rect_of_the_current_window(driver): rect = driver.get_window_rect() - assert rect.get('x') >= 0 - assert rect.get('y') >= 0 - assert rect.get('width') >= 0 - assert rect.get('height') >= 0 + assert rect.get("x") >= 0 + assert rect.get("y") >= 0 + assert rect.get("width") >= 0 + assert rect.get("height") >= 0 -@pytest.mark.xfail_safari(raises=WebDriverException, - reason='Get Window Rect command not implemented') +@pytest.mark.xfail_safari(raises=WebDriverException, reason="Get Window Rect command not implemented") def test_should_set_the_rect_of_the_current_window(driver): rect = driver.get_window_rect() - target_x = rect.get('x') + 10 - target_y = rect.get('y') + 10 - target_width = rect.get('width') + 10 - target_height = rect.get('height') + 10 + target_x = rect.get("x") + 10 + target_y = rect.get("y") + 10 + target_width = rect.get("width") + 10 + target_height = rect.get("height") + 10 driver.set_window_rect(x=target_x, y=target_y, width=target_width, height=target_height) - WebDriverWait(driver, 2)\ - .until(lambda d: d.get_window_position()['x'] != rect['x'] and d.get_window_position()['y'] != rect['y']) + WebDriverWait(driver, 2).until( + lambda d: d.get_window_position()["x"] != rect["x"] and d.get_window_position()["y"] != rect["y"] + ) new_rect = driver.get_window_rect() - assert new_rect.get('x') == target_x - assert new_rect.get('y') == target_y - assert new_rect.get('width') == target_width - assert new_rect.get('height') == target_height + assert new_rect.get("x") == target_x + assert new_rect.get("y") == target_y + assert new_rect.get("width") == target_width + assert new_rect.get("height") == target_height def test_set_window_rect_should_accept_0_as_x_and_y(driver): from selenium.common.exceptions import InvalidArgumentException + try: driver.set_window_rect(x=0, y=0) except InvalidArgumentException: @@ -123,6 +124,7 @@ def test_set_window_rect_should_accept_0_as_x_and_y(driver): def test_set_window_rect_throws_when_height_and_width_are_0(driver): from selenium.common.exceptions import InvalidArgumentException + with pytest.raises(InvalidArgumentException): driver.set_window_rect(height=0, width=0) diff --git a/py/test/selenium/webdriver/firefox/ff_installs_addons_tests.py b/py/test/selenium/webdriver/firefox/ff_installs_addons_tests.py index b13ed994e6ba1..0fdd9f8c688b8 100644 --- a/py/test/selenium/webdriver/firefox/ff_installs_addons_tests.py +++ b/py/test/selenium/webdriver/firefox/ff_installs_addons_tests.py @@ -27,7 +27,7 @@ def test_install_uninstall_signed_addon_xpi(driver, pages): extension = os.path.join(extensions, "webextensions-selenium-example.xpi") id = driver.install_addon(extension) - assert id == 'webextensions-selenium-example@example.com' + assert id == "webextensions-selenium-example@example.com" pages.load("blank.html") injected = driver.find_element(By.ID, "webextensions-selenium-example") @@ -42,7 +42,7 @@ def test_install_uninstall_signed_addon_zip(driver, pages): extension = os.path.join(extensions, "webextensions-selenium-example.zip") id = driver.install_addon(extension) - assert id == 'webextensions-selenium-example@example.com' + assert id == "webextensions-selenium-example@example.com" pages.load("blank.html") injected = driver.find_element(By.ID, "webextensions-selenium-example") @@ -54,10 +54,10 @@ def test_install_uninstall_signed_addon_zip(driver, pages): def test_install_uninstall_unsigned_addon_zip(driver, pages): - extension = os.path.join(extensions, 'webextensions-selenium-example-unsigned.zip') + extension = os.path.join(extensions, "webextensions-selenium-example-unsigned.zip") id = driver.install_addon(extension, temporary=True) - assert id == 'webextensions-selenium-example@example.com' + assert id == "webextensions-selenium-example@example.com" pages.load("blank.html") injected = driver.find_element(By.ID, "webextensions-selenium-example") @@ -69,14 +69,14 @@ def test_install_uninstall_unsigned_addon_zip(driver, pages): def test_install_uninstall_signed_addon_dir(driver, pages): - zip = os.path.join(extensions, 'webextensions-selenium-example.zip') + zip = os.path.join(extensions, "webextensions-selenium-example.zip") - target = os.path.join(extensions, 'webextensions-selenium-example') - with zipfile.ZipFile(zip, 'r') as zip_ref: + target = os.path.join(extensions, "webextensions-selenium-example") + with zipfile.ZipFile(zip, "r") as zip_ref: zip_ref.extractall(target) id = driver.install_addon(target) - assert id == 'webextensions-selenium-example@example.com' + assert id == "webextensions-selenium-example@example.com" pages.load("blank.html") injected = driver.find_element(By.ID, "webextensions-selenium-example") @@ -88,13 +88,13 @@ def test_install_uninstall_signed_addon_dir(driver, pages): def test_install_uninstall_unsigned_addon_dir(driver, pages): - zip = os.path.join(extensions, 'webextensions-selenium-example-unsigned.zip') - target = os.path.join(extensions, 'webextensions-selenium-example-unsigned') - with zipfile.ZipFile(zip, 'r') as zip_ref: + zip = os.path.join(extensions, "webextensions-selenium-example-unsigned.zip") + target = os.path.join(extensions, "webextensions-selenium-example-unsigned") + with zipfile.ZipFile(zip, "r") as zip_ref: zip_ref.extractall(target) id = driver.install_addon(target, temporary=True) - assert id == 'webextensions-selenium-example@example.com' + assert id == "webextensions-selenium-example@example.com" pages.load("blank.html") injected = driver.find_element(By.ID, "webextensions-selenium-example") diff --git a/py/test/selenium/webdriver/firefox/ff_takes_full_page_screenshots_tests.py b/py/test/selenium/webdriver/firefox/ff_takes_full_page_screenshots_tests.py index 01c1d435561c5..03ecd0d3cb562 100644 --- a/py/test/selenium/webdriver/firefox/ff_takes_full_page_screenshots_tests.py +++ b/py/test/selenium/webdriver/firefox/ff_takes_full_page_screenshots_tests.py @@ -22,10 +22,10 @@ def test_get_full_page_screenshot_as_base64(driver, pages): pages.load("simpleTest.html") result = base64.b64decode(driver.get_full_page_screenshot_as_base64()) - assert imghdr.what('', result) == 'png' + assert imghdr.what("", result) == "png" def test_get_full_page_screenshot_as_png(driver, pages): pages.load("simpleTest.html") result = driver.get_full_page_screenshot_as_png() - assert imghdr.what('', result) == 'png' + assert imghdr.what("", result) == "png" diff --git a/py/test/selenium/webdriver/marionette/conftest.py b/py/test/selenium/webdriver/marionette/conftest.py index 77871a7e24104..68f7c09dcfaa8 100644 --- a/py/test/selenium/webdriver/marionette/conftest.py +++ b/py/test/selenium/webdriver/marionette/conftest.py @@ -22,7 +22,7 @@ @pytest.fixture def capabilities(): - capabilities = {'marionette': True} + capabilities = {"marionette": True} return capabilities @@ -33,7 +33,7 @@ def driver_class(): @pytest.fixture def driver_kwargs(capabilities): - return {'capabilities': capabilities} + return {"capabilities": capabilities} @pytest.fixture diff --git a/py/test/selenium/webdriver/marionette/mn_context_tests.py b/py/test/selenium/webdriver/marionette/mn_context_tests.py index 8722e98c1b958..c8c53cf6fc61a 100644 --- a/py/test/selenium/webdriver/marionette/mn_context_tests.py +++ b/py/test/selenium/webdriver/marionette/mn_context_tests.py @@ -17,9 +17,8 @@ def test_context_sets_correct_context_and_returns(driver): - def get_context(): - return driver.execute('GET_CONTEXT').pop('value') + return driver.execute("GET_CONTEXT").pop("value") assert get_context() == driver.CONTEXT_CONTENT with driver.context(driver.CONTEXT_CHROME): diff --git a/py/test/selenium/webdriver/marionette/mn_launcher_tests.py b/py/test/selenium/webdriver/marionette/mn_launcher_tests.py index e81f0258fd274..8c8da755463c4 100644 --- a/py/test/selenium/webdriver/marionette/mn_launcher_tests.py +++ b/py/test/selenium/webdriver/marionette/mn_launcher_tests.py @@ -19,7 +19,7 @@ def test_launch_and_close_browser(driver): - assert 'browserName' in driver.capabilities + assert "browserName" in driver.capabilities def test_we_can_launch_multiple_firefox_instances(capabilities): diff --git a/py/test/selenium/webdriver/marionette/mn_options_tests.py b/py/test/selenium/webdriver/marionette/mn_options_tests.py index 5870425e938f2..10d14c65749bf 100644 --- a/py/test/selenium/webdriver/marionette/mn_options_tests.py +++ b/py/test/selenium/webdriver/marionette/mn_options_tests.py @@ -27,7 +27,7 @@ @pytest.fixture def driver_kwargs(driver_kwargs): - driver_kwargs['options'] = Options() + driver_kwargs["options"] = Options() return driver_kwargs diff --git a/py/test/selenium/webdriver/marionette/mn_set_context_tests.py b/py/test/selenium/webdriver/marionette/mn_set_context_tests.py index 6a64a713ef730..bbe712ed279e6 100644 --- a/py/test/selenium/webdriver/marionette/mn_set_context_tests.py +++ b/py/test/selenium/webdriver/marionette/mn_set_context_tests.py @@ -17,5 +17,5 @@ def test_we_can_switch_context_to_chrome(driver): - driver.set_context('chrome') + driver.set_context("chrome") assert 1 == driver.execute_script("var c = Components.classes; return 1;") diff --git a/py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py b/py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py index 09184e436836a..5d0a7b3cf4d76 100644 --- a/py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py +++ b/py/test/selenium/webdriver/remote/remote_firefox_profile_tests.py @@ -24,7 +24,7 @@ @pytest.fixture def capabilities(): capabilities = DesiredCapabilities.FIREFOX.copy() - capabilities['marionette'] = False + capabilities["marionette"] = False return capabilities @@ -38,9 +38,9 @@ def driver(options): @pytest.fixture def options(): options = webdriver.FirefoxOptions() - options.set_preference('browser.startup.homepage', 'about:') + options.set_preference("browser.startup.homepage", "about:") return options def test_profile_is_used(driver): - assert 'about:blank' == driver.current_url or 'about:' == driver.current_url + assert "about:blank" == driver.current_url or "about:" == driver.current_url diff --git a/py/test/selenium/webdriver/remote/remote_hub_connection.py b/py/test/selenium/webdriver/remote/remote_hub_connection.py index 48616399be8d3..2a70fe0bad826 100644 --- a/py/test/selenium/webdriver/remote/remote_hub_connection.py +++ b/py/test/selenium/webdriver/remote/remote_hub_connection.py @@ -23,6 +23,6 @@ def test_command_executor_ssl_certificate_is_verified(): with pytest.raises(urllib3.exceptions.MaxRetryError) as excinfo: - webdriver.Remote(command_executor='https://wrong.host.badssl.com/') + webdriver.Remote(command_executor="https://wrong.host.badssl.com/") assert isinstance(excinfo.value.reason, urllib3.exceptions.SSLError) assert "doesn't match" in str(excinfo.value) diff --git a/py/test/selenium/webdriver/safari/launcher_tests.py b/py/test/selenium/webdriver/safari/launcher_tests.py index be37b66624b59..7117a9f4ba493 100644 --- a/py/test/selenium/webdriver/safari/launcher_tests.py +++ b/py/test/selenium/webdriver/safari/launcher_tests.py @@ -21,47 +21,53 @@ def test_launch(driver): - assert driver.capabilities['browserName'] == 'Safari' + assert driver.capabilities["browserName"] == "Safari" def test_launch_with_invalid_executable_path_raises_exception(driver_class): - path = '/this/path/should/never/exist' + path = "/this/path/should/never/exist" assert not os.path.exists(path) with pytest.raises(Exception) as e: driver_class(executable_path=path) - assert 'are you running Safari 10 or later?' in str(e) + assert "are you running Safari 10 or later?" in str(e) -@pytest.mark.skipif(not os.path.exists('/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver'), reason="Preview not installed") +@pytest.mark.skipif( + not os.path.exists("/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver"), + reason="Preview not installed", +) class TestTechnologyPreview: - @pytest.fixture def driver_kwargs(self): - path = '/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver' - assert os.path.exists(path), 'Safari Technology Preview required! Download it from https://developer.apple.com/safari/technology-preview/' - return {'executable_path': path} + path = "/Applications/Safari Technology Preview.app/Contents/MacOS/safaridriver" + assert os.path.exists( + path + ), "Safari Technology Preview required! Download it from https://developer.apple.com/safari/technology-preview/" + return {"executable_path": path} def test_launch(self, driver): - assert driver.capabilities['browserName'] == 'safari' + assert driver.capabilities["browserName"] == "safari" def test_launch_safari_with_legacy_flag(mocker, driver_class): import subprocess - mocker.patch('subprocess.Popen') + + mocker.patch("subprocess.Popen") try: - driver_class(service_args=['--legacy']) + driver_class(service_args=["--legacy"]) except Exception: pass args, kwargs = subprocess.Popen.call_args - assert '--legacy' in args[0] + assert "--legacy" in args[0] def test_launch_safari_without_legacy_flag(mocker, driver_class): import subprocess - mocker.patch('subprocess.Popen') + + mocker.patch("subprocess.Popen") try: driver_class() except Exception: pass args, kwargs = subprocess.Popen.call_args - assert '--legacy' not in args[0] + assert "--legacy" not in args[0] diff --git a/py/test/selenium/webdriver/support/conftest.py b/py/test/selenium/webdriver/support/conftest.py index 75670927e31e3..043b7df7e146f 100644 --- a/py/test/selenium/webdriver/support/conftest.py +++ b/py/test/selenium/webdriver/support/conftest.py @@ -17,5 +17,5 @@ def pytest_generate_tests(metafunc): - if 'driver' in metafunc.fixturenames and metafunc.config.option.drivers: - metafunc.parametrize('driver', metafunc.config.option.drivers, indirect=True) + if "driver" in metafunc.fixturenames and metafunc.config.option.drivers: + metafunc.parametrize("driver", metafunc.config.option.drivers, indirect=True) diff --git a/py/test/selenium/webdriver/support/event_firing_webdriver_tests.py b/py/test/selenium/webdriver/support/event_firing_webdriver_tests.py index 22399b50017c4..6b6bf77ade830 100644 --- a/py/test/selenium/webdriver/support/event_firing_webdriver_tests.py +++ b/py/test/selenium/webdriver/support/event_firing_webdriver_tests.py @@ -36,9 +36,7 @@ def log(): def test_should_fire_navigation_events(driver, log, pages): - class EventListener(AbstractEventListener): - def before_navigate_to(self, url, driver): log.write(("before_navigate_to %s" % url.split("/")[-1]).encode()) @@ -69,19 +67,19 @@ def after_navigate_forward(self, driver): ef_driver.forward() assert ef_driver.title == "We Arrive Here" - assert (b"before_navigate_to formPage.html" - b"after_navigate_to formPage.html" - b"before_navigate_back" - b"after_navigate_back" - b"before_navigate_forward" - b"after_navigate_forward") == log.getvalue() + assert ( + b"before_navigate_to formPage.html" + b"after_navigate_to formPage.html" + b"before_navigate_back" + b"after_navigate_back" + b"before_navigate_forward" + b"after_navigate_forward" + ) == log.getvalue() @pytest.mark.xfail_safari def test_should_fire_click_event(driver, log, pages): - class EventListener(AbstractEventListener): - def before_click(self, element, driver): log.write(b"before_click") @@ -97,9 +95,7 @@ def after_click(self, element, driver): def test_should_fire_change_value_event(driver, log, pages): - class EventListener(AbstractEventListener): - def before_change_value_of(self, element, driver): log.write(b"before_change_value_of") @@ -117,16 +113,13 @@ def after_change_value_of(self, element, driver): keyReporter.send_keys("abc def") assert keyReporter.get_attribute("value") == "abc def" - assert (b"before_change_value_of" - b"after_change_value_of" - b"before_change_value_of" - b"after_change_value_of") == log.getvalue() + assert ( + b"before_change_value_of" b"after_change_value_of" b"before_change_value_of" b"after_change_value_of" + ) == log.getvalue() def test_should_fire_find_event(driver, log, pages): - class EventListener(AbstractEventListener): - def before_find(self, by, value, driver): log.write((f"before_find by {by} {value}").encode()) @@ -147,16 +140,17 @@ def after_find(self, by, value, driver): assert "frame" == elements[0].tag_name.lower() assert "sixth" == elements[0].get_attribute("id") - assert (b"before_find by id oneline" - b"after_find by id oneline" - b"before_find by xpath /html/body/p[1]" - b"after_find by xpath /html/body/p[1]" - b"before_find by css selector frame#sixth" - b"after_find by css selector frame#sixth") == log.getvalue() + assert ( + b"before_find by id oneline" + b"after_find by id oneline" + b"before_find by xpath /html/body/p[1]" + b"after_find by xpath /html/body/p[1]" + b"before_find by css selector frame#sixth" + b"after_find by css selector frame#sixth" + ) == log.getvalue() def test_should_call_listener_when_an_exception_is_thrown(driver, log, pages): - class EventListener(AbstractEventListener): def on_exception(self, exception, driver): if isinstance(exception, NoSuchElementException): @@ -174,8 +168,8 @@ def test_should_unwrap_element_args_when_calling_scripts(driver, log, pages): ef_driver.get(pages.url("javascriptPage.html")) button = ef_driver.find_element(By.ID, "plainButton") value = ef_driver.execute_script( - "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble']", - button) + "arguments[0]['flibble'] = arguments[0].getAttribute('id'); return arguments[0]['flibble']", button + ) assert "plainButton" == value @@ -188,7 +182,6 @@ def test_should_unwrap_element_args_when_switching_frames(driver, log, pages): def test_should_be_able_to_access_wrapped_instance_from_event_calls(driver): - class EventListener(AbstractEventListener): def before_navigate_to(url, d): assert driver is d @@ -229,7 +222,7 @@ def test_can_use_pointer_input_with_event_firing_webdriver(driver, pages): pointer.move_to(to_click).click() actions.perform() - assert to_click.get_attribute('value') == 'Clicked' + assert to_click.get_attribute("value") == "Clicked" @pytest.mark.xfail_safari @@ -240,8 +233,8 @@ def test_can_use_key_input_with_event_firing_webdriver(driver, pages): actions = ActionBuilder(ef_driver) key = actions.key_action - key.send_keys('Success') + key.send_keys("Success") actions.perform() result = ef_driver.find_element(By.ID, "result") - assert result.text == 'Success' + assert result.text == "Success" diff --git a/py/test/selenium/webdriver/support/expected_conditions_tests.py b/py/test/selenium/webdriver/support/expected_conditions_tests.py index 2e04a6e9f03e0..22b5361d51873 100644 --- a/py/test/selenium/webdriver/support/expected_conditions_tests.py +++ b/py/test/selenium/webdriver/support/expected_conditions_tests.py @@ -26,22 +26,20 @@ def test_any_of_true(driver, pages): pages.load("simpleTest.html") - WebDriverWait(driver, 0.1).until(EC.any_of( - EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) + WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) def test_any_of_false(driver, pages): pages.load("simpleTest.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.1).until(EC.any_of( - EC.title_is("Nope"), EC.title_is("Still Nope"))) + WebDriverWait(driver, 0.1).until(EC.any_of(EC.title_is("Nope"), EC.title_is("Still Nope"))) def test_all_of_true(driver, pages): pages.load("simpleTest.html") - results = WebDriverWait(driver, 0.1).until(EC.all_of( - EC.title_is("Hello WebDriver"), - EC.visibility_of_element_located((By.ID, "oneline")))) + results = WebDriverWait(driver, 0.1).until( + EC.all_of(EC.title_is("Hello WebDriver"), EC.visibility_of_element_located((By.ID, "oneline"))) + ) assert results[0] is True assert isinstance(results[1], WebElement) @@ -49,35 +47,30 @@ def test_all_of_true(driver, pages): def test_all_of_false(driver, pages): pages.load("simpleTest.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.1).until(EC.all_of( - EC.title_is("Nope"), EC.title_is("Still Nope"))) + WebDriverWait(driver, 0.1).until(EC.all_of(EC.title_is("Nope"), EC.title_is("Still Nope"))) def test_none_of_true(driver, pages): pages.load("simpleTest.html") - WebDriverWait(driver, 0.1).until(EC.none_of( - EC.title_is("Nope"), EC.title_is("Still Nope"))) + WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Still Nope"))) def test_none_of_false(driver, pages): pages.load("simpleTest.html") with pytest.raises(TimeoutException): - WebDriverWait(driver, 0.1).until(EC.none_of( - EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) + WebDriverWait(driver, 0.1).until(EC.none_of(EC.title_is("Nope"), EC.title_is("Hello WebDriver"))) def test_clickable_locator_true(driver, pages): pages.load("simpleTest.html") - WebDriverWait(driver, 0.1).until( - EC.element_to_be_clickable((By.ID, "multilinelink"))) + WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "multilinelink"))) def test_clickable_locator_false(driver, pages): pages.load("simpleTest.html") with pytest.raises(TimeoutException): # text element, should not be clickable - WebDriverWait(driver, 0.1).until( - EC.element_to_be_clickable((By.ID, "hiddenline"))) + WebDriverWait(driver, 0.1).until(EC.element_to_be_clickable((By.ID, "hiddenline"))) def test_clickable_element_true(driver, pages): diff --git a/py/test/selenium/webdriver/support/relative_by_tests.py b/py/test/selenium/webdriver/support/relative_by_tests.py index 7c4ee24e96e3c..49868eed4c159 100644 --- a/py/test/selenium/webdriver/support/relative_by_tests.py +++ b/py/test/selenium/webdriver/support/relative_by_tests.py @@ -28,7 +28,7 @@ def test_should_be_able_to_find_first_one(driver, pages): el = driver.find_element(with_tag_name("p").above(lowest)) - assert el.get_attribute('id') == "mid" + assert el.get_attribute("id") == "mid" def test_should_be_able_to_find_elements_above_another(driver, pages): @@ -37,7 +37,7 @@ def test_should_be_able_to_find_elements_above_another(driver, pages): elements = driver.find_elements(with_tag_name("p").above(lowest)) - ids = [el.get_attribute('id') for el in elements] + ids = [el.get_attribute("id") for el in elements] assert "above" in ids assert "mid" in ids @@ -45,30 +45,39 @@ def test_should_be_able_to_find_elements_above_another(driver, pages): def test_should_be_able_to_combine_filters(driver, pages): pages.load("relative_locators.html") - elements = driver.find_elements(with_tag_name("td").above(driver.find_element(By.ID, "center")) - .to_right_of(driver.find_element(By.ID, "second"))) + elements = driver.find_elements( + with_tag_name("td") + .above(driver.find_element(By.ID, "center")) + .to_right_of(driver.find_element(By.ID, "second")) + ) - ids = [el.get_attribute('id') for el in elements] + ids = [el.get_attribute("id") for el in elements] assert "third" in ids def test_should_be_able_to_use_css_selectors(driver, pages): pages.load("relative_locators.html") - elements = driver.find_elements(locate_with(By.CSS_SELECTOR, "td").above(driver.find_element(By.ID, "center")) - .to_right_of(driver.find_element(By.ID, "second"))) + elements = driver.find_elements( + locate_with(By.CSS_SELECTOR, "td") + .above(driver.find_element(By.ID, "center")) + .to_right_of(driver.find_element(By.ID, "second")) + ) - ids = [el.get_attribute('id') for el in elements] + ids = [el.get_attribute("id") for el in elements] assert "third" in ids def test_should_be_able_to_use_xpath(driver, pages): pages.load("relative_locators.html") - elements = driver.find_elements(locate_with(By.XPATH, "//td[1]").below(driver.find_element(By.ID, "second")) - .above(driver.find_element(By.ID, "seventh"))) + elements = driver.find_elements( + locate_with(By.XPATH, "//td[1]") + .below(driver.find_element(By.ID, "second")) + .above(driver.find_element(By.ID, "seventh")) + ) - ids = [el.get_attribute('id') for el in elements] + ids = [el.get_attribute("id") for el in elements] assert "fourth" in ids diff --git a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py index 46172f507dfec..6d6135b5bd510 100644 --- a/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py +++ b/py/test/unit/selenium/webdriver/chrome/chrome_options_tests.py @@ -28,33 +28,33 @@ def options(): def test_set_binary_location(options): - options.binary_location = '/foo/bar' - assert options._binary_location == '/foo/bar' + options.binary_location = "/foo/bar" + assert options._binary_location == "/foo/bar" def test_get_binary_location(options): - options._binary_location = '/foo/bar' - assert options.binary_location == '/foo/bar' + options._binary_location = "/foo/bar" + assert options.binary_location == "/foo/bar" def test_set_debugger_address(options): - options.debugger_address = '/foo/bar' - assert options._debugger_address == '/foo/bar' + options.debugger_address = "/foo/bar" + assert options._debugger_address == "/foo/bar" def test_get_debugger_address(options): - options._debugger_address = '/foo/bar' - assert options.debugger_address == '/foo/bar' + options._debugger_address = "/foo/bar" + assert options.debugger_address == "/foo/bar" def test_add_arguments(options): - options.add_argument('foo') - assert 'foo' in options._arguments + options.add_argument("foo") + assert "foo" in options._arguments def test_get_arguments(options): - options._arguments = ['foo'] - assert 'foo' in options.arguments + options._arguments = ["foo"] + assert "foo" in options.arguments def test_raises_exception_if_argument_is_falsy(options): @@ -69,12 +69,12 @@ def test_raises_exception_if_extension_is_falsy(options): def test_raises_exception_if_extension_does_not_exist(options): with pytest.raises(IOError): - options.add_extension(path.join(path.abspath(path.curdir), 'fakepath')) + options.add_extension(path.join(path.abspath(path.curdir), "fakepath")) def test_add_extension(options, mocker): - pth = path.abspath(path.expanduser('/foo/bar')) - mocker.patch('os.path.exists').return_value = True + pth = path.abspath(path.expanduser("/foo/bar")) + mocker.patch("os.path.exists").return_value = True options.add_extension(pth) assert pth in options._extension_files @@ -85,68 +85,68 @@ def test_raises_exception_if_encoded_extension_is_falsy(options): def test_add_encoded_extension(options): - options.add_encoded_extension('/foo/bar') - assert '/foo/bar' in options._extensions + options.add_encoded_extension("/foo/bar") + assert "/foo/bar" in options._extensions def test_get_extensions_from_extension_files(options, mocker): - null = 'NUL' if platform.system().lower() == 'windows' else '/dev/null' - mocker.patch( - 'selenium.webdriver.chromium.options.open').return_value = open(null) - mocker.patch('base64.b64encode').return_value = b'foo' - options._extension_files = ['foo'] - assert 'foo' in options.extensions + null = "NUL" if platform.system().lower() == "windows" else "/dev/null" + mocker.patch("selenium.webdriver.chromium.options.open").return_value = open(null) + mocker.patch("base64.b64encode").return_value = b"foo" + options._extension_files = ["foo"] + assert "foo" in options.extensions def test_get_extensions_from_encoded_extensions(options, mocker): - options._extensions = ['foo'] - assert 'foo' in options.extensions + options._extensions = ["foo"] + assert "foo" in options.extensions def test_add_experimental_options(options): - options.add_experimental_option('foo', 'bar') - assert options._experimental_options['foo'] == 'bar' + options.add_experimental_option("foo", "bar") + assert options._experimental_options["foo"] == "bar" def test_get_experimental_options(options): - options._experimental_options = {'foo': 'bar'} - assert options.experimental_options['foo'] == 'bar' + options._experimental_options = {"foo": "bar"} + assert options.experimental_options["foo"] == "bar" def test_set_headless(options): options.headless = True - assert '--headless' in options._arguments + assert "--headless" in options._arguments def test_unset_headless(options): - options._arguments = ['--headless'] + options._arguments = ["--headless"] options.headless = False - assert '--headless' not in options._arguments + assert "--headless" not in options._arguments def test_get_headless(options): - options._arguments = ['--headless'] + options._arguments = ["--headless"] assert options.headless is True def test_creates_capabilities(options): - options._arguments = ['foo'] - options._binary_location = '/bar' - options._extensions = ['baz'] - options._debugger_address = '/foo/bar' - options._experimental_options = {'foo': 'bar'} + options._arguments = ["foo"] + options._binary_location = "/bar" + options._extensions = ["baz"] + options._debugger_address = "/foo/bar" + options._experimental_options = {"foo": "bar"} caps = options.to_capabilities() opts = caps.get(Options.KEY) assert opts - assert 'foo' in opts['args'] - assert opts['binary'] == '/bar' - assert 'baz' in opts['extensions'] - assert opts['debuggerAddress'] == '/foo/bar' - assert opts['foo'] == 'bar' + assert "foo" in opts["args"] + assert opts["binary"] == "/bar" + assert "baz" in opts["extensions"] + assert opts["debuggerAddress"] == "/foo/bar" + assert opts["foo"] == "bar" def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.CHROME.copy() caps.update({"pageLoadStrategy": "normal"}) assert options._caps == caps @@ -154,6 +154,7 @@ def test_starts_with_default_capabilities(options): def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions) diff --git a/py/test/unit/selenium/webdriver/common/common_options_tests.py b/py/test/unit/selenium/webdriver/common/common_options_tests.py index 63c6073ccc5a9..4973e9b15fc57 100644 --- a/py/test/unit/selenium/webdriver/common/common_options_tests.py +++ b/py/test/unit/selenium/webdriver/common/common_options_tests.py @@ -26,13 +26,13 @@ def options(): def test_add_arguments(options): - options.add_argument('foo') - assert 'foo' in options._arguments + options.add_argument("foo") + assert "foo" in options._arguments def test_get_arguments(options): - options._arguments = ['foo'] - assert 'foo' in options.arguments + options._arguments = ["foo"] + assert "foo" in options.arguments def test_enables_mobile(options): @@ -48,15 +48,12 @@ def test_enable_mobile_errors_without_package(options): def test_enable_mobile_with_activity(options): - options.enable_mobile(android_package="sausages", - android_activity="eating") + options.enable_mobile(android_package="sausages", android_activity="eating") assert options.mobile_options["androidActivity"] == "eating" def test_enable_mobile_with_device_serial(options): - options.enable_mobile(android_package="cheese", - android_activity="crackers", - device_serial="1234") + options.enable_mobile(android_package="cheese", android_activity="crackers", device_serial="1234") options.mobile_options["androidDeviceSerial"] == "1234" diff --git a/py/test/unit/selenium/webdriver/common/print_page_options_tests.py b/py/test/unit/selenium/webdriver/common/print_page_options_tests.py index c7d01960efee3..76666de94f746 100644 --- a/py/test/unit/selenium/webdriver/common/print_page_options_tests.py +++ b/py/test/unit/selenium/webdriver/common/print_page_options_tests.py @@ -26,13 +26,13 @@ def print_options(): def test_set_orientation(print_options): - print_options.orientation = 'portrait' - assert print_options.orientation == 'portrait' + print_options.orientation = "portrait" + assert print_options.orientation == "portrait" def test_raises_exception_if_orientation_is_invalid(print_options): with pytest.raises(ValueError): - print_options.orientation = 'foobar' + print_options.orientation = "foobar" def test_set_scale(print_options): @@ -86,17 +86,17 @@ def test_set_shrink_to_fit(print_options): def test_raises_exception_if_set_shrink_to_fit_non_bool(print_options): with pytest.raises(ValueError): - print_options.shrink_to_fit = 'True' + print_options.shrink_to_fit = "True" def test_set_page_ranges(print_options): - print_options.page_ranges = ['1-2'] - assert print_options.page_ranges == ['1-2'] + print_options.page_ranges = ["1-2"] + assert print_options.page_ranges == ["1-2"] def test_raises_exception_if_page_ranges_not_list(print_options): with pytest.raises(ValueError): - print_options.page_ranges = 'foobar' + print_options.page_ranges = "foobar" def test_margin_height(print_options): diff --git a/py/test/unit/selenium/webdriver/edge/edge_options_tests.py b/py/test/unit/selenium/webdriver/edge/edge_options_tests.py index 58b4434924746..3822ca66b9323 100644 --- a/py/test/unit/selenium/webdriver/edge/edge_options_tests.py +++ b/py/test/unit/selenium/webdriver/edge/edge_options_tests.py @@ -27,28 +27,29 @@ def options(): def test_raises_exception_with_invalid_page_load_strategy(options): with pytest.raises(ValueError): - options.page_load_strategy = 'never' + options.page_load_strategy = "never" def test_set_page_load_strategy(options): - options.page_load_strategy = 'normal' + options.page_load_strategy = "normal" caps = options.to_capabilities() - assert caps['pageLoadStrategy'] == 'normal' + assert caps["pageLoadStrategy"] == "normal" def test_get_page_load_strategy(options): - options._caps['pageLoadStrategy'] = 'normal' - assert options.page_load_strategy == 'normal' + options._caps["pageLoadStrategy"] = "normal" + assert options.page_load_strategy == "normal" def test_creates_capabilities(options): - options.page_load_strategy = 'eager' + options.page_load_strategy = "eager" caps = options.to_capabilities() - assert caps['pageLoadStrategy'] == 'eager' + assert caps["pageLoadStrategy"] == "eager" def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.EDGE.copy() caps.update({"pageLoadStrategy": "normal"}) assert options._caps == caps @@ -56,6 +57,7 @@ def test_starts_with_default_capabilities(options): def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions) @@ -63,4 +65,4 @@ def test_use_webview(): options = Options() options.use_webview = True caps = options.to_capabilities() - assert caps['browserName'] == "webview2" + assert caps["browserName"] == "webview2" diff --git a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py index 8f3e81a797186..5cfcff7409a71 100644 --- a/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py +++ b/py/test/unit/selenium/webdriver/firefox/firefox_options_tests.py @@ -31,49 +31,49 @@ def options(): def test_set_binary_with_firefox_binary(options): - binary = FirefoxBinary('foo') + binary = FirefoxBinary("foo") options.binary = binary assert options._binary == binary def test_set_binary_with_path(options): - options.binary = '/foo' - assert options._binary._start_cmd == '/foo' + options.binary = "/foo" + assert options._binary._start_cmd == "/foo" def test_get_binary(options): - options.binary = '/foo' - assert options.binary._start_cmd == '/foo' + options.binary = "/foo" + assert options.binary._start_cmd == "/foo" def test_set_binary_location(options): - options.binary_location = '/foo' - assert options._binary._start_cmd == '/foo' + options.binary_location = "/foo" + assert options._binary._start_cmd == "/foo" def test_get_binary_location(options): - options._binary = FirefoxBinary('/foo') - assert options.binary_location == '/foo' + options._binary = FirefoxBinary("/foo") + assert options.binary_location == "/foo" def test_set_preference(options): - options.set_preference('foo', 'bar') - assert options._preferences['foo'] == 'bar' + options.set_preference("foo", "bar") + assert options._preferences["foo"] == "bar" def test_get_preferences(options): - options._preferences = {'foo': 'bar'} - assert options.preferences['foo'] == 'bar' + options._preferences = {"foo": "bar"} + assert options.preferences["foo"] == "bar" def test_set_proxy(options): - proxy = Proxy({'proxyType': ProxyType.MANUAL}) + proxy = Proxy({"proxyType": ProxyType.MANUAL}) options.proxy = proxy assert options._proxy == proxy def test_set_proxy_isnt_in_moz_prefix(options): - proxy = Proxy({'proxyType': ProxyType.MANUAL}) + proxy = Proxy({"proxyType": ProxyType.MANUAL}) options.proxy = proxy caps = options.to_capabilities() @@ -83,12 +83,12 @@ def test_set_proxy_isnt_in_moz_prefix(options): def test_raises_exception_if_proxy_is_not_proxy_object(options): with pytest.raises(InvalidArgumentException): - options.proxy = 'foo' + options.proxy = "foo" def test_get_proxy(options): - options._proxy = 'foo' - assert options.proxy == 'foo' + options._proxy = "foo" + assert options.proxy == "foo" def test_set_profile_with_firefox_profile(options): @@ -103,18 +103,18 @@ def test_set_profile_with_path(options): def test_get_profile(options): - options._profile = 'foo' - assert options.profile == 'foo' + options._profile = "foo" + assert options.profile == "foo" def test_add_arguments(options): - options.add_argument('foo') - assert 'foo' in options._arguments + options.add_argument("foo") + assert "foo" in options._arguments def test_get_arguments(options): - options._arguments = ['foo'] - assert 'foo' in options.arguments + options._arguments = ["foo"] + assert "foo" in options.arguments def test_raises_exception_if_argument_is_falsy(options): @@ -123,47 +123,48 @@ def test_raises_exception_if_argument_is_falsy(options): def test_set_log_level(options): - options.log.level = 'debug' - assert options.log.level == 'debug' + options.log.level = "debug" + assert options.log.level == "debug" def test_set_headless(options): options.headless = True - assert '-headless' in options._arguments + assert "-headless" in options._arguments def test_unset_headless(options): - options._arguments = ['-headless'] + options._arguments = ["-headless"] options.headless = False - assert '-headless' not in options._arguments + assert "-headless" not in options._arguments def test_get_headless(options): - options._arguments = ['-headless'] + options._arguments = ["-headless"] assert options.headless def test_creates_capabilities(options): profile = FirefoxProfile() - options._arguments = ['foo'] - options._binary = FirefoxBinary('/bar') - options._preferences = {'foo': 'bar'} - options._proxy = Proxy({'proxyType': ProxyType.MANUAL}) + options._arguments = ["foo"] + options._binary = FirefoxBinary("/bar") + options._preferences = {"foo": "bar"} + options._proxy = Proxy({"proxyType": ProxyType.MANUAL}) options._profile = profile - options.log.level = 'debug' + options.log.level = "debug" caps = options.to_capabilities() opts = caps.get(Options.KEY) assert opts - assert 'foo' in opts['args'] - assert opts['binary'] == '/bar' - assert opts['prefs']['foo'] == 'bar' - assert opts['profile'] == profile.encoded - assert caps['proxy']['proxyType'] == ProxyType.MANUAL['string'] - assert opts['log']['level'] == 'debug' + assert "foo" in opts["args"] + assert opts["binary"] == "/bar" + assert opts["prefs"]["foo"] == "bar" + assert opts["profile"] == profile.encoded + assert caps["proxy"]["proxyType"] == ProxyType.MANUAL["string"] + assert opts["log"]["level"] == "debug" def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.FIREFOX.copy() caps.update({"pageLoadStrategy": "normal"}) assert options._caps == caps @@ -171,28 +172,29 @@ def test_starts_with_default_capabilities(options): def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions) def test_raises_exception_with_invalid_page_load_strategy(options): with pytest.raises(ValueError): - options.page_load_strategy = 'never' + options.page_load_strategy = "never" def test_set_page_load_strategy(options): - options.page_load_strategy = 'normal' - assert options._caps["pageLoadStrategy"] == 'normal' + options.page_load_strategy = "normal" + assert options._caps["pageLoadStrategy"] == "normal" def test_get_page_load_strategy(options): - options._page_load_strategy = 'normal' - assert options._caps["pageLoadStrategy"] == 'normal' + options._page_load_strategy = "normal" + assert options._caps["pageLoadStrategy"] == "normal" def test_creates_capabilities_with_page_load_strategy(options): - options.page_load_strategy = 'eager' + options.page_load_strategy = "eager" caps = options.to_capabilities() - assert caps['pageLoadStrategy'] == 'eager' + assert caps["pageLoadStrategy"] == "eager" def test_enables_firefox_mobile(options): diff --git a/py/test/unit/selenium/webdriver/ie/test_ie_options.py b/py/test/unit/selenium/webdriver/ie/test_ie_options.py index 041ca6edf8b9f..71332a9b584af 100644 --- a/py/test/unit/selenium/webdriver/ie/test_ie_options.py +++ b/py/test/unit/selenium/webdriver/ie/test_ie_options.py @@ -30,8 +30,8 @@ def opts(): def test_arguments(opts): - arg1 = '-k' - arg2 = '-private' + arg1 = "-k" + arg2 = "-private" opts.add_argument(arg1) opts.add_argument(arg2) assert arg1 in opts.arguments @@ -46,7 +46,7 @@ def test_browser_attach_timeout(opts): def test_raises_exception_for_invalid_browser_attach_timeout(opts): with pytest.raises(ValueError): - opts.browser_attach_timeout = 'foo' + opts.browser_attach_timeout = "foo" def test_element_scroll_behavior(opts): @@ -69,7 +69,7 @@ def test_file_upload_dialog_timeout(opts): def test_raises_exception_for_file_upload_dialog_timeout(opts): with pytest.raises(ValueError): - opts.file_upload_dialog_timeout = 'foo' + opts.file_upload_dialog_timeout = "foo" def test_force_create_process_api(opts): @@ -103,7 +103,7 @@ def test_ignore_zoom_level(opts): def test_initial_browser_url(opts): - url = 'http://www.selenium.dev' + url = "http://www.selenium.dev" opts.initial_browser_url = url assert opts.initial_browser_url == url assert opts.options.get(Options.INITIAL_BROWSER_URL) == url @@ -146,51 +146,52 @@ def test_attach_to_edge_chrome(opts): def test_edge_executable_path(opts): - path = '/path/to/edge' + path = "/path/to/edge" opts.edge_executable_path = path assert opts.edge_executable_path == path assert opts.options.get(Options.EDGE_EXECUTABLE_PATH) == path def test_additional_options(opts): - opts.add_additional_option('foo', 'bar') - assert opts.additional_options.get('foo') == 'bar' + opts.add_additional_option("foo", "bar") + assert opts.additional_options.get("foo") == "bar" def test_to_capabilities(opts): - opts._options['foo'] = 'bar' + opts._options["foo"] = "bar" assert Options.KEY in opts.to_capabilities() assert opts.to_capabilities().get(Options.KEY) == opts._options def test_to_capabilities_arguments(opts): - arg = '-k' + arg = "-k" opts.add_argument(arg) caps_opts = opts.to_capabilities().get(Options.KEY) assert caps_opts.get(Options.SWITCHES) == arg def test_to_capabilities_additional_options(opts): - name = 'foo' - value = 'bar' + name = "foo" + value = "bar" opts.add_additional_option(name, value) caps_opts = opts.to_capabilities().get(Options.KEY) assert caps_opts.get(name) == value def test_to_capabilities_should_not_modify_set_options(opts): - opts._options['foo'] = 'bar' - arg = '-k' + opts._options["foo"] = "bar" + arg = "-k" opts.add_argument(arg) - opts.add_additional_option('baz', 'qux') + opts.add_additional_option("baz", "qux") opts.to_capabilities().get(Options.KEY) - assert opts.options.get('foo') == 'bar' + assert opts.options.get("foo") == "bar" assert opts.arguments[0] == arg - assert opts.additional_options.get('baz') == 'qux' + assert opts.additional_options.get("baz") == "qux" def test_starts_with_default_capabilities(opts): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.INTERNETEXPLORER.copy() caps.update({"pageLoadStrategy": "normal"}) assert opts._caps == caps @@ -198,4 +199,5 @@ def test_starts_with_default_capabilities(opts): def test_is_a_baseoptions(opts): from selenium.webdriver.common.options import BaseOptions + assert isinstance(opts, BaseOptions) diff --git a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py index 3700586c453f2..809d64193387a 100644 --- a/py/test/unit/selenium/webdriver/remote/error_handler_tests.py +++ b/py/test/unit/selenium/webdriver/remote/error_handler_tests.py @@ -28,242 +28,246 @@ def handler(): def test_does_not_raise_exception_on_success(handler): - assert handler.check_response({'status': ErrorCode.SUCCESS}) is None + assert handler.check_response({"status": ErrorCode.SUCCESS}) is None assert handler.check_response({}) is None -@pytest.mark.parametrize('code', ErrorCode.NO_SUCH_ELEMENT) +@pytest.mark.parametrize("code", ErrorCode.NO_SUCH_ELEMENT) def test_raises_exception_for_no_such_element(handler, code): with pytest.raises(exceptions.NoSuchElementException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.NO_SUCH_FRAME) +@pytest.mark.parametrize("code", ErrorCode.NO_SUCH_FRAME) def test_raises_exception_for_no_such_frame(handler, code): with pytest.raises(exceptions.NoSuchFrameException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNKNOWN_COMMAND) +@pytest.mark.parametrize("code", ErrorCode.UNKNOWN_COMMAND) def test_raises_exception_for_unknown_command(handler, code): with pytest.raises(exceptions.WebDriverException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.STALE_ELEMENT_REFERENCE) +@pytest.mark.parametrize("code", ErrorCode.STALE_ELEMENT_REFERENCE) def test_raises_exception_for_stale_element_reference(handler, code): with pytest.raises(exceptions.StaleElementReferenceException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.ELEMENT_NOT_VISIBLE) +@pytest.mark.parametrize("code", ErrorCode.ELEMENT_NOT_VISIBLE) def test_raises_exception_for_element_not_visible(handler, code): with pytest.raises(exceptions.ElementNotVisibleException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_ELEMENT_STATE) +@pytest.mark.parametrize("code", ErrorCode.INVALID_ELEMENT_STATE) def test_raises_exception_for_invalid_element_state(handler, code): with pytest.raises(exceptions.InvalidElementStateException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNKNOWN_ERROR) +@pytest.mark.parametrize("code", ErrorCode.UNKNOWN_ERROR) def test_raises_exception_for_unknown_error(handler, code): with pytest.raises(exceptions.WebDriverException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.ELEMENT_IS_NOT_SELECTABLE) +@pytest.mark.parametrize("code", ErrorCode.ELEMENT_IS_NOT_SELECTABLE) def test_raises_exception_for_element_not_selectable(handler, code): with pytest.raises(exceptions.ElementNotSelectableException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.JAVASCRIPT_ERROR) +@pytest.mark.parametrize("code", ErrorCode.JAVASCRIPT_ERROR) def test_raises_exception_for_javascript_error(handler, code): with pytest.raises(exceptions.JavascriptException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.XPATH_LOOKUP_ERROR) +@pytest.mark.parametrize("code", ErrorCode.XPATH_LOOKUP_ERROR) def test_raises_exception_for_xpath_lookup_error(handler, code): with pytest.raises(exceptions.WebDriverException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.TIMEOUT) +@pytest.mark.parametrize("code", ErrorCode.TIMEOUT) def test_raises_exception_for_timeout(handler, code): with pytest.raises(exceptions.TimeoutException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.NO_SUCH_WINDOW) +@pytest.mark.parametrize("code", ErrorCode.NO_SUCH_WINDOW) def test_raises_exception_for_no_such_window(handler, code): with pytest.raises(exceptions.NoSuchWindowException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_COOKIE_DOMAIN) +@pytest.mark.parametrize("code", ErrorCode.INVALID_COOKIE_DOMAIN) def test_raises_exception_for_invalid_cookie_domain(handler, code): with pytest.raises(exceptions.InvalidCookieDomainException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNABLE_TO_SET_COOKIE) +@pytest.mark.parametrize("code", ErrorCode.UNABLE_TO_SET_COOKIE) def test_raises_exception_for_unable_to_set_cookie(handler, code): with pytest.raises(exceptions.UnableToSetCookieException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNEXPECTED_ALERT_OPEN) +@pytest.mark.parametrize("code", ErrorCode.UNEXPECTED_ALERT_OPEN) def test_raises_exception_for_unexpected_alert_open(handler, code): with pytest.raises(exceptions.UnexpectedAlertPresentException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.NO_ALERT_OPEN) +@pytest.mark.parametrize("code", ErrorCode.NO_ALERT_OPEN) def test_raises_exception_for_no_alert_open(handler, code): with pytest.raises(exceptions.NoAlertPresentException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.SCRIPT_TIMEOUT) +@pytest.mark.parametrize("code", ErrorCode.SCRIPT_TIMEOUT) def test_raises_exception_for_script_timeout(handler, code): with pytest.raises(exceptions.TimeoutException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_ELEMENT_COORDINATES) +@pytest.mark.parametrize("code", ErrorCode.INVALID_ELEMENT_COORDINATES) def test_raises_exception_for_invalid_element_coordinates(handler, code): with pytest.raises(exceptions.WebDriverException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.IME_NOT_AVAILABLE) +@pytest.mark.parametrize("code", ErrorCode.IME_NOT_AVAILABLE) def test_raises_exception_for_ime_not_available(handler, code): with pytest.raises(exceptions.ImeNotAvailableException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.IME_ENGINE_ACTIVATION_FAILED) +@pytest.mark.parametrize("code", ErrorCode.IME_ENGINE_ACTIVATION_FAILED) def test_raises_exception_for_ime_activation_failed(handler, code): with pytest.raises(exceptions.ImeActivationFailedException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_SELECTOR) +@pytest.mark.parametrize("code", ErrorCode.INVALID_SELECTOR) def test_raises_exception_for_invalid_selector(handler, code): with pytest.raises(exceptions.InvalidSelectorException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.SESSION_NOT_CREATED) +@pytest.mark.parametrize("code", ErrorCode.SESSION_NOT_CREATED) def test_raises_exception_for_session_not_created(handler, code): with pytest.raises(exceptions.SessionNotCreatedException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS) +@pytest.mark.parametrize("code", ErrorCode.MOVE_TARGET_OUT_OF_BOUNDS) def test_raises_exception_for_move_target_out_of_bounds(handler, code): with pytest.raises(exceptions.MoveTargetOutOfBoundsException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_XPATH_SELECTOR) +@pytest.mark.parametrize("code", ErrorCode.INVALID_XPATH_SELECTOR) def test_raises_exception_for_invalid_xpath_selector(handler, code): with pytest.raises(exceptions.InvalidSelectorException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER) +@pytest.mark.parametrize("code", ErrorCode.INVALID_XPATH_SELECTOR_RETURN_TYPER) def test_raises_exception_for_invalid_xpath_selector_return_typer(handler, code): with pytest.raises(exceptions.InvalidSelectorException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.ELEMENT_NOT_INTERACTABLE) +@pytest.mark.parametrize("code", ErrorCode.ELEMENT_NOT_INTERACTABLE) def test_raises_exception_for_element_not_interactable(handler, code): with pytest.raises(exceptions.ElementNotInteractableException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INSECURE_CERTIFICATE) +@pytest.mark.parametrize("code", ErrorCode.INSECURE_CERTIFICATE) def test_raises_exception_for_insecure_certificate(handler, code): with pytest.raises(exceptions.InsecureCertificateException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_ARGUMENT) +@pytest.mark.parametrize("code", ErrorCode.INVALID_ARGUMENT) def test_raises_exception_for_invalid_argument(handler, code): with pytest.raises(exceptions.InvalidArgumentException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_COORDINATES) +@pytest.mark.parametrize("code", ErrorCode.INVALID_COORDINATES) def test_raises_exception_for_invalid_coordinates(handler, code): with pytest.raises(exceptions.InvalidCoordinatesException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.INVALID_SESSION_ID) +@pytest.mark.parametrize("code", ErrorCode.INVALID_SESSION_ID) def test_raises_exception_for_invalid_session_id(handler, code): with pytest.raises(exceptions.InvalidSessionIdException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.NO_SUCH_COOKIE) +@pytest.mark.parametrize("code", ErrorCode.NO_SUCH_COOKIE) def test_raises_exception_for_no_such_cookie(handler, code): with pytest.raises(exceptions.NoSuchCookieException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNABLE_TO_CAPTURE_SCREEN) +@pytest.mark.parametrize("code", ErrorCode.UNABLE_TO_CAPTURE_SCREEN) def test_raises_exception_for_unable_to_capture_screen_exception(handler, code): with pytest.raises(exceptions.ScreenshotException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.ELEMENT_CLICK_INTERCEPTED) +@pytest.mark.parametrize("code", ErrorCode.ELEMENT_CLICK_INTERCEPTED) def test_raises_exception_for_element_click_intercepted(handler, code): with pytest.raises(exceptions.ElementClickInterceptedException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.UNKNOWN_METHOD) +@pytest.mark.parametrize("code", ErrorCode.UNKNOWN_METHOD) def test_raises_exception_for_unknown_method(handler, code): with pytest.raises(exceptions.UnknownMethodException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('code', ErrorCode.METHOD_NOT_ALLOWED) +@pytest.mark.parametrize("code", ErrorCode.METHOD_NOT_ALLOWED) def test_raises_exception_for_method_not_allowed(handler, code): with pytest.raises(exceptions.WebDriverException): - handler.check_response({'status': code, 'value': 'foo'}) + handler.check_response({"status": code, "value": "foo"}) -@pytest.mark.parametrize('key', ['stackTrace', 'stacktrace']) +@pytest.mark.parametrize("key", ["stackTrace", "stacktrace"]) def test_relays_exception_stacktrace(handler, key): import json - stacktrace = {'lineNumber': 100, 'fileName': 'egg', 'methodName': 'ham', 'className': 'Spam'} - value = {key: [stacktrace], - 'message': 'very bad', - 'error': ErrorCode.UNKNOWN_METHOD[0]} - response = {'status': 400, 'value': json.dumps({'value': value})} + + stacktrace = {"lineNumber": 100, "fileName": "egg", "methodName": "ham", "className": "Spam"} + value = {key: [stacktrace], "message": "very bad", "error": ErrorCode.UNKNOWN_METHOD[0]} + response = {"status": 400, "value": json.dumps({"value": value})} with pytest.raises(exceptions.UnknownMethodException) as e: handler.check_response(response) - assert 'Spam.ham' in e.value.stacktrace[0] + assert "Spam.ham" in e.value.stacktrace[0] def test_handle_errors_better(handler): import json - response = {"status": 500, - "value": json.dumps({"value": { + + response = { + "status": 500, + "value": json.dumps( + { + "value": { "message": "Could not start a new session. No Node supports the required capabilities: Capabilities {browserName: chrome, goog:chromeOptions: {args: [headless, silent], extensions: [], w3c: false}}, Capabilities {browserName: chrome, goog:chromeOptions: {args: [headless, silent], extensions: [], w3c: false}, version: }\nBuild info: version: '4.0.0-beta-3', revision: '5d108f9a67'\nSystem info: host: '9315f0a993d2', ip: '172.17.0.8', os.name: 'Linux', os.arch: 'amd64', os.version: '5.8.0-44-generic', java.version: '1.8.0_282'\nDriver info: driver.version: unknown" } - }) - } + } + ), + } with pytest.raises(exceptions.WebDriverException) as e: handler.check_response(response) diff --git a/py/test/unit/selenium/webdriver/remote/new_session_tests.py b/py/test/unit/selenium/webdriver/remote/new_session_tests.py index ca372a5ce18bd..8e5aac88290a2 100644 --- a/py/test/unit/selenium/webdriver/remote/new_session_tests.py +++ b/py/test/unit/selenium/webdriver/remote/new_session_tests.py @@ -28,37 +28,42 @@ def test_converts_oss_capabilities_to_w3c(mocker): - mock = mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.execute') - oss_caps = {'platform': 'WINDOWS', 'version': '11', 'acceptSslCerts': True} - w3c_caps = {'platformName': 'windows', 'browserVersion': '11', 'acceptInsecureCerts': True} + mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.execute") + oss_caps = {"platform": "WINDOWS", "version": "11", "acceptSslCerts": True} + w3c_caps = {"platformName": "windows", "browserVersion": "11", "acceptInsecureCerts": True} WebDriver(desired_capabilities=deepcopy(oss_caps)) - expected_params = {'capabilities': {'firstMatch': [{}], 'alwaysMatch': w3c_caps}} + expected_params = {"capabilities": {"firstMatch": [{}], "alwaysMatch": w3c_caps}} mock.assert_called_with(Command.NEW_SESSION, expected_params) -@pytest.mark.parametrize("oss_name, val, w3c_name", ( - ('acceptSslCerts', True, 'acceptInsecureCerts'), - ("version", '11', "browserVersion"), - ("platform", 'windows', 'platformName'))) +@pytest.mark.parametrize( + "oss_name, val, w3c_name", + ( + ("acceptSslCerts", True, "acceptInsecureCerts"), + ("version", "11", "browserVersion"), + ("platform", "windows", "platformName"), + ), +) def test_non_compliant_w3c_caps_is_deprecated(oss_name, val, w3c_name): from selenium.webdriver.remote.webdriver import _make_w3c_caps + msg = f"{oss_name} is not a w3c capability. use `{w3c_name}` instead. This will no longer be converted in 4.7.0" with pytest.warns(DeprecationWarning, match=msg): _ = _make_w3c_caps({oss_name: val}) def test_converts_proxy_type_value_to_lowercase_for_w3c(mocker): - mock = mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.execute') - oss_caps = {'proxy': {'proxyType': 'MANUAL', 'httpProxy': 'foo'}} - w3c_caps = {'proxy': {'proxyType': 'manual', 'httpProxy': 'foo'}} + mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.execute") + oss_caps = {"proxy": {"proxyType": "MANUAL", "httpProxy": "foo"}} + w3c_caps = {"proxy": {"proxyType": "manual", "httpProxy": "foo"}} WebDriver(desired_capabilities=deepcopy(oss_caps)) - expected_params = {'capabilities': {'firstMatch': [{}], 'alwaysMatch': w3c_caps}} + expected_params = {"capabilities": {"firstMatch": [{}], "alwaysMatch": w3c_caps}} mock.assert_called_with(Command.NEW_SESSION, expected_params) def test_works_as_context_manager(mocker): - mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.execute') - quit_ = mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.quit') + mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.execute") + quit_ = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.quit") with WebDriver() as driver: assert isinstance(driver, WebDriver) @@ -66,14 +71,14 @@ def test_works_as_context_manager(mocker): assert quit_.call_count == 1 -@pytest.mark.parametrize('browser_name', ['firefox', 'chrome', 'ie']) +@pytest.mark.parametrize("browser_name", ["firefox", "chrome", "ie"]) def test_accepts_firefox_options_to_remote_driver(mocker, browser_name): - options = import_module(f'selenium.webdriver.{browser_name}.options') - caps_name = browser_name.upper() if browser_name != 'ie' else 'INTERNETEXPLORER' - mock = mocker.patch('selenium.webdriver.remote.webdriver.WebDriver.start_session') + options = import_module(f"selenium.webdriver.{browser_name}.options") + caps_name = browser_name.upper() if browser_name != "ie" else "INTERNETEXPLORER" + mock = mocker.patch("selenium.webdriver.remote.webdriver.WebDriver.start_session") opts = options.Options() - opts.add_argument('foo') + opts.add_argument("foo") expected_caps = getattr(DesiredCapabilities, caps_name) caps = expected_caps.copy() expected_caps.update(opts.to_capabilities()) @@ -100,7 +105,7 @@ def test_always_match_if_2_of_the_same_options(): "firstMatch": [ {"goog:chromeOptions": {"args": ["foo"], "extensions": []}}, {"goog:chromeOptions": {"args": ["bar"], "extensions": []}}, - ] + ], } } result = webdriver.create_matches([co1, co2]) @@ -115,14 +120,14 @@ def test_first_match_when_2_different_option_types(): "capabilities": { "alwaysMatch": {"pageLoadStrategy": "normal"}, "firstMatch": [ - {"browserName": "chrome", - "goog:chromeOptions": {"extensions": [], "args": []}}, - {"browserName": "firefox", - "acceptInsecureCerts": True, - "moz:debuggerAddress": True, - "moz:firefoxOptions": {"args": ["foo"]} - } - ] + {"browserName": "chrome", "goog:chromeOptions": {"extensions": [], "args": []}}, + { + "browserName": "firefox", + "acceptInsecureCerts": True, + "moz:debuggerAddress": True, + "moz:firefoxOptions": {"args": ["foo"]}, + }, + ], } } diff --git a/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py b/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py index aaddc396eb933..ca4ccde5acec7 100644 --- a/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py +++ b/py/test/unit/selenium/webdriver/remote/remote_connection_tests.py @@ -25,50 +25,50 @@ def test_get_remote_connection_headers_defaults(): - url = 'http://remote' + url = "http://remote" headers = RemoteConnection.get_remote_connection_headers(parse.urlparse(url)) - assert 'Authorization' not in headers.keys() - assert 'Connection' not in headers.keys() - assert headers.get('Accept') == 'application/json' - assert headers.get('Content-Type') == 'application/json;charset=UTF-8' - assert headers.get('User-Agent').startswith("selenium/%s (python " % __version__) - assert headers.get('User-Agent').split(' ')[-1] in {'windows)', 'mac)', 'linux)'} + assert "Authorization" not in headers.keys() + assert "Connection" not in headers.keys() + assert headers.get("Accept") == "application/json" + assert headers.get("Content-Type") == "application/json;charset=UTF-8" + assert headers.get("User-Agent").startswith("selenium/%s (python " % __version__) + assert headers.get("User-Agent").split(" ")[-1] in {"windows)", "mac)", "linux)"} def test_get_remote_connection_headers_adds_auth_header_if_pass(): - url = 'http://user:pass@remote' + url = "http://user:pass@remote" headers = RemoteConnection.get_remote_connection_headers(parse.urlparse(url)) - assert headers.get('Authorization') == 'Basic dXNlcjpwYXNz' + assert headers.get("Authorization") == "Basic dXNlcjpwYXNz" def test_get_remote_connection_headers_adds_keep_alive_if_requested(): - url = 'http://remote' + url = "http://remote" headers = RemoteConnection.get_remote_connection_headers(parse.urlparse(url), keep_alive=True) - assert headers.get('Connection') == 'keep-alive' + assert headers.get("Connection") == "keep-alive" def test_get_proxy_url_http(mock_proxy_settings): - proxy = 'http://http_proxy.com:8080' - remote_connection = RemoteConnection('http://remote', keep_alive=False) + proxy = "http://http_proxy.com:8080" + remote_connection = RemoteConnection("http://remote", keep_alive=False) proxy_url = remote_connection._get_proxy_url() assert proxy_url == proxy def test_get_proxy_url_https(mock_proxy_settings): - proxy = 'http://https_proxy.com:8080' - remote_connection = RemoteConnection('https://remote', keep_alive=False) + proxy = "http://https_proxy.com:8080" + remote_connection = RemoteConnection("https://remote", keep_alive=False) proxy_url = remote_connection._get_proxy_url() assert proxy_url == proxy def test_get_proxy_url_none(mock_proxy_settings_missing): - remote_connection = RemoteConnection('https://remote', keep_alive=False) + remote_connection = RemoteConnection("https://remote", keep_alive=False) proxy_url = remote_connection._get_proxy_url() assert proxy_url is None def test_get_proxy_url_http_auth(mock_proxy_auth_settings): - remote_connection = RemoteConnection('http://remote', keep_alive=False) + remote_connection = RemoteConnection("http://remote", keep_alive=False) proxy_url = remote_connection._get_proxy_url() raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth() assert proxy_url == "http://user:password@http_proxy.com:8080" @@ -77,7 +77,7 @@ def test_get_proxy_url_http_auth(mock_proxy_auth_settings): def test_get_proxy_url_https_auth(mock_proxy_auth_settings): - remote_connection = RemoteConnection('https://remote', keep_alive=False) + remote_connection = RemoteConnection("https://remote", keep_alive=False) proxy_url = remote_connection._get_proxy_url() raw_proxy_url, basic_auth_string = remote_connection._separate_http_proxy_auth() assert proxy_url == "https://user:password@https_proxy.com:8080" @@ -86,65 +86,77 @@ def test_get_proxy_url_https_auth(mock_proxy_auth_settings): def test_get_connection_manager_without_proxy(mock_proxy_settings_missing): - remote_connection = RemoteConnection('http://remote', keep_alive=False) + remote_connection = RemoteConnection("http://remote", keep_alive=False) conn = remote_connection._get_connection_manager() assert type(conn) == urllib3.PoolManager def test_get_connection_manager_for_certs_and_timeout(monkeypatch): monkeypatch.setattr(RemoteConnection, "get_timeout", lambda _: 10) # Class state; leaks into subsequent tests. - remote_connection = RemoteConnection('http://remote', keep_alive=False) + remote_connection = RemoteConnection("http://remote", keep_alive=False) conn = remote_connection._get_connection_manager() - assert conn.connection_pool_kw['timeout'] == 10 - assert conn.connection_pool_kw['cert_reqs'] == 'CERT_REQUIRED' - assert 'certifi/cacert.pem' in conn.connection_pool_kw['ca_certs'] + assert conn.connection_pool_kw["timeout"] == 10 + assert conn.connection_pool_kw["cert_reqs"] == "CERT_REQUIRED" + assert "certifi/cacert.pem" in conn.connection_pool_kw["ca_certs"] def test_default_socket_timeout_is_correct(): remote_connection = RemoteConnection("http://remote", keep_alive=True) conn = remote_connection._get_connection_manager() - assert conn.connection_pool_kw['timeout'] is None + assert conn.connection_pool_kw["timeout"] is None def test_get_connection_manager_with_proxy(mock_proxy_settings): - remote_connection = RemoteConnection('http://remote', keep_alive=False) + remote_connection = RemoteConnection("http://remote", keep_alive=False) conn = remote_connection._get_connection_manager() assert type(conn) == urllib3.ProxyManager - assert conn.proxy.scheme == 'http' - assert conn.proxy.host == 'http_proxy.com' + assert conn.proxy.scheme == "http" + assert conn.proxy.host == "http_proxy.com" assert conn.proxy.port == 8080 - remote_connection_https = RemoteConnection('https://remote', keep_alive=False) + remote_connection_https = RemoteConnection("https://remote", keep_alive=False) conn = remote_connection_https._get_connection_manager() assert type(conn) == urllib3.ProxyManager - assert conn.proxy.scheme == 'http' - assert conn.proxy.host == 'https_proxy.com' + assert conn.proxy.scheme == "http" + assert conn.proxy.host == "https_proxy.com" assert conn.proxy.port == 8080 def test_get_connection_manager_with_auth_proxy(mock_proxy_auth_settings): - proxy_auth_header = urllib3.make_headers( - proxy_basic_auth="user:password" - ) - remote_connection = RemoteConnection('http://remote', keep_alive=False) + proxy_auth_header = urllib3.make_headers(proxy_basic_auth="user:password") + remote_connection = RemoteConnection("http://remote", keep_alive=False) conn = remote_connection._get_connection_manager() assert type(conn) == urllib3.ProxyManager - assert conn.proxy.scheme == 'http' - assert conn.proxy.host == 'http_proxy.com' + assert conn.proxy.scheme == "http" + assert conn.proxy.host == "http_proxy.com" assert conn.proxy.port == 8080 assert conn.proxy_headers == proxy_auth_header - remote_connection_https = RemoteConnection('https://remote', keep_alive=False) + remote_connection_https = RemoteConnection("https://remote", keep_alive=False) conn = remote_connection_https._get_connection_manager() assert type(conn) == urllib3.ProxyManager - assert conn.proxy.scheme == 'https' - assert conn.proxy.host == 'https_proxy.com' + assert conn.proxy.scheme == "https" + assert conn.proxy.host == "https_proxy.com" assert conn.proxy.port == 8080 assert conn.proxy_headers == proxy_auth_header -@pytest.mark.parametrize("url", - ["*", ".localhost", "localhost:80", "locahost", "127.0.0.1", - "LOCALHOST", "LOCALHOST:80", "http://localhost", "https://localhost", - "test.localhost", " localhost", "::1", "127.0.0.2"]) +@pytest.mark.parametrize( + "url", + [ + "*", + ".localhost", + "localhost:80", + "locahost", + "127.0.0.1", + "LOCALHOST", + "LOCALHOST:80", + "http://localhost", + "https://localhost", + "test.localhost", + " localhost", + "::1", + "127.0.0.2", + ], +) def test_get_connection_manager_when_no_proxy_set(mock_no_proxy_settings, url): remote_connection = RemoteConnection(url) conn = remote_connection._get_connection_manager() @@ -161,6 +173,7 @@ def test_get_socks_proxy_when_set(mock_socks_proxy_settings): remote_connection = RemoteConnection("http://127.0.0.1:4444/wd/hub") conn = remote_connection._get_connection_manager() from urllib3.contrib.socks import SOCKSProxyManager + assert type(conn) == SOCKSProxyManager @@ -188,8 +201,8 @@ def mock_proxy_settings_missing(monkeypatch): @pytest.fixture(scope="function") def mock_socks_proxy_settings(monkeypatch): - http_proxy = 'SOCKS5://http_proxy.com:8080' - https_proxy = 'SOCKS5://https_proxy.com:8080' + http_proxy = "SOCKS5://http_proxy.com:8080" + https_proxy = "SOCKS5://https_proxy.com:8080" monkeypatch.setenv("HTTPS_PROXY", https_proxy) monkeypatch.setenv("HTTP_PROXY", http_proxy) monkeypatch.setenv("https_proxy", https_proxy) @@ -198,8 +211,8 @@ def mock_socks_proxy_settings(monkeypatch): @pytest.fixture(scope="function") def mock_proxy_settings(monkeypatch): - http_proxy = 'http://http_proxy.com:8080' - https_proxy = 'http://https_proxy.com:8080' + http_proxy = "http://http_proxy.com:8080" + https_proxy = "http://https_proxy.com:8080" monkeypatch.setenv("HTTPS_PROXY", https_proxy) monkeypatch.setenv("HTTP_PROXY", http_proxy) monkeypatch.setenv("https_proxy", https_proxy) @@ -208,8 +221,8 @@ def mock_proxy_settings(monkeypatch): @pytest.fixture(scope="function") def mock_proxy_auth_settings(monkeypatch): - http_proxy = 'http://user:password@http_proxy.com:8080' - https_proxy = 'https://user:password@https_proxy.com:8080' + http_proxy = "http://user:password@http_proxy.com:8080" + https_proxy = "https://user:password@https_proxy.com:8080" monkeypatch.setenv("HTTPS_PROXY", https_proxy) monkeypatch.setenv("HTTP_PROXY", http_proxy) monkeypatch.setenv("https_proxy", https_proxy) @@ -218,8 +231,8 @@ def mock_proxy_auth_settings(monkeypatch): @pytest.fixture(scope="function") def mock_no_proxy_settings(monkeypatch): - http_proxy = 'http://http_proxy.com:8080' - https_proxy = 'http://https_proxy.com:8080' + http_proxy = "http://http_proxy.com:8080" + https_proxy = "http://https_proxy.com:8080" monkeypatch.setenv("HTTPS_PROXY", https_proxy) monkeypatch.setenv("HTTP_PROXY", http_proxy) monkeypatch.setenv("https_proxy", https_proxy) diff --git a/py/test/unit/selenium/webdriver/remote/subtyping_tests.py b/py/test/unit/selenium/webdriver/remote/subtyping_tests.py index 90310dfc12856..1162ec7031c3d 100644 --- a/py/test/unit/selenium/webdriver/remote/subtyping_tests.py +++ b/py/test/unit/selenium/webdriver/remote/subtyping_tests.py @@ -22,6 +22,7 @@ def test_web_element_not_subclassed(): """A registered subtype of WebElement should work with isinstance checks.""" + class MyWebElement: def __init__(self, parent, id, _w3c=True): self.parent = parent @@ -29,18 +30,19 @@ def __init__(self, parent, id, _w3c=True): self._w3c = _w3c # Test that non registered class instance is not instance of Remote WebElement - my_web_element = MyWebElement('parent', '1') + my_web_element = MyWebElement("parent", "1") assert not isinstance(my_web_element, WebElement) # Register the class as a subtype of WebElement WebElement.register(MyWebElement) - my_registered_web_element = MyWebElement('parent', '2') + my_registered_web_element = MyWebElement("parent", "2") assert isinstance(my_registered_web_element, WebElement) def test_webdriver_not_subclassed(): """A registered subtype of WebDriver should work with isinstance checks.""" + class MyWebDriver: def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/py/test/unit/selenium/webdriver/safari/safari_options_tests.py b/py/test/unit/selenium/webdriver/safari/safari_options_tests.py index 19bb5767e7f10..97ba58b8ffdf8 100644 --- a/py/test/unit/selenium/webdriver/safari/safari_options_tests.py +++ b/py/test/unit/selenium/webdriver/safari/safari_options_tests.py @@ -26,27 +26,28 @@ def options(): def test_set_binary_location(options): - options.binary_location = '/foo/bar' - assert options._binary_location == '/foo/bar' + options.binary_location = "/foo/bar" + assert options._binary_location == "/foo/bar" def test_get_binary_location(options): - options._binary_location = '/foo/bar' - assert options.binary_location == '/foo/bar' + options._binary_location = "/foo/bar" + assert options.binary_location == "/foo/bar" def test_creates_capabilities(options): - options._arguments = ['foo'] - options._binary_location = '/bar' + options._arguments = ["foo"] + options._binary_location = "/bar" caps = options.to_capabilities() opts = caps.get(Options.KEY) assert opts - assert 'foo' in opts['args'] - assert opts['binary'] == '/bar' + assert "foo" in opts["args"] + assert opts["binary"] == "/bar" def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.SAFARI.copy() caps.update({"pageLoadStrategy": "normal"}) assert options._caps == caps @@ -54,6 +55,7 @@ def test_starts_with_default_capabilities(options): def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions) @@ -71,7 +73,8 @@ def test_can_set_automatic_profiling(options): def test_setting_technology_preview_changes_browser_name(options): from selenium.webdriver import DesiredCapabilities - BROWSER_NAME = 'browserName' + + BROWSER_NAME = "browserName" assert options._caps.get(BROWSER_NAME) == DesiredCapabilities.SAFARI[BROWSER_NAME] options.use_technology_preview = True diff --git a/py/test/unit/selenium/webdriver/support/color_tests.py b/py/test/unit/selenium/webdriver/support/color_tests.py index 6c8ba93e260f9..24bbf3b8ab76d 100644 --- a/py/test/unit/selenium/webdriver/support/color_tests.py +++ b/py/test/unit/selenium/webdriver/support/color_tests.py @@ -21,6 +21,7 @@ def test_color_can_be_subclassed(): class MyColor(Color): ... + assert type(MyColor.from_string("rgb(1, 2, 3)")) == MyColor diff --git a/py/test/unit/selenium/webdriver/virtual_authenticator/credentials_test.py b/py/test/unit/selenium/webdriver/virtual_authenticator/credentials_test.py index fb629a6313639..6bc82bc11df04 100644 --- a/py/test/unit/selenium/webdriver/virtual_authenticator/credentials_test.py +++ b/py/test/unit/selenium/webdriver/virtual_authenticator/credentials_test.py @@ -23,7 +23,7 @@ from selenium.webdriver.common.virtual_authenticator import Credential -BASE64__ENCODED_PK = ''' +BASE64__ENCODED_PK = """ MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbBOu5Lhs4vpowbCnmCyLUpIE7JM9sm9QXzye2G+jr+Kr MsinWohEce47BFPJlTaDzHSvOW2eeunBO89ZcvvVc8RLz4qyQ8rO98xS1jtgqi1NcBPETDrtzthODu/gd0sjB2Tk3TLuBGV oPXt54a+Oo4JbBJ6h3s0+5eAfGplCbSNq6hN3Jh9YOTw5ZA6GCEy5l8zBaOgjXytd2v2OdSVoEDNiNQRkjJd2rmS2oi9AyQ @@ -42,7 +42,7 @@ 9QulbC3C/qgGFNrcWgcT9kCgYAZTa1P9bFCDU7hJc2mHwJwAW7/FQKEJg8SL33KINpLwcR8fqaYOdAHWWz636osVEqosRrH zJOGpf9x2RSWzQJ+dq8+6fACgfFZOVpN644+sAHfNPAI/gnNKU5OfUv+eav8fBnzlf1A3y3GIkyMyzFN3DE7e0n/lyqxE4H BYGpI8g== -''' +""" @pytest.fixture() diff --git a/py/test/unit/selenium/webdriver/virtual_authenticator/virtual_authenticator_options_tests.py b/py/test/unit/selenium/webdriver/virtual_authenticator/virtual_authenticator_options_tests.py index 56ce050915d42..2f4d04c2d818a 100644 --- a/py/test/unit/selenium/webdriver/virtual_authenticator/virtual_authenticator_options_tests.py +++ b/py/test/unit/selenium/webdriver/virtual_authenticator/virtual_authenticator_options_tests.py @@ -87,9 +87,9 @@ def test_get_is_user_verified(options): def test_to_dict_with_defaults(options): default_options = options.to_dict() - assert default_options['transport'] == VirtualAuthenticatorOptions.Transport.USB.value - assert default_options['protocol'] == VirtualAuthenticatorOptions.Protocol.CTAP2.value - assert default_options['hasResidentKey'] is False - assert default_options['hasUserVerification'] is False - assert default_options['isUserConsenting'] is True - assert default_options['isUserVerified'] is False + assert default_options["transport"] == VirtualAuthenticatorOptions.Transport.USB.value + assert default_options["protocol"] == VirtualAuthenticatorOptions.Protocol.CTAP2.value + assert default_options["hasResidentKey"] is False + assert default_options["hasUserVerification"] is False + assert default_options["isUserConsenting"] is True + assert default_options["isUserVerified"] is False diff --git a/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py b/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py index 63aee42ba5f1c..9638c5d4f34e3 100644 --- a/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py +++ b/py/test/unit/selenium/webdriver/webkitgtk/webkitgtk_options_tests.py @@ -26,13 +26,13 @@ def options(): def test_set_binary_location(options): - options.binary_location = '/foo/bar' - assert options._binary_location == '/foo/bar' + options.binary_location = "/foo/bar" + assert options._binary_location == "/foo/bar" def test_get_binary_location(options): - options._binary_location = '/foo/bar' - assert options.binary_location == '/foo/bar' + options._binary_location = "/foo/bar" + assert options.binary_location == "/foo/bar" def test_set_overlay_scrollbars_enabled(options): @@ -46,19 +46,20 @@ def test_get_overlay_scrollbars_enabled(options): def test_creates_capabilities(options): - options._arguments = ['foo'] - options._binary_location = '/bar' + options._arguments = ["foo"] + options._binary_location = "/bar" options._overlay_scrollbars_enabled = True caps = options.to_capabilities() opts = caps.get(Options.KEY) assert opts - assert 'foo' in opts['args'] - assert opts['binary'] == '/bar' - assert opts['useOverlayScrollbars'] is True + assert "foo" in opts["args"] + assert opts["binary"] == "/bar" + assert opts["useOverlayScrollbars"] is True def test_starts_with_default_capabilities(options): from selenium.webdriver import DesiredCapabilities + caps = DesiredCapabilities.WEBKITGTK.copy() caps.update({"pageLoadStrategy": "normal"}) assert options._caps == caps @@ -66,4 +67,5 @@ def test_starts_with_default_capabilities(options): def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions) diff --git a/py/test/unit/selenium/webdriver/wpewebkit/wpewebkit_options_tests.py b/py/test/unit/selenium/webdriver/wpewebkit/wpewebkit_options_tests.py index 5f26f5240559e..b43e01b8a3b5e 100644 --- a/py/test/unit/selenium/webdriver/wpewebkit/wpewebkit_options_tests.py +++ b/py/test/unit/selenium/webdriver/wpewebkit/wpewebkit_options_tests.py @@ -26,25 +26,26 @@ def options(): def test_set_binary_location(options): - options.binary_location = '/foo/bar' - assert options._binary_location == '/foo/bar' + options.binary_location = "/foo/bar" + assert options._binary_location == "/foo/bar" def test_get_binary_location(options): - options._binary_location = '/foo/bar' - assert options.binary_location == '/foo/bar' + options._binary_location = "/foo/bar" + assert options.binary_location == "/foo/bar" def test_creates_capabilities(options): - options._arguments = ['foo'] - options._binary_location = '/bar' + options._arguments = ["foo"] + options._binary_location = "/bar" caps = options.to_capabilities() opts = caps.get(Options.KEY) assert opts - assert 'foo' in opts['args'] - assert opts['binary'] == '/bar' + assert "foo" in opts["args"] + assert opts["binary"] == "/bar" def test_is_a_baseoptions(options): from selenium.webdriver.common.options import BaseOptions + assert isinstance(options, BaseOptions)