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 answered_by(self, the_actor: Actor) -> float:
        """
        Asks the actor to count the number of search results.

        Args:
            the_actor: the actor who will answer the question.

        Returns:
            float
        """
        return Number.of(SEARCH_RESULTS).answered_by(the_actor)
Пример #3
0
def test_is_equal_to_unequal_value(Tester):
    """IsEqual complains if the values are not equal"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    return_value = [1, 2, 3]
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = return_value

    with pytest.raises(AssertionError):
        Tester.should_see_the(
            (Number.of(fake_target), IsEqualTo(len(return_value) + 3)))
def test_ask_for_number(Tester):
    """Number uses .to_find_all() and returns an int"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    return_value = [1, 2, 3]
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = return_value

    Tester.should_see_the((Number.of(fake_target), IsEqualTo(len(return_value))))

    mocked_btw.to_find_all.assert_called_once_with(fake_target)
Пример #5
0
    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)))
Пример #6
0
    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)))
    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)))
Пример #8
0
    def test_can_be_instantiated(self):
        """Number can be instantiated"""
        n1 = Number.of(None)

        assert isinstance(n1, Number)
 def answered_by(self, the_actor):
     return Number.of(SEARCH_RESULTS).answered_by(the_actor)