Skip to content

Commit

Permalink
match previous black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
tsnowlan committed Jul 13, 2022
1 parent 2189133 commit 0526b58
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 20 deletions.
20 changes: 15 additions & 5 deletions src/behaving/web/steps/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

# Accepts a lambda as first paramter, returns lambda result on success, or False on timeout
def _retry(func, timeout=0, delay=1):
assert isinstance(func, type(lambda: None)), "Retry expects a lambda as the first argument"
assert isinstance(
func, type(lambda: None)
), "Retry expects a lambda as the first argument"

start = time.time()
while True:
Expand All @@ -33,28 +35,36 @@ def wait_for_timeout(context, timeout):
@persona_vars
def show_element_by_id(context, id):
assert context.browser.find_by_id(id)
context.browser.execute_script('document.getElementById("%s").style.display="inline";' % id)
context.browser.execute_script(
'document.getElementById("%s").style.display="inline";' % id
)


@step('I hide the element with id "{id}"')
@persona_vars
def hide_element_by_id(context, id):
assert context.browser.find_by_id(id)
context.browser.execute_script('document.getElementById("%s").style.display="none";' % id)
context.browser.execute_script(
'document.getElementById("%s").style.display="none";' % id
)


@step('I should see "{text}"')
@step('I should see "{text}" within {timeout:d} seconds')
@persona_vars
def should_see_within_timeout(context, text, timeout=None):
assert context.browser.is_text_present(text, wait_time=timeout), f'Text "{text}" not found'
assert context.browser.is_text_present(
text, wait_time=timeout
), f'Text "{text}" not found'


@step('I should not see "{text}"')
@step('I should not see "{text}" within {timeout:d} seconds')
@persona_vars
def should_not_see_within_timeout(context, text, timeout=None):
assert context.browser.is_text_not_present(text, wait_time=timeout), f'Text "{text}" was found'
assert context.browser.is_text_not_present(
text, wait_time=timeout
), f'Text "{text}" was found'


@step('I should see an element with id "{id}"')
Expand Down
60 changes: 45 additions & 15 deletions src/behaving/web/steps/css.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@


@step('the element with xpath "{xpath}" should have the class "{cls}"')
@step('the element with xpath "{xpath}" should have the class "{cls}" within {timeout:d} seconds')
@step(
'the element with xpath "{xpath}" should have the class "{cls}" within {timeout:d} seconds'
)
@set_timeout
def element_by_xpath_should_have_class_within_timeout(
context, xpath: str, cls: str, timeout: int = 0
Expand Down Expand Up @@ -35,7 +37,9 @@ def element_by_xpath_should_not_have_class_within_timeout(

@step('"{name}" should have the class "{cls}"')
@step('"{name}" should have the class "{cls}" within {timeout:d} seconds')
def element_should_have_class_within_timeout(context, name: str, cls: str, timeout: int = 0):
def element_should_have_class_within_timeout(
context, name: str, cls: str, timeout: int = 0
):
element = context.browser.find_by_xpath(
("//*[@id='%(name)s']|" "//*[@name='%(name)s']") % {"name": name}
)
Expand All @@ -47,7 +51,9 @@ def element_should_have_class_within_timeout(context, name: str, cls: str, timeo

@step('"{name}" should not have the class "{cls}"')
@step('"{name}" should not have the class "{cls}" within {timeout:d} seconds')
def element_should_not_have_class_within_timeout(context, name: str, cls: str, timeout: int = 0):
def element_should_not_have_class_within_timeout(
context, name: str, cls: str, timeout: int = 0
):
element = context.browser.find_by_xpath(
("//*[@id='%(name)s']|" "//*[@name='%(name)s']") % {"name": name}
)
Expand All @@ -58,13 +64,21 @@ def element_should_not_have_class_within_timeout(context, name: str, cls: str, t


@step('I should see an element with the css selector "{css}"')
@step('I should see an element with the css selector "{css}" within {timeout:d} seconds')
def should_see_element_with_css_within_timeout(context, css: str, timeout: Optional[int] = None):
assert context.browser.is_element_present_by_css(css, wait_time=timeout), "Element not found"
@step(
'I should see an element with the css selector "{css}" within {timeout:d} seconds'
)
def should_see_element_with_css_within_timeout(
context, css: str, timeout: Optional[int] = None
):
assert context.browser.is_element_present_by_css(
css, wait_time=timeout
), "Element not found"


@step('I should not see an element with the css selector "{css}"')
@step('I should not see an element with the css selector "{css}" within {timeout:d} seconds')
@step(
'I should not see an element with the css selector "{css}" within {timeout:d} seconds'
)
def should_not_see_element_with_css_within_timeout(
context, css: str, timeout: Optional[int] = None
):
Expand Down Expand Up @@ -113,30 +127,46 @@ def _element_should_not_be_visible(context, css: str, timeout: int):

def _n_elements_should_be_visible(context, expected: str, css: str, timeout: int):
check = lambda: len(find_visible_by_css(context, css)) == expected
assert _retry(check, timeout), "Didn't find exactly {:d} visible elements".format(expected)
assert _retry(check, timeout), "Didn't find exactly {:d} visible elements".format(
expected
)


def _at_least_n_elements_should_be_visible(context, expected: str, css: str, timeout: int):
def _at_least_n_elements_should_be_visible(
context, expected: str, css: str, timeout: int
):
check = lambda: len(find_visible_by_css(context, css)) >= expected
assert _retry(check, timeout), "Didn't find at least {:d} visible elements".format(expected)
assert _retry(check, timeout), "Didn't find at least {:d} visible elements".format(
expected
)


@step('the element with the css selector "{css}" should be visible')
@step('the element with the css selector "{css}" should be visible within {timeout:d} seconds')
@step(
'the element with the css selector "{css}" should be visible within {timeout:d} seconds'
)
@set_timeout
def should_see_element_visible_with_css_within_timeout(context, css: str, timeout: int = 0):
def should_see_element_visible_with_css_within_timeout(
context, css: str, timeout: int = 0
):
_element_should_be_visible(context, css, timeout)


@step('the element with the css selector "{css}" should not be visible')
@step('the element with the css selector "{css}" should not be visible within {timeout:d} seconds')
@step(
'the element with the css selector "{css}" should not be visible within {timeout:d} seconds'
)
@set_timeout
def should_not_see_element_visible_with_css_within_timeout(context, css: str, timeout: int = 0):
def should_not_see_element_visible_with_css_within_timeout(
context, css: str, timeout: int = 0
):
_element_should_not_be_visible(context, css, timeout)


@step('{n:d} elements with the css selector "{css}" should be visible')
@step('{n:d} elements with the css selector "{css}" should be visible within {timeout:d} seconds')
@step(
'{n:d} elements with the css selector "{css}" should be visible within {timeout:d} seconds'
)
@set_timeout
def should_see_n_elements_visible_with_css_within_timeout(
context, n: int, css: str, timeout: int = 0
Expand Down

0 comments on commit 0526b58

Please sign in to comment.