Skip to content

Commit

Permalink
CHORE: fix black style violations
Browse files Browse the repository at this point in the history
  • Loading branch information
yashaka committed Apr 22, 2022
1 parent 0a5a5b6 commit bceaf28
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions examples/custom_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,16 @@ def test_wait_for_produced_todos_v2():


def test_wait_for_notification_after_reload_v1():
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

def assert_action_successful_on_reload(entity):
browser.element('[href*=notification_message]').click()

if not browser.element('#flash').matching(have.exact_text('Action successful\n×')):
if not browser.element('#flash').matching(
have.exact_text('Action successful\n×')
):
raise AssertionError('wrong message received')

browser.wait.for_(assert_action_successful_on_reload)
Expand All @@ -76,7 +80,9 @@ def test_wait_for_notification_after_reload_v2():
more descriptive implementation
with custom rendering of error message on failure
"""
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

def assert_action_successful_on_reload(entity):
browser.element('[href*=notification_message]').click()
Expand Down Expand Up @@ -114,7 +120,9 @@ def test_wait_for_notification_after_reload_v3():
- that should be browser
if condition was called on a browser object
"""
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

def notification_on_reload(message: str) -> BrowserCondition:
def fn(entity: Browser):
Expand All @@ -137,16 +145,19 @@ def fn(entity: Browser):
)

browser.wait.for_(
notification_on_reload('Action successful\n×')
.or_(notification_on_reload('Action unsuccesful, please try again\n×'))
notification_on_reload('Action successful\n×').or_(
notification_on_reload('Action unsuccesful, please try again\n×')
)
)


def test_wait_for_notification_after_reload_v4():
"""
with default rendering (built into selene's condition) of error message on failure
"""
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

def assert_action_successful_on_reload(entity):
browser.element('[href*=notification_message]').click()
Expand All @@ -160,12 +171,16 @@ def test_wait_for_notification_after_reload_v5():
with default rendering (built into selene's condition) of error message on failure
AND simplified syntax with lambdas
"""
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

browser.wait.for_(lambda _: (
browser.element('[href*=notification_message]').click(),
have.exact_text('Action successful\n×')(browser.element('#flash')),
))
browser.wait.for_(
lambda _: (
browser.element('[href*=notification_message]').click(),
have.exact_text('Action successful\n×')(browser.element('#flash')),
)
)


def test_wait_for_notification_after_reload_v6():
Expand All @@ -174,12 +189,16 @@ def test_wait_for_notification_after_reload_v6():
and simplified syntax with lambdas
AND with optimised performance and removed potential side effects of "nested waiting"
"""
browser.open('https://the-internet.herokuapp.com/notification_message_rendered')
browser.open(
'https://the-internet.herokuapp.com/notification_message_rendered'
)

browser.wait.for_(lambda _: (
browser.element('[href*=notification_message]')().click(),
have.exact_text('Action successful\n×')(browser.element('#flash')),
))
browser.wait.for_(
lambda _: (
browser.element('[href*=notification_message]')().click(),
have.exact_text('Action successful\n×')(browser.element('#flash')),
)
)
'''
notice how we called `().click()` instead of `.click()` on notification element
extra parenthesis allows to get actual webelement
Expand Down

0 comments on commit bceaf28

Please sign in to comment.