Ejemplo n.º 1
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)
Ejemplo 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)
Ejemplo n.º 3
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 = mock.Mock()

        with pytest.raises(ElementNotFoundError):
            element.click()
Ejemplo n.º 4
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 = mock.Mock()

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

        element.save_last_screenshot.assert_called()
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
    def test_mouse_is_moved_away_from_failsafe(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.return_value = Rect(left=0, top=15, width=10, height=20)

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

        assert_that(position_mock.mock_calls, has_item(mock.call((10, 10))))
Ejemplo n.º 7
0
    def test_click_parameters_are_applied(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", click_offset=(2, 3)), region,
        )
        element.click(button=Button.right, count=2)

        assert_that(Mouse().position, is_((7, 28)))
        Mouse().click.assert_called_with(button=Button.right, count=2)
Ejemplo n.º 8
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()