Beispiel #1
0
    def test_can_be_instantiated(self):
        """Target can be instantiated"""
        t1 = Target.the("test")
        t2 = Target.the("test").located_by("test")

        self.assertIsInstance(t1, Target)
        self.assertIsInstance(t2, Target)
Beispiel #2
0
    def test_get_locator(self):
        """Target returns the correct locator tuple"""
        css_selector = "#id"
        xpath_locator = '//div[@id="id"]'
        t1 = Target.the("css element").located_by(css_selector)
        t2 = Target.the("xpath element").located_by(xpath_locator)

        self.assertEqual(t1.get_locator(), (By.CSS_SELECTOR, css_selector))
        self.assertEqual(t2.get_locator(), (By.XPATH, xpath_locator))
Beispiel #3
0
def test_is_not_negates(Tester):
    """IsNot negates the resolution it is passed"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = [1, 2, 3]

    Tester.should_see_the((List.of(fake_target), IsNot(Empty())))
Beispiel #4
0
def test_is_empty_nonempty_list(Tester):
    """IsEmpty complains about a not-empty list"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = ["not", "empty"]

    with pytest.raises(AssertionError):
        Tester.should_see_the((List.of(fake_target), IsEmpty()))
Beispiel #5
0
def test_visible_element(Tester):
    """IsVisible matches a visible element"""
    fake_target = Target.the("fake").located_by("//html")
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_element = mock.Mock()
    mocked_element.is_displayed.return_value = True
    mocked_btw.to_find.return_value = mocked_element

    Tester.should_see_the((Element(fake_target), IsVisible()))
Beispiel #6
0
    def test_switch_to_frame(self, Tester):
        """SwitchTo calls .to_switch_to()"""
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(SwitchTo.the(fake_target))

        mocked_btw = Tester.ability_to(BrowseTheWeb)
        mocked_btw.to_switch_to.assert_called_once_with(fake_target)
Beispiel #7
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")))
Beispiel #8
0
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()
Beispiel #9
0
def test_ask_for_list(Tester):
    """List uses .to_find_all() and returns a list"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_find_all.return_value = []

    Tester.should_see_the((List.of(fake_target), IsEmpty()))

    mocked_btw.to_find_all.assert_called_once_with(fake_target)
Beispiel #10
0
def test_ask_for_element(Tester):
    """Element asks for, duh, an element"""
    fake_target = Target.the("fake").located_by("//html")
    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_element = mock.Mock()
    mocked_btw.to_find.return_value = mocked_element

    Tester.should_see_the((Element(fake_target), IsNot(EqualTo(None))))

    mocked_btw.to_find.assert_called_once_with(fake_target)
Beispiel #11
0
def test_wait(Tester):
    """Wait calls .to_wait_for()"""
    fake_xpath = "//xpath"
    fake_target = Target.the("fake").located_by(fake_xpath)

    Tester.attempts_to(Wait.for_the(fake_target).to_appear())

    mocked_btw = Tester.ability_to(BrowseTheWeb)
    mocked_btw.to_wait_for.assert_called_once_with(
        fake_target, timeout=20, cond=EC.visibility_of_element_located)
Beispiel #12
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)
Beispiel #14
0
    def test_basic_action(self, Tester):
        """Enter finds its target and calls .send_keys()"""
        text = "test"
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(Enter.the_text(text).into_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.send_keys.assert_called_once_with(text)
Beispiel #15
0
    def test_basic_action(self, mocked_selenium_select, Tester):
        """SelectByText finds its target and calls .select_by_visible_text()"""
        text = "test"
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(Select.the_option_named(text).from_the(fake_target))

        mocked_btw = Tester.ability_to(BrowseTheWeb)
        mocked_btw.to_find.assert_called_once_with(fake_target)
        mocked_select = mocked_selenium_select.return_value
        mocked_select.select_by_visible_text.assert_called_once_with(text)
Beispiel #16
0
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")))
Beispiel #17
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)
Beispiel #18
0
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)
Beispiel #19
0
    def test_basic_action(self, mocked_selenium_select, Tester):
        """SelectByIndex finds its target and calls .select_by_index()"""
        index = 1
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(
            Select.the_option_at_index(index).from_the(fake_target))

        mocked_btw = Tester.ability_to(BrowseTheWeb)
        mocked_btw.to_find.assert_called_once_with(fake_target)
        mocked_selenium_select.return_value.select_by_index.assert_called_once_with(
            str(index))
Beispiel #20
0
    def test_description_is_set_by_method(self):
        """Description is built by what is included"""
        element_name = "test_element"
        coords = (1, 2)
        target = Target.the(element_name).located_by("*")
        mm1 = MoveMouse.to_the(target)
        mm2 = MoveMouse.by_offset(*coords)
        mm3 = MoveMouse.to_the(target).with_offset(*coords)

        assert element_name in mm1.description
        assert str(coords) in mm2.description
        assert element_name in mm3.description and str(
            coords) in mm3.description
Beispiel #21
0
    def test_enter_2FA_token(self, Tester):
        """Enter2FAToken calls .to_get_token(), .to_find(), and .send_keys()"""
        text = "test"
        mocked_2fa = Tester.ability_to(AuthenticateWith2FA)
        mocked_2fa.to_get_token.return_value = text
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(Enter2FAToken.into_the(fake_target))
        mocked_2fa.to_get_token.assert_called_once()
        mocked_btw = Tester.ability_to(BrowseTheWeb)
        mocked_btw.to_find.assert_called_once_with(fake_target)
        mocked_btw.to_find.return_value.send_keys.assert_called_once_with(text)
Beispiel #22
0
    def test_following_keys(self, Tester):
        """Enter hits the following keys"""
        text = "test"
        fake_xpath = "//xpath"
        fake_target = Target.the("fake").located_by(fake_xpath)

        Tester.attempts_to(
            Enter.the_text(text).into_the(fake_target).then_hit(Keys.ENTER))

        mocked_btw = Tester.ability_to(BrowseTheWeb)
        mocked_btw.to_find.assert_called_once_with(fake_target)
        mocked_element = mocked_btw.to_find.return_value
        assert mocked_element.send_keys.call_count == 2
        called_args, _ = mocked_element.send_keys.call_args_list[1]
        assert Keys.ENTER in called_args
Beispiel #23
0
"""
Locators and URL for the Dropdown page.
"""


from screenpy import Target

URL = "http://the-internet.herokuapp.com/dropdown"

THE_DROPDOWN = Target.the("dropdown menu").located_by("#dropdown")
Beispiel #24
0
"""
Locators for elements in the GitHub header bar.
"""

from screenpy import Target

SEARCH_INPUT = Target.the("GitHub header's search input").located_by(
    "input.header-search-input")
Beispiel #25
0
from screenpy import Target


URL = "http://the-internet.herokuapp.com/"

CHECKBOXES_LINK = Target.the("checkboxes link").located_by("a[href*=checkboxes]")
DROPDOWN_LINK = Target.the("dropdown link").located_by("a[href*=dropdown]")
ADD_REMOVE_ELEMENTS_LINK = Target.the("add and remove elements link").located_by(
    "a[href*=add_remove_elements]"
)
from screenpy import Target


ADD_BUTTON = Target.the("add element button").located_by("button[onclick^=addElement]")
ADDED_ELEMENTS = Target.the("added elements").located_by("button.added-manually")
Beispiel #27
0
"""
Locators for the GitHub search results page.
"""

from screenpy import Target

RESULTS_MESSAGE = Target.the("search results message").located_by(
    "div.codesearch-results > div > div > h3"  # ew
)
SEARCH_RESULTS = Target.the("search results items").located_by(
    "li.repo-list-item")
Beispiel #28
0
"""
Locators and URL for the Iframe page.
"""

from screenpy import Target

URL = "http://the-internet.herokuapp.com/iframe"

WYSIWYG_IFRAME = Target.the("WYSIWYG iframe").located_by("#mce_0_ifr")
CONTENT_BOX = Target.the("content box").located_by("p")
Beispiel #29
0
from screenpy import Target

url = "https://screenpy-docs.readthedocs.io/en/latest/"

WELCOME_MESSAGE = Target.the("welcome message").located_by(
    "#welcome-to-screenpy-s-documentation>h1")
Beispiel #30
0
"""
Locators and URL for the Drag and Drop page.
"""

from screenpy import Target

URL = "http://the-internet.herokuapp.com/drag_and_drop"

FIRST_DRAGGABLE_BOX = Target.the("first draggable box").located_by("#column-a")
SECOND_DRAGGABLE_BOX = Target.the("second draggable box").located_by(
    "#column-b")