-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathtest_element.py
105 lines (76 loc) · 2.32 KB
/
test_element.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# -*- coding: utf-8 -*-
import pytest
from hmdriver2.driver import Driver
from hmdriver2.proto import ElementInfo, ComponentData
@pytest.fixture
def d():
d = Driver("FMR0223C13000649")
d.force_start_app("com.samples.test.uitest", "EntryAbility")
yield d
del d
def test_by_type(d):
d(type="Button")
def test_by_combine(d):
assert d(type="Button", text="showToast").exists()
assert not d(type="Button", text="showToast1").exists()
assert d(type="Button", index=3).exists()
assert not d(type="Button", index=5).exists()
def test_isBefore_isAfter(d):
assert d(text="showToast", isAfter=True).text == "showDialog"
# assert d(id="drag", isBefore=True).text == "showDialog"
def test_count(d):
assert d(type="Button").count == 5
assert len(d(type="Button")) == 5
def test_id(d):
assert d(text="showToast").text == "showToast"
def test_info(d):
info: ElementInfo = d(text="showToast").info
mock = {
"id": "",
"key": "",
"type": "Button",
"text": "showToast",
"description": "",
"isSelected": False,
"isChecked": False,
"isEnabled": True,
"isFocused": False,
"isCheckable": False,
"isClickable": True,
"isLongClickable": False,
"isScrollable": False,
"bounds": {
"left": 539,
"top": 1282,
"right": 832,
"bottom": 1412
},
"boundsCenter": {
"x": 685,
"y": 1347
}
}
assert info.to_dict() == mock
def test_click(d):
d(text="showToast1").click_if_exists()
d(text="showToast").click()
d(type="Button", index=3).click()
d.click(0.5, 0.2)
def test_double_click(d):
d(text="unit_jsunit").double_click()
assert d(id="swiper").exists()
d.go_back()
def test_long_click(d):
d(text="showToast").long_click()
def test_drag_to(d):
d(id="drag").click()
assert d(type="Text", index=6).text == "two"
component: ComponentData = d(type="ListItem", index=1).find_component()
d(type="ListItem").drag_to(component)
assert d(type="Text", index=5).text == "two"
def test_input(d):
d(text="showToast").input_text("abc")
d(text="showToast").clear_text()
def test_pinch(d):
d(text="showToast").pinch_in()
d(text="showToast").pinch_out()