def perform_as(self, actor: Actor):
        assert save_screenshot.path is not None, "capture_screenshot.path not set before trying to capture a screenshot"
        filename = path.join(save_screenshot.path, str(self._index) + '.png')

        actor.attempts_to(
            save_screenshot_to_file(filename)
        )
Exemplo n.º 2
0
 def perform_as(self, actor: Actor):
     if self._id is not None:
         value = actor.state[self._id].value
         matched = False
         for required_value in self._values:
             if value == required_value:
                 matched = True
         if matched is False:
             actor.attempts_to(*self._actions)
def test_selecting_an_element_from_a_stored_list_returns_the_value_and_stores_it_in_the_actors_state():
    user = Actor('user')
    user.state['list'].set(['a', 'b', 'c', 'd'])

    returned_value = user.attempts_to(
        select_element_at_index(1).from_stored_list('list').and_store_in('found')
    )

    assert returned_value == 'b', "Returned value was incorrect"
    assert user.state['found'].value == 'b', "Stored value was incorrect"
Exemplo n.º 4
0
def test_The_log_indent_is_restored_if_a_test_fails():
    user = Actor('user')

    Log.to_actions()
    original_indent = _LogIndent.current_indent

    try:
        user.attempts_to(failing_task())
    except AssertionError:
        pass

    assert original_indent == _LogIndent.current_indent, 'The indent was not reset if an action fails'
Exemplo n.º 5
0
def test_The_log_indent_is_not_increased_by_actions_if_only_logging_to_tasks():
    user = Actor('user')

    Log.to_tasks()

    start_indent = _LogIndent.current_indent

    action = record_log_indent_action()
    task = record_log_indent_task(action)

    user.attempts_to(task)

    assert task.indent == start_indent + 2, 'Task not indented correctly'
    assert action.indent == start_indent + 2, 'Action not indented correctly'
def test_an_attempted_out_of_bounds_access_causes_an_assertion():
    user = Actor('user')
    user.state['list'].set(['a'])

    with pytest.raises(AssertionError) as exception:
        user.attempts_to(
            select_element_at_index(1).from_stored_list('list').and_store_in(
                'found'))

    expected = "'list' does not have enough elements to access element 1"
    actual = exception.value.args[0]

    assert actual == expected, "Incorrect message\nExpected: {expected}\nActual:{actual}".format(
        expected=expected, actual=actual)
def capture_log_messages(user: Actor, *actions):
    original_log_function = Log.write_line
    log_text = []

    def write_line(*values, sep=''):
        line = sep.join(map(str, chain.from_iterable(values)))
        log_text.append(line)

    Log.write_line = write_line

    try:
        user.attempts_to(*actions)
    finally:
        Log.write_line = original_log_function

    return log_text
def test_fail_with_message_causes_an_assertion():
    user = Actor.named('user')

    with pytest.raises(AssertionError) as exception:
        user.attempts_to(fail_with_message('simple message'))

    assert exception.value.args[0] == 'simple message'
def test_A_using_task_whose_sub_task_does_not_return_a_value_sets_the_state_to_none(
):
    frank = Actor.named('Frank')

    frank.attempts_to(using(StubTask()).as_('Simon'))

    assert value_of(frank.state['Simon']) is None
def test_Trying_to_get_an_ability_an_Actor_does_not_have_causes_an_assertion():
    bob = Actor.named('Bob')

    bob.can(SecondStubAbility())

    with pytest.raises(AssertionError):
        bob.ability(StubAbility)
def test_An_Ability_can_be_added_and_reterived_from_an_Actor():
    bob = Actor.named('Bob')

    bob.can(StubAbility())

    ability = bob.ability(StubAbility)

    assert ability is not None, "Ability not found"
def test_Multiple_Ability_objects_can_be_added_and_reterived_from_an_Actor():
    bob = Actor.named('Bob')

    bob.can(StubAbility())
    bob.can(SecondStubAbility())

    assert bob.ability(StubAbility) is not None, "Ability not found"
    assert bob.ability(SecondStubAbility) is not None, "Ability not found"
Exemplo n.º 13
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'
Exemplo n.º 14
0
def test_if_a_value_is_2_and_the_required_is_1_or_2_then_the_actions_are_run():
    user = Actor.named('user')
    action = record_if_run()

    user.state['not_set'].set(2)

    user.attempts_to(if_value_of('not_set').equals(2).then(action))

    assert action.triggered, "Action was not triggered"
Exemplo n.º 15
0
def test_if_a_value_is_set_then_the_actions_are_not_run():
    user = Actor.named('user')
    action = record_if_run()

    user.state['not_set'].set(1)

    user.attempts_to(if_value_of('not_set').is_None().then(action))

    assert not action.triggered, "Action was triggered"
Exemplo n.º 16
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_An_Actor_can_perform_Tasks():
    claire = Actor.named('Claire')

    task1 = StubTask()
    task2 = StubTask()

    claire.attempts_to(task1, task2)

    assert task1.called, "Task 1 not run"
    assert task2.called, "Task 2 not run"
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_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_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_Multiple_Ability_objects_are_cleaned_up_with_an_Actor_is_cleaned_up():
    bob = Actor.named('Bob')

    first_ability = StubAbility()
    second_ability = SecondStubAbility()
    bob.can(first_ability)
    bob.can(second_ability)

    bob.clean_up()

    assert first_ability.clean_up_run, 'Ability not cleaned up'
    assert second_ability.clean_up_run, 'Ability not cleaned up'
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'
Exemplo n.º 24
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'
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'
Exemplo n.º 27
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
Exemplo n.º 28
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'
Exemplo n.º 29
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\')"'