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 = """
top - """.format(page_number=path[5:]) - html = html.encode('utf-8') +