def should_see_in_the_page(step, negate, text, wait_time): def assert_text_present_with_negates(negate, text): body = world.browser.driver.find_element_by_tag_name('body') assert_with_negate(text in body.text, negate) return True wait_for_completion(wait_time, assert_text_present_with_negates, negate, text)
def should_see_alert(step, negate, wait_time): def assert_alert(negate): world.prompt = _get_alert_or_none() assert_with_negate(world.prompt is not None, negate) if world.prompt: world.prompt.accept() return True wait_for_completion(wait_time, assert_alert, negate)
def should_be_titled(step, negate, partial, title, wait_time): def assert_title_equals(negate, partial, title): if 'contains' in partial: assert_with_negate(title in world.browser.title, negate) else: assert_equals_with_negate(world.browser.title, title, negate) return True wait_for_completion(wait_time, assert_title_equals, negate, partial, title)
def should_have_html(step, negate, partial, html, wait_time): def assert_page_html_is(negate, partial, html): if partial == 'is': assert_equals_with_negate(world.browser.html, html, negate) else: assert_with_negate(html in world.browser.html, negate) return True wait_for_completion(wait_time, assert_page_html_is, negate, partial, html)
def should_have_the_url(step, negate, partial, url, wait_time): def assert_url_equals(negate, partial, url): if partial == 'is': assert_equals_with_negate(world.browser.url, url, negate) else: assert_with_negate(url in world.browser.url, negate) return True wait_for_completion(wait_time, assert_url_equals, negate, partial, url)
def _this_step(step, negate, attribute, element_name, type_of_match, value, wait_time): def assert_element_attribute_is_or_contains_text( negate, attribute, element_name, type_of_match, value): ele_value = _get_attribute_of_element(element_name, attribute) assert_value(type_of_match, value, ele_value, negate) return True wait_for_completion( wait_time, assert_element_attribute_is_or_contains_text, negate, attribute, element_name, type_of_match, value)
def should_see_alert_with_text(step, negate, type_of_match, text, wait_time): def assert_alert_with_text(negate, type_of_match, text): world.prompt = _get_alert_or_none() prompt_exists = world.prompt is not None text_exists = None if "contains" in type_of_match: text_exists = text in world.prompt.text else: text_exists = world.prompt.text == text assert_with_negate(prompt_exists and text_exists, negate) if world.prompt: world.prompt.accept() return True wait_for_completion(wait_time, assert_alert_with_text, negate, type_of_match, text)
def should_see_alert_with_text(step, negate, type_of_match, text, wait_time): def assert_alert_with_text(negate, type_of_match, text): world.prompt = _get_alert_or_none() prompt_exists = world.prompt is not None text_exists = None if 'contains' in type_of_match: text_exists = text in world.prompt.text else: text_exists = world.prompt.text == text assert_with_negate(prompt_exists and text_exists, negate) if world.prompt: world.prompt.accept() return True wait_for_completion(wait_time, assert_alert_with_text, negate, type_of_match, text)
def _this_step(step, negate, attribute, element_name, type_of_match, upper_lower, name, wait_time): def assert_element_attribute_is_or_contains_stored_value( negate, attribute, element_name, type_of_match, upper_lower, name): current = _get_attribute_of_element(element_name, attribute) stored = world.stored_values[name] if upper_lower: stored, current = transform_for_upper_lower_comparison( stored, current, upper_lower) assert_value(type_of_match, stored, current, negate) return True wait_for_completion( wait_time, assert_element_attribute_is_or_contains_stored_value, negate, attribute, element_name, type_of_match, upper_lower, name)
def evaluate_the_javascript(step, negate, script, value, wait_time): def assert_javascript_returns_value(negate, script, value): try: assert_equals_with_negate( "%s" % world.browser.evaluate_script(script), value, negate) except NotImplementedError: logger.info("Attempted to run javascript in a javascript-disabled" "browser. Moving along.") return True try: wait_for_completion(wait_time, assert_javascript_returns_value, negate, script, value) except: ret_val = world.browser.evaluate_script(script) msg = "%s != %s after %s seconds" % (ret_val, value, wait_time) raise WrongJavascriptReturnValue(msg)
def should_see_alert_with_stored_value(step, negate, type_of_match, upper_lower, name, wait_time): def assert_alert_with_stored_value(negate, type_of_match, upper_lower, name): world.prompt = _get_alert_or_none() assert world.stored_values[name] stored = world.stored_values[name] current = world.prompt.text if upper_lower: stored, current = transform_for_upper_lower_comparison(stored, current, upper_lower) prompt_exists = world.prompt is not None text_exists = None if "contains" in type_of_match: text_exists = stored in current else: text_exists = stored == current assert_with_negate(prompt_exists and text_exists, negate) if world.prompt: world.prompt.accept() return True wait_for_completion(wait_time, assert_alert_with_stored_value, negate, type_of_match, upper_lower, name)
def should_see_alert_with_stored_value(step, negate, type_of_match, upper_lower, name, wait_time): def assert_alert_with_stored_value(negate, type_of_match, upper_lower, name): world.prompt = _get_alert_or_none() assert world.stored_values[name] stored = world.stored_values[name] current = world.prompt.text if upper_lower: stored, current = transform_for_upper_lower_comparison( stored, current, upper_lower) prompt_exists = world.prompt is not None text_exists = None if 'contains' in type_of_match: text_exists = stored in current else: text_exists = stored == current assert_with_negate(prompt_exists and text_exists, negate) if world.prompt: world.prompt.accept() return True wait_for_completion(wait_time, assert_alert_with_stored_value, negate, type_of_match, upper_lower, name)
def should_be_in_page(step, negate, page, wait_time): def _assert_on_page(): _check_is_on_page(page, negate) return True wait_for_completion(wait_time, _assert_on_page)
def should_see_a_link_called(step, negate, text, wait_time): wait_for_completion(wait_time, assert_element_exists_with_negate, negate, text, None, "find_link_by_%stext")
def should_see_a_link_to(step, negate, partial, text, wait_time): wait_for_completion(wait_time, assert_element_exists_with_negate, negate, text, partial, "find_by_%shref")
def should_see_a_link_with_partial_text(step, negate, text, wait_time): wait_for_completion(wait_time, assert_element_exists_with_negate, negate, text, "partial", "find_link_by_%stext")