Skip to content

Commit

Permalink
python: test function names tidy up inline with pep8 (SeleniumHQ#10490
Browse files Browse the repository at this point in the history
)

* `python`: apply pep8 compliant snake case to tests

* fix fallout from commented test changes; update everything inside `py/test/`

Co-authored-by: David Burns <[email protected]>
  • Loading branch information
symonk and AutomatedTester authored Apr 7, 2022
1 parent cfec55b commit 74f6344
Show file tree
Hide file tree
Showing 39 changed files with 609 additions and 608 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Gemfile.lock
.idea/inspectionProfiles/Project_Default.xml
.idea/misc.xml
third_party/py/googlestorage/client_secrets.json
.venv
venv
venv3
py/.idea
Expand Down
2 changes: 1 addition & 1 deletion py/docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Selenium WebDriver is often used as a basis for testing web applications. Here
self.browser = webdriver.Firefox()
self.addCleanup(self.browser.quit)
def testPageTitle(self):
def test_page_title(self):
self.browser.get('http://www.google.com')
self.assertIn('Google', self.browser.title)
Expand Down
92 changes: 46 additions & 46 deletions py/test/selenium/webdriver/common/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def close_alert(driver):
pass


def testShouldBeAbleToOverrideTheWindowAlertMethod(driver, pages):
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; }")
Expand All @@ -48,79 +48,79 @@ def testShouldBeAbleToOverrideTheWindowAlertMethod(driver, pages):
# if we're here, likely the alert is displayed
# not dismissing it will affect other tests
try:
_waitForAlert(driver).dismiss()
_wait_for_alert(driver).dismiss()
except Exception:
pass
raise e


def testShouldAllowUsersToAcceptAnAlertManually(driver, pages):
def test_should_allow_users_to_accept_an_alert_manually(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()
# If we can perform any action, we're good to go
assert "Testing Alerts" == driver.title


def testShouldAllowUsersToAcceptAnAlertWithNoTextManually(driver, pages):
def test_should_allow_users_to_accept_an_alert_with_no_text_manually(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "empty-alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

# If we can perform any action, we're good to go
assert "Testing Alerts" == driver.title


def testShouldGetTextOfAlertOpenedInSetTimeout(driver, pages):
def test_should_get_text_of_alert_opened_in_set_timeout(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "slow-alert").click()

# DO NOT WAIT OR SLEEP HERE
# This is a regression test for a bug where only the first switchTo call would throw,
# and only if it happens before the alert actually loads.

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
try:
assert "Slow" == alert.text
finally:
alert.accept()


def testShouldAllowUsersToDismissAnAlertManually(driver, pages):
def test_should_allow_users_to_dismiss_an_alert_manually(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.dismiss()
# If we can perform any action, we're good to go
assert "Testing Alerts" == driver.title


def testShouldAllowAUserToAcceptAPrompt(driver, pages):
def test_should_allow_auser_to_accept_aprompt(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="prompt").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

# If we can perform any action, we're good to go
assert "Testing Alerts" == driver.title


def testShouldAllowAUserToDismissAPrompt(driver, pages):
def test_should_allow_auser_to_dismiss_aprompt(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="prompt").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.dismiss()

# If we can perform any action, we're good to go
assert "Testing Alerts" == driver.title


def testShouldAllowAUserToSetTheValueOfAPrompt(driver, pages):
def test_should_allow_auser_to_set_the_value_of_aprompt(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="prompt").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.send_keys("cheese")
alert.accept()

Expand All @@ -130,11 +130,11 @@ def testShouldAllowAUserToSetTheValueOfAPrompt(driver, pages):

@pytest.mark.xfail_firefox
@pytest.mark.xfail_remote
def testSettingTheValueOfAnAlertThrows(driver, pages):
def test_setting_the_value_of_an_alert_throws(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "alert").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
with pytest.raises(InvalidElementStateException):
alert.send_keys("cheese")
alert.accept()
Expand All @@ -148,11 +148,11 @@ def testSettingTheValueOfAnAlertThrows(driver, pages):
condition=sys.platform == 'darwin',
reason='https://bugs.chromium.org/p/chromedriver/issues/detail?id=26',
run=False)
def testAlertShouldNotAllowAdditionalCommandsIfDimissed(driver, pages):
def test_alert_should_not_allow_additional_commands_if_dimissed(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "alert").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.dismiss()

with pytest.raises(NoAlertPresentException):
Expand All @@ -162,12 +162,12 @@ def testAlertShouldNotAllowAdditionalCommandsIfDimissed(driver, pages):
@pytest.mark.xfail_firefox(reason='Fails on travis')
@pytest.mark.xfail_remote(reason='Fails on travis')
@pytest.mark.xfail_safari
def testShouldAllowUsersToAcceptAnAlertInAFrame(driver, pages):
def test_should_allow_users_to_accept_an_alert_in_aframe(driver, pages):
pages.load("alerts.html")
driver.switch_to.frame(driver.find_element(By.NAME, "iframeWithAlert"))
driver.find_element(By.ID, "alertInFrame").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

assert "Testing Alerts" == driver.title
Expand All @@ -176,54 +176,54 @@ def testShouldAllowUsersToAcceptAnAlertInAFrame(driver, pages):
@pytest.mark.xfail_firefox(reason='Fails on travis')
@pytest.mark.xfail_remote(reason='Fails on travis')
@pytest.mark.xfail_safari
def testShouldAllowUsersToAcceptAnAlertInANestedFrame(driver, pages):
def test_should_allow_users_to_accept_an_alert_in_anested_frame(driver, pages):
pages.load("alerts.html")
driver.switch_to.frame(driver.find_element(By.NAME, "iframeWithIframe"))
driver.switch_to.frame(driver.find_element(By.NAME, "iframeWithAlert"))

driver.find_element(By.ID, "alertInFrame").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

assert "Testing Alerts" == driver.title


def testShouldThrowAnExceptionIfAnAlertHasNotBeenDealtWithAndDismissTheAlert():
def test_should_throw_an_exception_if_an_alert_has_not_been_dealt_with_and_dismiss_the_alert():
pass
# //TODO(David) Complete this test


def testPromptShouldUseDefaultValueIfNoKeysSent(driver, pages):
def test_prompt_should_use_default_value_if_no_keys_sent(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "prompt-with-default").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

txt = driver.find_element(By.ID, "text").text
assert "This is a default value" == txt


def testPromptShouldHaveNullValueIfDismissed(driver, pages):
def test_prompt_should_have_null_value_if_dismissed(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "prompt-with-default").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.dismiss()

assert "null" == driver.find_element(By.ID, "text").text


def testHandlesTwoAlertsFromOneInteraction(driver, pages):
def test_handles_two_alerts_from_one_interaction(driver, pages):
pages.load("alerts.html")

driver.find_element(By.ID, "double-prompt").click()

alert1 = _waitForAlert(driver)
alert1 = _wait_for_alert(driver)
alert1.send_keys("brie")
alert1.accept()

alert2 = _waitForAlert(driver)
alert2 = _wait_for_alert(driver)
alert2.send_keys("cheddar")
alert2.accept()

Expand All @@ -232,18 +232,18 @@ def testHandlesTwoAlertsFromOneInteraction(driver, pages):


@pytest.mark.xfail_safari
def testShouldHandleAlertOnPageLoad(driver, pages):
def test_should_handle_alert_on_page_load(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "open-page-with-onload-alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
value = alert.text
alert.accept()
assert "onload" == value


def testShouldHandleAlertOnPageLoadUsingGet(driver, pages):
def test_should_handle_alert_on_page_load_using_get(driver, pages):
pages.load("pageWithOnLoad.html")
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
value = alert.text
alert.accept()

Expand All @@ -253,39 +253,39 @@ def testShouldHandleAlertOnPageLoadUsingGet(driver, pages):

@pytest.mark.xfail_chrome(reason='Non W3C conformant')
@pytest.mark.xfail_chromiumedge(reason='Non W3C conformant')
def testShouldHandleAlertOnPageBeforeUnload(driver, pages):
def test_should_handle_alert_on_page_before_unload(driver, pages):
pages.load("pageWithOnBeforeUnloadMessage.html")

element = driver.find_element(By.ID, "navigate")
element.click()
WebDriverWait(driver, 3).until(EC.title_is("Testing Alerts"))


def testShouldAllowTheUserToGetTheTextOfAnAlert(driver, pages):
def test_should_allow_the_user_to_get_the_text_of_an_alert(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
value = alert.text
alert.accept()
assert "cheese" == value


def testShouldAllowTheUserToGetTheTextOfAPrompt(driver, pages):
def test_should_allow_the_user_to_get_the_text_of_aprompt(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "prompt").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
value = alert.text
alert.accept()

assert "Enter something" == value


def testAlertShouldNotAllowAdditionalCommandsIfDismissed(driver, pages):
def test_alert_should_not_allow_additional_commands_if_dismissed(driver, pages):
pages.load("alerts.html")
driver.find_element(By.ID, "alert").click()

alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
alert.accept()

with pytest.raises(NoAlertPresentException):
Expand All @@ -297,16 +297,16 @@ def testAlertShouldNotAllowAdditionalCommandsIfDismissed(driver, pages):
@pytest.mark.xfail_remote(
reason='https://bugzilla.mozilla.org/show_bug.cgi?id=1279211')
@pytest.mark.xfail_chrome
def testUnexpectedAlertPresentExceptionContainsAlertText(driver, pages):
def test_unexpected_alert_present_exception_contains_alert_text(driver, pages):
pages.load("alerts.html")
driver.find_element(by=By.ID, value="alert").click()
alert = _waitForAlert(driver)
alert = _wait_for_alert(driver)
value = alert.text
with pytest.raises(UnexpectedAlertPresentException) as e:
pages.load("simpleTest.html")
assert value == e.value.alert_text
assert "Alert Text: {}".format(value) in str(e)


def _waitForAlert(driver):
def _wait_for_alert(driver):
return WebDriverWait(driver, 3).until(EC.alert_is_present())
Loading

0 comments on commit 74f6344

Please sign in to comment.