Skip to content

Commit

Permalink
[py]: format python tests with black
Browse files Browse the repository at this point in the history
  • Loading branch information
symonk committed Oct 1, 2022
1 parent c686e68 commit b5b495d
Show file tree
Hide file tree
Showing 70 changed files with 1,099 additions and 1,005 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 2 additions & 2 deletions py/test/selenium/webdriver/chrome/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions py/test/selenium/webdriver/chrome/options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
14 changes: 7 additions & 7 deletions py/test/selenium/webdriver/chrome/proxy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
37 changes: 17 additions & 20 deletions py/test/selenium/webdriver/common/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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")
Expand All @@ -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")
Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down
33 changes: 17 additions & 16 deletions py/test/selenium/webdriver/common/api_example_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand All @@ -177,15 +177,15 @@ 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")
assert "4" == attr


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")
Expand All @@ -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


Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions py/test/selenium/webdriver/common/bidi_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"

Expand All @@ -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"] == ""
Expand Down
6 changes: 2 additions & 4 deletions py/test/selenium/webdriver/common/click_scrolling_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions py/test/selenium/webdriver/common/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit b5b495d

Please sign in to comment.