示例#1
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    b = actions.get_browser()
    text_input = b.find(id='input-one')
    actions.focus_element(text_input)
    active_element = actions.get_active_element()
    assert active_element == actions.get_browser().switch_to.active_element
def test(data):
    actions.navigate(data.env.url+'dynamic-elements/?delay=3')
    actions.get_browser().wait_for_element_text_contains('#button-seven', 'New', 5)
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "Timeout waiting for element #button-seven text to contain 'New'"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_text_contains('#button-seven', 'New', 3)
示例#3
0
def test(data):
    actions.navigate(data.env.url + 'tabs/')
    actions.click('#openTab')
    actions.wait_for_window_present_by_title('Tab')
    assert actions.get_browser().get_window_index() == 0
    actions.switch_to_window_by_index(1)
    assert actions.get_browser().get_window_index() == 1
示例#4
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.get_browser().wait_for_element_present('#button-five', 5)
    actions.verify_element_present('#button-five')
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "timeout waiting for element #button-five to be present"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_present('#button-five', 3)
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.wait_for_element_enabled('#button-three', 10)
    actions.verify_element_enabled('#button-three')
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "Timeout waiting for element #button-three to be enabled"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_enabled('#button-three',
                                                       timeout=3)
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.get_browser().wait_for_element_text_is_not('#button-seven',
                                                       'Initial Text', 10)
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "Timeout waiting for element #button-seven text not to be 'Initial Text'"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_text_is_not(
            '#button-seven', 'Initial Text', 3)
示例#7
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.wait_for_element_not_enabled('#button-four', timeout=5)
    actions.verify_element_not_enabled('#button-four')
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = 'Timeout waiting for element #button-four to be not enabled'
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_not_enabled('#button-four',
                                                           timeout=3)
示例#8
0
def test(data):
    actions.navigate(data.env.url+'tabs/')
    actions.click('#openTab')
    actions.wait_for_window_present_by_title('Tab')
    actions.get_browser().switch_to_window_by_index(1)
    assert actions.get_window_index() == 1
    actions.verify_title('Tab')
    actions.switch_to_first_window()
    assert actions.get_window_index() == 0
    actions.verify_title('Web Playground - Tabs')
示例#9
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.get_browser().wait_for_page_not_contains_text(
        '<button id="button-six"', timeout=5)
    # wait times out waiting for text to be present in page
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "Timeout waiting for page to not contain '<button id=\"button-six\"'"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_page_not_contains_text(
            '<button id="button-six"', timeout=3)
def test(data):
    actions.navigate(data.env.url + 'tabs/')
    actions.send_keys('#urlInput', '/elements/')
    actions.click("#goButton")
    actions.get_browser().switch_to_window_by_partial_title('Ele')
    actions.verify_title('Web Playground - Elements')
    msg = "Window with partial title 'incorrect title' was not found"
    with expected_exception(Exception, msg):
        actions.get_browser().switch_to_window_by_partial_title(
            'incorrect title')
示例#11
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    actions.click('#change-title-button')
    actions.assert_title('Web Playground - Dynamic Elements')
    actions.get_browser().wait_for_title_contains('New', 4)
    actions.assert_title('New Title')
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = "Timeout waiting for title to contain 'New'"
    with expected_exception(Exception, msg):
        actions.click('#change-title-button')
        actions.get_browser().wait_for_title_contains('New', 2)
示例#12
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=2')
    actions.verify_title('Web Playground - Dynamic Elements')
    actions.click('#change-title-button')
    actions.get_browser().wait_for_title('New Title', 4)
    actions.verify_title('New Title')
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    with expected_exception(Exception,
                            "Timeout waiting for title to be 'New Title'"):
        actions.click('#change-title-button')
        actions.get_browser().wait_for_title('New Title', 2)
示例#13
0
def test(data):
    actions.navigate(data.env.url + 'tabs/')
    actions.send_keys('#delay', 3)
    actions.send_keys('#title', 'MY_TITLE')
    actions.click("#goButtonCustom")
    url = data.env.url + 'tab/?delay=3&title=MY_TITLE'
    actions.get_browser().wait_for_window_present_by_url(url, timeout=5)
    actions.verify_window_present_by_url(url)
    msg = "Timeout waiting for window present by url 'URL_NOT_PRESENT'"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_window_present_by_url('URL_NOT_PRESENT',
                                                             timeout=3)
def test(data):
    actions.navigate(data.env.url + 'tabs/')
    actions.send_keys('#delay', 2)
    actions.send_keys('#title', 'MY TITLE')
    actions.click("#goButtonCustom")
    actions.get_browser().wait_for_window_present_by_title('MY TITLE',
                                                           timeout=4)
    actions.verify_window_present_by_title('MY TITLE')
    msg = "Timeout waiting for window present by title 'TITLE NOT PRESENT'"
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_window_present_by_title(
            'TITLE NOT PRESENT', timeout=2)
示例#15
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    element = actions.get_browser().find('#input-one')
    element.press_key('NUMPAD2')
    actions.verify_text_in_element('#input-one-input-result', 'Welcome 2')
    try:
        element = actions.get_browser().find('#input-one')
        element.press_key('UNDEFINED_KEY')
    except Exception as e:
        assert 'Key UNDEFINED_KEY is invalid' in e.args[0]
    else:
        raise AssertionError('expected an exception')
示例#16
0
def assert_info_bar_message(msg):
    actions.step('Assert an info bar is displayed with msg: {}'.format(msg))
    info_bars = actions.get_browser().find_all('.info-bar')
    if not info_bars:
        time.sleep(1)
        info_bars = actions.get_browser().find_all('.info-bar')
    for bar in info_bars:
        if msg in bar.text:
            return
    info_bars_text = '\n'.join([bar.text for bar in info_bars])
    error = ('expected an info bar with text {}\nInfo Bars found:\n{}'
             .format(msg, info_bars_text))
    actions.fail(error)
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=3')
    element = '#button-height'
    attribute = 'verified'
    actions.verify_element_has_not_attribute(element, attribute)
    actions.get_browser().wait_for_element_has_attribute(element, attribute, 5)
    actions.verify_element_has_attribute(element, attribute)
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    msg = 'Timeout waiting for element {} to have attribute {}'.format(
        element, attribute)
    with expected_exception(Exception, msg):
        actions.get_browser().wait_for_element_has_attribute(
            element, attribute, 3)
def test(data):
    actions.navigate(data.env.url + 'tabs/')
    actions.send_keys('#urlInput', '/elements/')
    actions.click("#goButton")
    actions.clear_element('#urlInput')
    actions.send_keys('#urlInput', '/alert/')
    actions.click("#goButton")
    actions.switch_to_window_by_index(0)
    first_title = actions.get_window_title()
    first_title_partial = first_title[:-2]
    actions.switch_to_window_by_index(1)
    second_title = actions.get_window_title()
    actions.switch_to_window_by_index(2)
    third_title = actions.get_window_title()
    third_title_partial = third_title[:-2]
    actions.switch_to_window_by_index(0)
    browser = actions.get_browser()
    # close third window by partial title
    browser.close_window_by_partial_title(third_title_partial)
    actions.verify_amount_of_windows(2)
    actions.verify_title(first_title)
    # close first window by partial title, from the first window
    browser.close_window_by_partial_title(first_title_partial)
    # second window is now active
    actions.verify_amount_of_windows(1)
    actions.verify_title(second_title)
    # try to close a window that is not present
    msg = "a window with partial title 'Incorrect Title' was not found"
    with expected_exception(Exception, msg):
        browser.close_window_by_partial_title('Incorrect Title')
示例#19
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    checkbox_not_checked = '#unselected-checkbox'
    checkbox_checked = '#selected-checkbox'
    radio_not_checked = '#exampleRadios2'
    # checkbox not checked
    actions.verify_element_not_checked(checkbox_not_checked)
    browser.check_element(checkbox_not_checked)
    actions.verify_element_checked(checkbox_not_checked)
    # checkbox already checked
    actions.verify_element_checked(checkbox_checked)
    browser.check_element(checkbox_checked)
    actions.verify_element_checked(checkbox_checked)
    # radio button not checked
    actions.verify_element_not_checked(radio_not_checked)
    browser.check_element(radio_not_checked)
    actions.verify_element_checked(radio_not_checked)
    radio_checked = radio_not_checked
    # radio button already checked
    browser.check_element(radio_checked)
    actions.verify_element_checked(radio_checked)
    # try to check an element not radio or checkbox
    try:
        browser.check_element('#button-one')
        assert False, 'Expected Exception'
    except Exception as e:
        assert 'Element #button-one is not checkbox or radiobutton' in e.args[
            0]
示例#20
0
def test(data):
    actions.navigate(data.env.url+'elements/')
    browser = actions.get_browser()
    execution.settings['implicit_wait'] = 0
    actions.step('Find element by id with settings timeout equals zero')
    button = browser.find(id='button-one')
    assert button.text == 'Click Me'
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    selector = 'this is a link to'
    actions.step('Find all elements by partial_link_text')
    links = browser.find_all(partial_link_text=selector)
    assert len(links) == 1
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    browser = actions.get_browser()
    execution.settings['implicit_wait'] = 10
    actions.step('Find element by id with settings timeout')
    button = browser.find(id='button-five')
    assert button.text == 'Click Me'
示例#23
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    checkbox_not_checked = browser.find('#unselected-checkbox')
    checkbox_checked = browser.find('#selected-checkbox')
    radio_not_checked = browser.find('#exampleRadios2')
    # checkbox not checked
    actions.verify_element_not_checked(checkbox_not_checked)
    checkbox_not_checked.check()
    actions.verify_element_checked(checkbox_not_checked)
    # checkbox already checked
    actions.verify_element_checked(checkbox_checked)
    checkbox_checked.check()
    actions.verify_element_checked(checkbox_checked)
    # radio button not checked
    actions.verify_element_not_checked(radio_not_checked)
    radio_not_checked.check()
    actions.verify_element_checked(radio_not_checked)
    radio_checked = radio_not_checked
    # radio button already checked
    radio_checked.check()
    actions.verify_element_checked(radio_checked)
    # try to check an element not radio or checkbox
    msg = 'Element #button-one is not checkbox or radiobutton'
    with expected_exception(Exception, msg):
        browser.find('#button-one').check()
示例#24
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    selector = '//input[@type="checkbox"]'
    actions.step('Find all elements by xpath')
    checkboxes = browser.find_all(xpath=selector)
    assert len(checkboxes) == 2
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    selector = '.invalid-selector-value'
    actions.step('Find all elements by css')
    elems = browser.find_all(css=selector)
    assert type(elems) == list
    assert len(elems) == 0
示例#26
0
def test(data):
    actions.navigate(data.env.url + 'dynamic-elements/?delay=5')
    browser = actions.get_browser()
    actions.step('Find element by id with timeout')
    try:
        button = browser.find(id='button-one', timeout=3, wait_displayed=True)
    except ElementNotDisplayed:
        pass
示例#27
0
def test(data):
    actions.open_browser()
    actions.set_window_size(400, 400)
    browser = actions.get_browser()
    width = browser.get_window_size()['width']
    height = browser.get_window_size()['height']
    assert width == 400
    assert height == 400
示例#28
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    selector = '//img[@id="image1"]'
    img = actions.get_browser().find(selector)
    assert type(img) in [ExtendedRemoteWebElement, ExtendedFirefoxWebElement]
    assert img.selector_type == 'xpath'
    assert img.selector_value == selector
    assert img.name == selector
示例#29
0
def test(data):
    tabs_url = data.env.url + 'tabs/'
    tab_url = data.env.url + 'tab/'
    actions.navigate(tabs_url)
    actions.click('#openTab')
    actions.wait_for_window_present_by_title('Tab')
    window_urls = actions.get_browser().get_window_urls()
    assert window_urls == [tabs_url, tab_url]
示例#30
0
def test(data):
    actions.navigate(data.env.url + 'elements/')
    browser = actions.get_browser()
    actions.step('Find parent element')
    body = browser.find('body')
    actions.step('Find child element by id')
    inputs = body.find_all(tag_name='input')
    assert len(inputs) == 5