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_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_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"
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'
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"
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"
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_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_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'
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_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'
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'
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\')"'
def test_An_actors_name_can_be_retrieved(): frank = Actor.named('Frank') assert frank.name == 'Frank'
def test_An_Actor_will_assert_if_any_of_the_checked_conditions_are_all_False(): david = Actor.named('David') with pytest.raises(AssertionError): david.should(see_that(StubQuestion('1'), equals('1')), see_that(StubQuestion('text'), equals('2')))
def test_An_Actor_can_check_conditions_and_does_not_assert_if_the_conditions_are_all_True( ): david = Actor.named('David') david.should(see_that(StubQuestion('1'), equals('1')), see_that(StubQuestion('2'), equals('2')))
def test_An_Actors_state_can_be_updated_with_a_using_task(): frank = Actor.named('Frank') frank.attempts_to(using(StubTaskWithResult(2)).as_('Bob')) assert value_of(frank.state['Bob']) == 2
def test_A_using_task_without_an_id_asserts(): frank = Actor.named('Frank') with pytest.raises(AssertionError): frank.attempts_to(using(StubTaskWithResult(2)))
from screenplay import Actor, Ability, Action, Question, Task from screenplay.matcher import Matcher from screenplay.task_or_action import TaskOrAction actor = Actor.named('unused') Ability().clean_up() Action().perform_as(actor) Question().answered_by(actor) Task().perform_as(actor) Matcher().matches(2) message = Matcher().fail_message TaskOrAction().perform_as(actor)