Skip to content

Commit

Permalink
[py] Fixing flake8 issues
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Mar 22, 2020
1 parent 24e9a3a commit bb3a800
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
1 change: 0 additions & 1 deletion py/selenium/webdriver/chromium/remote_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.

from selenium.webdriver.remote.remote_connection import RemoteConnection
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


class ChromiumRemoteConnection(RemoteConnection):
Expand Down
6 changes: 3 additions & 3 deletions py/selenium/webdriver/remote/webdriver.py
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,10 @@ def add_cookie(self, cookie_dict):
"""
if 'sameSite' in cookie_dict:
assert cookie_dict['sameSite'] in ['Strict', 'Lax']
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
assert cookie_dict['sameSite'] in ['Strict', 'Lax']
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
else:
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})
self.execute(Command.ADD_COOKIE, {'cookie': cookie_dict})

# Timeouts
def implicitly_wait(self, time_to_wait):
Expand Down
20 changes: 14 additions & 6 deletions py/test/selenium/webdriver/common/cookie_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from selenium.common.exceptions import WebDriverException


@pytest.fixture
def cookie(webserver):
cookie = {
Expand All @@ -33,6 +34,7 @@ def cookie(webserver):
'secure': False}
return cookie


@pytest.fixture
def same_site_cookie_strict(webserver):
same_site_cookie_strict = {
Expand All @@ -44,42 +46,48 @@ def same_site_cookie_strict(webserver):
'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(autouse=True)
def pages(request, driver, pages):
pages.load('simpleTest.html')
yield pages
driver.delete_all_cookies()


def testAddCookie(cookie, driver):
driver.add_cookie(cookie)
returned = driver.execute_script('return document.cookie')
assert cookie['name'] in returned


@pytest.mark.xfail_firefox(raises=WebDriverException,
reason='sameSite cookie attribute not implemented')
def testAddCookieSameSiteStrict(same_site_cookie_strict, driver):
driver.add_cookie(same_site_cookie_strict)
returned = driver.get_cookie('foo')
assert returned['sameSite'] == 'Strict'


@pytest.mark.xfail_firefox(raises=WebDriverException,
reason='sameSite cookie attribute not implemented')
def testAddCookieSameSiteLax(same_site_cookie_lax, driver):
driver.add_cookie(same_site_cookie_lax)
returned = driver.get_cookie('foo')
assert returned['sameSite'] == 'Lax'


@pytest.mark.xfail_ie
def testAddingACookieThatExpiredInThePast(cookie, driver):
expired = cookie.copy()
Expand Down
6 changes: 4 additions & 2 deletions py/test/selenium/webdriver/common/timeout_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@

from selenium.webdriver.common.timeouts import Timeouts


def test_should_create_timeouts_object():
implicit_wait = 10
page_load = 10
script = 10
timeouts = Timeouts(implicit_wait=implicit_wait,page_load=page_load,script=script)
timeouts = Timeouts(implicit_wait=implicit_wait, page_load=page_load, script=script)

assert implicit_wait == timeouts.implicit_wait
assert page_load == timeouts.page_load
Expand All @@ -42,7 +43,7 @@ def test_should_error_if_implicit_wait_isnt_a_number():
def test_should_error_if_page_load_isnt_a_number():
with pytest.raises(TypeError):
Timeouts(page_load="abc")

timeout = Timeouts(page_load=0)
with pytest.raises(TypeError):
timeout.page_load = "abc"
Expand All @@ -63,6 +64,7 @@ def test_should_get_timeouts_without_setting_them(driver):
assert results.page_load == 300
assert results.script == 30


def test_should_set_and_get_timeouts_on_remote_end(driver):
timeout = Timeouts(implicit_wait=10)
driver.timeouts = timeout
Expand Down
14 changes: 6 additions & 8 deletions py/test/selenium/webdriver/support/relative_by_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
# specific language governing permissions and limitations
# under the License.

import pytest

from selenium.webdriver.common.by import By
from selenium.webdriver.common.by import By
from selenium.webdriver.support.relative_locator import with_tag_name


def test_should_be_able_to_find_elements_above_another(driver, pages):
pages.load("relative_locators.html")
lowest = driver.find_element(By.ID, "below")

elements = driver.find_elements(with_tag_name("p").above(lowest))

ids = [el.get_attribute('id') for el in elements]
assert "above" in ids
assert "mid" in ids
Expand All @@ -35,8 +34,7 @@ def test_should_be_able_to_combine_filters(driver, pages):
pages.load("relative_locators.html")

elements = driver.find_elements(with_tag_name("td").above(driver.find_element(By.ID, "center"))
.to_right_of(driver.find_element(By.ID, "second")))
.to_right_of(driver.find_element(By.ID, "second")))

ids = [el.get_attribute('id') for el in elements]
assert "third" in ids

assert "third" in ids
2 changes: 1 addition & 1 deletion py/test/unit/selenium/webdriver/edge/edge_options_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_use_chromium():
options = Options()
options.use_chromium = True
caps = options.to_capabilities()
assert caps['ms:edgeChromium'] == True
assert caps['ms:edgeChromium'] is True


def test_use_webview():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def test_get_page_load_strategy(options):
assert options._caps["pageLoadStrategy"] == 'normal'


def test_creates_capabilities(options):
def test_creates_capabilities_with_page_load_strategy(options):
options.page_load_strategy = 'eager'
caps = options.to_capabilities()
assert caps['pageLoadStrategy'] == 'eager'

0 comments on commit bb3a800

Please sign in to comment.