def assert_element_exists_with_negate(negate, text, partial, function): infix = "partial_" if partial else "" found = True try: _get_visible_element(function % (infix, ), None, text) except (ElementDoesNotExist, ElementIsNotVisible, ElementAtIndexDoesNotExist): found = False assert_with_negate(found, negate) return True
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
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
def _check_is_on_page(page, negate): if page not in leaf_world.available_pages: raise KeyError('"%s" page is undefined.' % page) if page not in leaf_world.pages: try: page_object = create_page_object(page) except KeyError: raise else: page_object = leaf_world.pages[page] is_on_page = page_object.is_current(world.browser.url, get_page_url(world.browser.url)) assert_with_negate(is_on_page, negate) leaf_world.current_page = page_object
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
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
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
def should_see_alert_with_text(step, negate, text): alert = _get_alert_or_none() assert_with_negate(alert is not None and alert.text == text, negate) if alert: alert.accept()
def attribute_test(element, negate, *args): attribute = args[0] assert_with_negate(element.get_attribute(attribute) is not None, negate)
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
def should_see_prompt(step, negate): world.prompt = _get_alert_or_none() assert_with_negate(world.prompt is not None, negate) if world.prompt: world.prompt.accept()
def should_see_in_the_page(step, negate, text): assert_with_negate(text in world.browser.html, negate)
def _this_step(step, negate, first, last, find_pattern, content): ele = _get_element(finder_function, first, last, find_pattern) assert_with_negate(content in ele.text, negate)
def should_see_a_link_to(step, negate, link): assert_with_negate(len(world.browser.find_link_by_href(link)) > 0, negate)
def should_see_in_the_page(step, negate, text): assert_with_negate(world.browser.is_text_present(text), negate)
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
def _this_step(step, negate, first, last, find_pattern, attr_name): ele = _get_element(finder_function, first, last, find_pattern) assert_with_negate(ele[attr_name] != None, negate)
def should_see_prompt_with_text(step, negate, text): world.prompt = _get_alert_or_none() assert_with_negate(world.prompt is not None and world.prompt.text == text, negate) if world.prompt: world.prompt.accept()
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
def contains_test(element, negate, *args): content = args[0] text = getattr(element, 'text', None) assert_with_negate(content in text, negate)
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
def should_see_a_link_called(step, negate, text): assert_with_negate(len(world.browser.find_link_by_text(text)) > 0, negate)
def attribute_test(element, negate, *args): attribute = args[0] assert_with_negate(element[attribute] != None, negate)
def visibility_test(element, negate, *args): assert_with_negate(element, negate)
def assert_text_present_with_negates(negate, text): assert_with_negate(world.browser.is_text_present(text), negate) return True
def assert_link_exists_negates(negate, text): assert_with_negate(len(world.browser.find_link_by_href(text)) > 0, negate) return True
def should_see_alert(step, negate): alert = _get_alert_or_none() assert_with_negate(alert is not None, negate) if alert: alert.accept()