wabot/tests/unit/test_pacing.py

47 lines
1.5 KiB
Python

from wabot.pacing import HumanPacing, NoPacing
class TestNoPacing:
def test_delay_is_zero_for_every_action(self):
p = NoPacing()
assert p.delay("text") == 0.0
assert p.delay("select") == 0.0
assert p.delay("unknown-action") == 0.0
def test_click_offset_is_none(self):
assert NoPacing().click_offset(200, 50) is None
class TestHumanPacing:
def test_delays_fall_in_documented_ranges(self):
p = HumanPacing()
for _ in range(50):
assert 3.0 <= p.delay("text") <= 5.0
assert 6.0 <= p.delay("select") <= 11.0
assert 2.0 <= p.delay("checkbox") <= 3.0
assert 3.0 <= p.delay("navigate") <= 6.0
def test_unknown_action_has_no_delay(self):
assert HumanPacing().delay("unknown-action") == 0.0
def test_delays_actually_vary(self):
assert len({HumanPacing().delay("text") for _ in range(50)}) > 1
def test_click_offset_stays_inside_element(self):
p = HumanPacing()
offsets = []
for _ in range(200):
offset = p.click_offset(100, 40)
assert offset is not None
offsets.append(offset)
x, y = offset
# offsets are measured from the element CENTER (selenium 4)
assert -49 <= x <= 49
assert -19 <= y <= 19
assert any(o != (0, 0) for o in offsets)
def test_tiny_elements_get_plain_click(self):
p = HumanPacing()
assert p.click_offset(4, 40) is None
assert p.click_offset(40, 4) is None