示例#1
0
def goto(step, url):
    url = url.strip('"')
    if not url.startswith('http'):
        url = url_for(url)

    with AssertContextManager(step):
        world.browser.get(url)
示例#2
0
def select_multi_items(step, select_name):
    with AssertContextManager(step):
        # Ensure only the options selected are actually selected
        option_names = step.multiline.split('\n')
        select_box = find_field(world.browser, 'select', select_name)

        select = Select(select_box)
        select.deselect_all()

        for option in option_names:
            try:
                select.select_by_value(option)
            except NoSuchElementException:
                select.select_by_visible_text(option)
示例#3
0
def assert_multi_selected(step, select_name):
    with AssertContextManager(step):
        # Ensure its not selected unless its one of our options
        option_names = step.multiline.split('\n')
        select_box = find_field(world.browser, 'select', select_name)
        option_elems = select_box.find_elements_by_xpath('./option')
        for option in option_elems:
            if option.get_attribute('id') in option_names or \
               option.get_attribute('name') in option_names or \
               option.get_attribute('value') in option_names or \
               option.text in option_names:
                assert_true(step, option.is_selected())
            else:
                assert_true(step, not option.is_selected())
示例#4
0
def focus_and_press_key(step, field_name, key):
    with AssertContextManager(step):
        text_field = find_field(world.browser, 'text', field_name) or \
          find_field(world.browser, 'textarea', field_name) or \
          find_field(world.browser, 'password', field_name) or \
          find_field(world.browser, 'datetime', field_name) or \
          find_field(world.browser, 'datetime-local', field_name) or \
          find_field(world.browser, 'date', field_name) or \
          find_field(world.browser, 'month', field_name) or \
          find_field(world.browser, 'time', field_name) or \
          find_field(world.browser, 'week', field_name) or \
          find_field(world.browser, 'number', field_name) or \
          find_field(world.browser, 'range', field_name) or \
          find_field(world.browser, 'email', field_name) or \
          find_field(world.browser, 'url', field_name) or \
          find_field(world.browser, 'search', field_name) or \
          find_field(world.browser, 'tel', field_name) or \
          find_field(world.browser, 'color', field_name)
        assert_false(step, text_field is False,
                     'Can not find a field named "%s"' % field_name)
        text_field.send_keys(getattr(Keys, key))
示例#5
0
def fill_in_textfield(step, field_name, value):
    with AssertContextManager(step):
        text_field = find_field(world.browser, 'text', field_name) or \
          find_field(world.browser, 'textarea', field_name) or \
          find_field(world.browser, 'password', field_name) or \
          find_field(world.browser, 'datetime', field_name) or \
          find_field(world.browser, 'datetime-local', field_name) or \
          find_field(world.browser, 'date', field_name) or \
          find_field(world.browser, 'month', field_name) or \
          find_field(world.browser, 'time', field_name) or \
          find_field(world.browser, 'week', field_name) or \
          find_field(world.browser, 'number', field_name) or \
          find_field(world.browser, 'range', field_name) or \
          find_field(world.browser, 'email', field_name) or \
          find_field(world.browser, 'url', field_name) or \
          find_field(world.browser, 'search', field_name) or \
          find_field(world.browser, 'tel', field_name) or \
          find_field(world.browser, 'color', field_name)
        assert_false(step, text_field is False,
                     'Can not find a field named "%s"' % field_name)
        text_field.clear()
        text_field.send_keys(value)
示例#6
0
def click(step, name):
    with AssertContextManager(step):
        elem = world.browser.find_element_by_link_text(name)
        elem.click()
示例#7
0
def visit(step, url):
    with AssertContextManager(step):
        world.browser.get(url)
示例#8
0
def click_on_an_element(step, selector):
    with AssertContextManager(step):
        e = world.browser.find_element_by_css_selector(selector)
        e.click()
示例#9
0
def fill_in_textfield_by_class(step, field_name, value):
    with AssertContextManager(step):
        text_field = find_field_by_class(world.browser, field_name)
        text_field.clear()
        text_field.send_keys(value)
示例#10
0
def choose_radio(step, value):
    with AssertContextManager(step):
        box = find_field(world.browser, 'radio', value)
        box.select()
示例#11
0
def select_single_item(step, option_name, select_name):
    with AssertContextManager(step):
        option_box = find_option(world.browser, select_name, option_name)
        option_box.click()
示例#12
0
def uncheck_checkbox(step, value):
    with AssertContextManager(step):
        check_box = find_field(world.browser, 'checkbox', value)
        if check_box.is_selected():
            check_box.click()
示例#13
0
def press_button(step, value):
    with AssertContextManager(step):
        button = find_button(world.browser, value)
        button.click()