forked from macaca-sample/sample-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmacaca-android-sample.test.py
More file actions
180 lines (134 loc) · 3.93 KB
/
macaca-android-sample.test.py
File metadata and controls
180 lines (134 loc) · 3.93 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
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#coding:utf-8
import unittest
import os
import time
from macaca import WebDriver
from macaca import Keys
from retrying import retry
desired_caps = {
'platformName': 'android',
'app': 'https://npmcdn.com/android-app-bootstrap@latest/android_app_bootstrap/build/outputs/apk/android_app_bootstrap-debug.apk',
}
server_url = {
'hostname': 'localhost',
'port': 3456
}
def switch_to_webview(driver):
contexts = driver.contexts
driver.context = contexts[-1]
return driver
def switch_to_native(driver):
contexts = driver.contexts
driver.context = contexts[0]
return driver
class MacacaTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.driver = WebDriver(desired_caps, server_url)
cls.initDriver()
@classmethod
def tearDownClass(cls):
cls.driver.quit()
@classmethod
@retry
def initDriver(cls):
print("Retry connecting server...")
cls.driver.init()
def test_01_login(self):
el = self.driver \
.elements_by_class_name('android.widget.EditText')[0] \
.send_keys('中文+Test+12345678') \
el = self.driver \
.elements_by_class_name('android.widget.EditText')[1] \
.send_keys('111111')
time.sleep(1)
# self.driver.keys(Keys.ENTER.value + Keys.ESCAPE.value)
self.driver \
.element_by_name('Login') \
.click()
def test_02_scroll_tableview(self):
self.driver \
.wait_for_element_by_name('HOME') \
.click()
self.driver \
.wait_for_element_by_name('list') \
.click()
def test_03_gesture(self):
time.sleep(5)
self.driver \
.wait_for_element_by_name('Alert') \
.click()
time.sleep(5)
self.driver \
.accept_alert()
time.sleep(3)
self.driver \
.back()
time.sleep(3)
self.driver \
.wait_for_element_by_name('Gesture') \
.click()
time.sleep(3)
self.driver \
.touch('tap', {
'x': 100,
'y': 100
})
time.sleep(5)
self.driver \
.touch('doubleTap', {
'x': 100,
'y': 100
})
time.sleep(5)
self.driver \
.touch('press', {
'x': 100,
'y': 100,
'steps': 100
})
time.sleep(5)
self.driver \
.touch('drag', {
'fromX': 100,
'fromY': 100,
'toX': 100,
'toY': 600,
'steps': 100
})
time.sleep(5)
self.driver.back()
time.sleep(5)
self.driver.back()
def test_04_webview(self):
self.driver \
.wait_for_element_by_name('Webview') \
.click()
time.sleep(5)
self.driver.save_screenshot('./webView.png') # save screen shot
switch_to_webview(self.driver) \
.wait_for_element_by_id('pushView') \
.click()
switch_to_webview(self.driver) \
.wait_for_element_by_id('popView') \
.click()
def test_05_web(self):
switch_to_native(self.driver) \
.wait_for_element_by_name('Baidu') \
.click()
time.sleep(5)
self.driver.save_screenshot("./baidu.png")
switch_to_webview(self.driver) \
.wait_for_element_by_id('index-kw') \
.send_keys('macaca')
self.driver \
.wait_for_element_by_id('index-bn') \
.click()
def test_06_logout(self):
switch_to_native(self.driver) \
.wait_for_element_by_name('PERSONAL') \
.click()
self.driver.wait_for_element_by_name('Logout') \
.click()
if __name__ == '__main__':
unittest.main()