-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_actions.py
More file actions
51 lines (38 loc) · 1.45 KB
/
test_actions.py
File metadata and controls
51 lines (38 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Tests for actions (click, type, press)
"""
import pytest
from sentience import SentienceBrowser, snapshot, find, click, type_text, press
def test_click():
"""Test click action"""
with SentienceBrowser() as browser:
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
snap = snapshot(browser)
link = find(snap, "role=link")
if link:
result = click(browser, link.id)
assert result.success is True
assert result.duration_ms > 0
assert result.outcome in ["navigated", "dom_updated"]
def test_type_text():
"""Test type action"""
with SentienceBrowser() as browser:
# Use a page with a text input
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
# Find textbox if available
snap = snapshot(browser)
textbox = find(snap, "role=textbox")
if textbox:
result = type_text(browser, textbox.id, "hello")
assert result.success is True
assert result.duration_ms > 0
def test_press():
"""Test press action"""
with SentienceBrowser() as browser:
browser.page.goto("https://example.com")
browser.page.wait_for_load_state("networkidle")
result = press(browser, "Enter")
assert result.success is True
assert result.duration_ms > 0