Exemplo n.º 1
0
    def test_exception_raised_if_element_not_found(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")
        retry_with_timeout.side_effect = ElementNotFoundError()
        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mocker.Mock()

        with pytest.raises(ElementNotFoundError):
            element.wait_until_visible()
Exemplo n.º 2
0
    def test_custom_timeout_can_be_set(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mocker.Mock()

        element.click(timeout_seconds=50)

        retry_with_timeout.assert_called_with(mocker.ANY, 50, log=mocker.ANY)
Exemplo n.º 3
0
    def test_default_timeout_is_30(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mocker.Mock()

        element.click()

        retry_with_timeout.assert_called_with(mocker.ANY, 30, log=mocker.ANY)
Exemplo n.º 4
0
    def test_screenshot_saved(self, mocker, region, capsys):
        screenshot = mock.Mock()
        Locater = mocker.patch("clickshot.element.Locater")
        Locater().last_screenshot = screenshot
        screenshot.save.return_value = "screenshots/my_region-my-element.png"

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot()

        screenshot.save.assert_called_with(Path("screenshots/my_region-my_element.png"))

        stdout = capsys.readouterr().out
        assert_that(
            stdout, contains_string("Expected Image: images/my_region-my_element.png\n")
        )
        assert_that(
            stdout,
            contains_string("Screenshot: screenshots/my_region-my-element.png\n"),
        )
Exemplo n.º 5
0
    def test_screenshot_saved_if_image_file_not_found(self, mocker, region):
        mocker.patch("clickshot.element.Mouse")
        retry_with_timeout = mocker.patch("clickshot.element.retry_with_timeout")
        retry_with_timeout.side_effect = FileNotFoundError()
        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mocker.Mock()

        with pytest.raises(FileNotFoundError):
            element.wait_until_visible()

        element.save_last_screenshot.assert_called()
Exemplo n.º 6
0
    def test_element_is_clicked(self, mocker, region):
        Mouse = mocker.patch("clickshot.element.Mouse")
        Locater = mocker.patch("clickshot.element.Locater")
        Locater().locate.return_value = Rect(left=0, top=15, width=10, height=20)

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mocker.Mock()

        element.click()

        assert_that(Mouse().position, is_((5, 25)))
        Mouse().click.assert_called_with(button=Button.left, count=1)
Exemplo n.º 7
0
    def test_failsafe_aborts_click_attempt(self, mocker, region):
        Mouse = mocker.patch("clickshot.element.Mouse")
        position_mock = mocker.PropertyMock(return_value=(0, 0))
        type(Mouse()).position = position_mock

        Locater = mocker.patch("clickshot.element.Locater")
        Locater().locate.side_effect = ElementNotFoundError()

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot = mock.Mock()

        with pytest.raises(ElementNotFoundError):
            with pytest.warns(UserWarning):
                element.click()
Exemplo n.º 8
0
    def test_screenshot_not_saved_if_it_is_none(self, mocker, region):
        Locater = mocker.patch("clickshot.element.Locater")
        Locater().last_screenshot = None

        element = Element(ElementConfig(name="my_element"), region)
        element.save_last_screenshot()