def test_search_for_nonexistent_repo(Perry: AnActor) -> None: """GitHub search fails to find a nonexistant repository.""" nonexistant_repository = "perrygoy/i-never-made-this-repo" given(Perry).was_able_to(Open.their_browser_on(URL)) when(Perry).attempts_to(SearchGitHub.for_text(nonexistant_repository)) then(Perry).should_see_that( (SearchResultsMessage(), ContainsTheText("We couldn’t find any")), (SearchResultsMessage(), ContainsTheText(nonexistant_repository)), (NumberOfSearchResults(), IsEqualTo(0)), )
def test_open_homepage(self): "Tests that the user can visit the homepage. Extend me!" Actor = self.actor given(Actor).was_able_to(Start.on_the_homepage()) # ... fill in your test steps here! then(Actor).should_see_the( (WelcomeMessage.text(), ContainsTheText("Welcome to ScreenPy")))
def test_ask_for_text_of_the_alert(Tester): """TextOfTheAlert gets the alert's text""" text = "spam" mocked_btw = Tester.ability_to(BrowseTheWeb) mocked_alert = mock.Mock() mocked_alert.text = f"{text} and eggs" mocked_btw.browser.switch_to.alert = mocked_alert Tester.should_see_the((TextOfTheAlert(), ContainsTheText(text)))
def test_contains_the_text_no_it_doesnt(Tester): """ContainsTheText complains if the substring does not exist""" fake_xpath = "//xpath" fake_target = Target.the("fake").located_by(fake_xpath) mocked_btw = Tester.ability_to(BrowseTheWeb) mocked_element = mock.Mock() mocked_element.text = "spam and eggs" mocked_btw.to_find.return_value = mocked_element with pytest.raises(AssertionError): Tester.should_see_the( (Text.of_the(fake_target), ContainsTheText("baked beans")))
def test_ask_for_text(Tester): """Text finds its target and gets its text""" text = "spam" fake_xpath = "//xpath" fake_target = Target.the("fake").located_by(fake_xpath) mocked_btw = Tester.ability_to(BrowseTheWeb) mocked_element = mock.Mock() mocked_element.text = f"{text} and eggs" mocked_btw.to_find.return_value = mocked_element Tester.should_see_the((Text.of_the(fake_target), ContainsTheText(text))) mocked_btw.to_find.assert_called_once_with(fake_target)
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_the_test(self): """ContainsTheText tests what it says on the tin""" ctt = ContainsTheText("hello") self.assertTrue(ctt.matches("hello world!")) self.assertFalse(ctt.matches("goodbye universe."))
def test_can_be_instantiated(self): """ContainsTheText can be instantiated""" ctt = ContainsTheText("hello") self.assertIsInstance(ctt, ContainsTheText)