Exemple #1
0
    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")))
Exemple #2
0
def test_browser_url(Tester):
    """BrowserURL asks for the browser's current_url"""
    fake_url = "http://www.screenpy.com"
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.browser.current_url = fake_url

    Tester.should_see_the((BrowserURL(), ReadsExactly(fake_url)))
Exemple #3
0
def test_browser_title(Tester):
    """BrowserTitle asks for the browser's title"""
    fake_title = "ScreenPy's Totally Awesome Webpage!"
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.browser.title = fake_title

    Tester.should_see_the((BrowserTitle(), ReadsExactly(fake_title)))
Exemple #4
0
def test_search_for_screenpy(Perry: AnActor) -> None:
    """GitHub search finds the screenpy repository."""
    given(Perry).was_able_to(Open.their_browser_on(URL))
    when(Perry).attempts_to(SearchGitHub.for_text("perrygoy/screenpy"))
    then(Perry).should_see_that(
        (SearchResultsMessage(), DoesNot(ContainTheText("couldn’t"))),
        (SearchResultsMessage(), ReadsExactly("1 repository result")),
        (NumberOfSearchResults(), IsEqualTo(1)),
    )
Exemple #5
0
    def test_select_by_value(self):
        """Can select an option from a dropdown by value."""
        Perry = self.actor

        given(Perry).was_able_to(Open.their_browser_on(URL))
        when(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")))
Exemple #6
0
def test_reads_exactly_mismatched_string(mocked_selenium_select, Tester):
    """ReadsExactly complains if the strings do not match exactly"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    mocked_selenium_select.return_value.first_selected_option.text = "sentences"

    with pytest.raises(AssertionError):
        Tester.should_see_the(
            (Selected.option_from(fake_target), ReadsExactly("sandwiches")))
Exemple #7
0
    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(SwitchTo.the(WYSIWYG_IFRAME))
        then(Perry).should_see_the(
            (Text.of_the(CONTENT_BOX), ReadsExactly("Your content goes here."))
        )
Exemple #8
0
    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"))
        )
Exemple #9
0
    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}"))
        )
Exemple #10
0
def test_ask_for_selected(mocked_selenium_select, Tester):
    """Selected finds its target and gets the first_selected_option"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    return_value = "test"
    mocked_selenium_select.return_value.first_selected_option.text = return_value

    Tester.should_see_the(
        (Selected.option_from(fake_target), ReadsExactly(return_value)))

    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find.assert_called_once_with(fake_target)
Exemple #11
0
    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")),
        )
Exemple #12
0
    def test_drag_and_drop(self):
        """
        User is able to drag and drop.

        Expected to fail because there is currently an issue in ActionChains.
        """
        Perry = self.actor

        given(Perry).was_able_to(Open.their_browser_on(URL))
        when(Perry).attempts_to(
            Wait.for_the(FIRST_DRAGGABLE_BOX).to_be_clickable(),
            Chain(
                HoldDown.left_mouse_button().on_the(FIRST_DRAGGABLE_BOX),
                MoveMouse.to_the(SECOND_DRAGGABLE_BOX),
                Release.left_mouse_button(),
            ),
        )
        then(Perry).should_see_the(
            (Text.of_the(FIRST_DRAGGABLE_BOX), ReadsExactly("B")))
Exemple #13
0
    def test_the_test(self):
        """ReadsExactly tests what it says on the tin"""
        re_ = ReadsExactly("Blah")

        self.assertTrue(re_.matches("Blah"))
        self.assertFalse(re_.matches("blah"))
Exemple #14
0
    def test_can_be_instantiated(self):
        """ReadsExactly can be instantiated"""
        re_ = ReadsExactly("Blah")

        self.assertIsInstance(re_, ReadsExactly)
Exemple #15
0
    def test_the_test(self):
        """ReadsExactly tests what it says on the tin"""
        re_ = ReadsExactly("Blah")

        assert re_.matches("Blah")
        assert not re_.matches("blah")