def test_can_be_instantiated(self): """Click can be instantiated""" c1 = Click.on(None) c2 = Click.on_the(None) assert isinstance(c1, Click) assert isinstance(c2, Click)
def test_can_be_instantiated(self): """Click can be instantiated""" c1 = Click.on(None) c2 = Click.on_the(None) c3 = Click.on_the(None).then_wait_for(None) self.assertIsInstance(c1, Click) self.assertIsInstance(c2, Click) self.assertIsInstance(c3, Click)
def test_add_one_element(self): Perry = self.actor given(Perry).was_able_to(Start.on_the_homepage()) when(Perry).attempts_to( Click.on_the(ADD_REMOVE_ELEMENTS_LINK).then_wait_for(ADD_BUTTON) ) and_(Perry).attempts_to(Click.on_the(ADD_BUTTON).then_wait_for(ADDED_ELEMENTS)) then(Perry).should_see_the((Number.of(ADDED_ELEMENTS), IsEqualTo(1)))
def test_remove_element(self): """User is able to remove an element that was added.""" Perry = self.actor given(Perry).was_able_to( Open.their_browser_on(URL), Click.on_the(ADD_BUTTON), Wait.for_the(ADDED_ELEMENTS), ) when(Perry).attempts_to(Click.on_the(ADDED_ELEMENTS)) then(Perry).should_see_the((Number.of(ADDED_ELEMENTS), IsEqualTo(0)))
def test_add_many_elements(self): Perry = self.actor repeat = random.choice(range(2, 10)) given(Perry).was_able_to(Start.on_the_homepage()) when(Perry).attempts_to( Click.on_the(ADD_REMOVE_ELEMENTS_LINK).then_wait_for(ADD_BUTTON) ) and_(Perry).attempts_to( *( Click.on_the(ADD_BUTTON).then_wait_for(ADDED_ELEMENTS) for each_time in range(repeat) ) ) then(Perry).should_see_the((Number.of(ADDED_ELEMENTS), IsEqualTo(repeat)))
def test_inspect_alert(self): """User can read the text of the alert.""" Perry = self.actor given(Perry).was_able_to(Open.their_browser_on(URL)) when(Perry).attempts_to(Click.on_the(JS_ALERT_BUTTON)) then(Perry).should_see_the((TextOfTheAlert(), ReadsExactly("I am a JS Alert")))
def test_add_one_element(self): """User is able to add one element.""" Perry = self.actor given(Perry).was_able_to(Open.their_browser_on(URL)) when(Perry).attempts_to(Click.on_the(ADD_BUTTON), Wait.for_the(ADDED_ELEMENTS)) then(Perry).should_see_the((Element(ADDED_ELEMENTS), IsVisible()))
def test_can_be_chained(self, MockedActionChains, Tester): """Click chained calls .click()""" mock_target = mock.Mock() mock_element = "element" mock_target.found_by.return_value = mock_element Tester.attempts_to(Chain(Click.on_the(mock_target))) MockedActionChains().click.assert_called_once_with(mock_element)
def test_click(Tester): """Click finds its target and calls .click()""" fake_xpath = "//xpath" fake_target = Target.the("fake").located_by(fake_xpath) Tester.attempts_to(Click.on_the(fake_target)) mocked_btw = Tester.ability_to(BrowseTheWeb) mocked_btw.to_find.assert_called_once_with(fake_target) mocked_btw.to_find.return_value.click.assert_called_once()
def test_select_by_value(self): Perry = self.actor given(Perry).was_able_to(Start.on_the_homepage()) when(Perry).attempts_to( Click.on_the(DROPDOWN_LINK).then_wait_for(THE_DROPDOWN)) and_(Perry).attempts_to( Select.the_option_with_value(2).from_(THE_DROPDOWN)) then(Perry).should_see_the( (Selected.option_from(THE_DROPDOWN), ReadsExactly("Option 2")))
def test_dismiss_alert(self): """User can dismiss an alert.""" Perry = self.actor given(Perry).was_able_to( Open.their_browser_on(URL), Click.on_the(JS_CONFIRM_BUTTON) ) when(Perry).attempts_to(DismissAlert()) then(Perry).should_see_the( (Text.of_the(RESULT_MESSAGE), ReadsExactly("You clicked: Cancel")) )
def test_respond_to_prompt(self): """User can enter text into a prompt.""" Perry = self.actor test_text = "Hello! I am responding to this prompt." given(Perry).was_able_to( Open.their_browser_on(URL), Click.on_the(JS_PROMPT_BUTTON) ) when(Perry).attempts_to(RespondToPrompt.with_(test_text)) then(Perry).should_see_the( (Text.of_the(RESULT_MESSAGE), ReadsExactly(f"You entered: {test_text}")) )
def test_switch_to_iframe(self): """User is able to switch to an iframe.""" Perry = self.actor given(Perry).was_able_to(Open.their_browser_on(URL)) when(Perry).attempts_to( Click.on_the(CLICK_HERE_LINK), Pause.for_(1).second_because("Selenium needs to catch up"), SwitchToTab.on_top(), ) then(Perry).should_see_the( (BrowserURL(), ContainsTheText("windows/new")), (Text.of_the(HEADER_MESSAGE), ReadsExactly("New Window")), )
def test_add_many_elements(self): """ User is able to add many elements. This test chooses a random number of elements to add, just to show off how to do that, if you want to do something like that. """ Perry = self.actor number_of_times = random.choice(range(2, 10)) given(Perry).was_able_to(Open.their_browser_on(URL)) when(Perry).attempts_to(*(Click.on_the(ADD_BUTTON) for each_time in range(number_of_times))) then(Perry).should_see_the( (Number.of(ADDED_ELEMENTS), IsEqualTo(number_of_times)))