55 lines
1.3 KiB
Python
55 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from unittest.mock import MagicMock
|
|
|
|
import pytest
|
|
|
|
|
|
def test_pause_respects_range(monkeypatch):
|
|
sleeps = []
|
|
|
|
def _rec(s):
|
|
sleeps.append(s)
|
|
|
|
monkeypatch.setattr("service.rpa_helpers.human.time.sleep", _rec)
|
|
from service.rpa_helpers.human import pause
|
|
|
|
for _ in range(10):
|
|
pause(50, 100)
|
|
assert len(sleeps) == 10
|
|
for s in sleeps:
|
|
assert 0.04 <= s <= 0.12
|
|
|
|
|
|
def test_human_type_calls_locator_methods():
|
|
from service.rpa_helpers.human import human_type
|
|
|
|
loc = MagicMock()
|
|
human_type(loc, "hello")
|
|
loc.scroll_into_view_if_needed.assert_called()
|
|
loc.click.assert_called()
|
|
loc.type.assert_called_once()
|
|
args, kwargs = loc.type.call_args
|
|
assert args[0] == "hello"
|
|
assert "delay" in kwargs
|
|
assert 50 <= kwargs["delay"] <= 200
|
|
|
|
|
|
def test_human_click_basic():
|
|
from service.rpa_helpers.human import human_click
|
|
|
|
loc = MagicMock()
|
|
human_click(loc)
|
|
loc.scroll_into_view_if_needed.assert_called()
|
|
loc.click.assert_called()
|
|
|
|
|
|
def test_human_select_basic():
|
|
from service.rpa_helpers.human import human_select
|
|
|
|
loc = MagicMock()
|
|
human_select(loc, "opt1")
|
|
loc.scroll_into_view_if_needed.assert_called()
|
|
loc.click.assert_called()
|
|
assert loc.select_option.call_count >= 1
|
|
|