Example #1
0
def test_an_element_found_by_locator_and_text_can_by_just_returned():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element_with_locator_and_text((By.CSS_SELECTOR, '#list li'),
                                           'fourth_li'))

    assert returned_value.text == 'fourth_li'
Example #2
0
def test_the_value_of_a_stored_element_is_returned():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'fourth_text')).and_store_as('textbox'),
        value_of().stored_element('textbox'))

    assert returned_value == 'fourth textbox'
def test_the_text_of_a_stored_element_is_only_returned_if_no_request_to_store_is_requested(
):
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'hello_id')).and_store_as('hello'),
        text_of().stored_element('hello'))

    assert returned_value == 'hello'
def test_a_located_element_can_be_clicked_on():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        click_on().element((By.ID, 'first')),
        find_element((By.ID, 'output')).and_store_as('output_div'),
        text_of().stored_element('output_div')
    )

    assert returned_value == 'first'
def test_text_can_be_entered_into_a_located_element():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        enter_text('Hello World').into_element((By.ID, 'third_text')),
        click_on().element((By.ID, 'third')),
        find_element((By.ID, 'output')).and_store_as('output_div'),
        text_of().stored_element('output_div'))

    assert returned_value == 'Hello World'
def test_finding_an_element_that_does_not_exists_stores_and_returns_None():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'does_not_exist')).and_store_as('hello'))

    assert returned_value is None

    stored_value = user.state['hello'].value

    assert stored_value is None
def test_an_element_that_exists_is_found_is_stored_and_returned():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'hello_id')).and_store_as('hello'))

    assert returned_value.text == 'hello'

    stored_value = user.state['hello'].value

    assert stored_value.text == 'hello'
Example #8
0
def test_a_whitespace_stripped_value_of_a_stored_element_is_returned():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    locator = (By.ID, 'third_text')

    returned_value = user.attempts_to(
        navigate_to(test_page),
        enter_text('  text  ').into_element(locator),
        find_element(locator).and_store_as('textbox'),
        value_of().stored_element('textbox').stripped_of_whitespace())

    assert returned_value == 'text'
def test_stripping_the_text_removes_whitespace():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'world_id')).and_store_as('world'),
        text_of().stored_element(
            'world').stripped_of_whitespace().and_store_as('text'))

    assert returned_value == 'world'

    stored_value = user.state['text'].value

    assert stored_value == 'world'
Example #10
0
def test_trying_to_find_an_element_that_does_not_exist_stores_and_returns_None(
):
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element_with_locator_and_text(
            (By.CSS_SELECTOR, '#does_not_exist'),
            'fourth_li').and_store_as('fourth'))

    assert returned_value is None

    stored_value = user.state['fourth'].value

    assert stored_value is None
def test_finding_a_subelement_of_a_stored_element_is_stored_and_returned():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    returned_value = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'parent')).and_store_as('parent'),
        find_sub_element(
            (By.ID,
             'child')).from_stored_element('parent').and_store_as('child'))

    assert returned_value.text == 'child'

    stored_value = user.state['child'].value

    assert stored_value.text == 'child'
Example #12
0
def test_a_sub_element_can_be_found_by_its_text():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    user.attempts_to(
        navigate_to(test_page),
        find_elements(
            (By.CSS_SELECTOR, '#list li')).and_store_as('list_elements'))

    returned_value = user.attempts_to(
        find_stored_element_in('list_elements').with_text_equal_to(
            'third_li').and_store_as('found'))

    assert returned_value.text == 'third_li'

    stored_value = user.state['found'].value

    assert stored_value.text == 'third_li'
Example #13
0
def test_a_subelement_of_a_WebElement_can_be_clicked_on():
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    element = user.attempts_to(
        navigate_to(test_page),
        find_element((By.ID, 'second_div'))
    )

    user.attempts_to(
        click_on_sub_element((By.ID, 'second')).of_WebElement(element),
    )

    returned_value = user.attempts_to(
        find_element((By.ID, 'output')).and_store_as('output_div'),
        text_of().stored_element('output_div')
    )

    assert returned_value == 'second'
def test_hiding_the_text_from_the_log_when_entering_text_into_a_located_element(
):
    user = Actor.named('user').who_can(browse_the_web.using_Chrome())

    user.attempts_to(navigate_to(test_page))

    Log.to_actions()

    log_text = capture_log_messages(
        user,
        enter_text('Hello World').into_element(
            (By.ID, 'third_text')).and_do_not_log_text())

    assert len(
        log_text
    ) == 1, "Only expected 1 log message, actually {n} message(s)".format(
        n=len(log_text))
    assert log_text[0].strip(
    ) == 'Enter text \'**hidden**\' into element "(\'id\', \'third_text\')"'