forked from openatx/facebook-wda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfull_example.py
More file actions
106 lines (80 loc) · 2.76 KB
/
full_example.py
File metadata and controls
106 lines (80 loc) · 2.76 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
# coding: utf-8
#
# 网易云音乐测试示例
#
import os
import time
import wda
import requests
from logzero import logger
bundle_id = 'com.apple.Preferences'
def test_preferences(c: wda.Client):
print("Status:", c.status())
print("Info:", c.info)
print("BatteryInfo", c.battery_info())
print("AppCurrent:", c.app_current())
# page_source = c.source()
# assert "</XCUIElementTypeApplication>" in page_source
app = c.session(bundle_id)
selector = app(label="蜂窝网络")
el = selector.get()
el.click()
print("Element bounds:", el.bounds)
logger.info("Take screenshot: %s", app.screenshot())
app.swipe_right()
app.swipe_up()
app(label="电池").scroll()
app(label="电池").click()
def test_open_safari(c: wda.Client):
""" session操作 """
app = c.session("com.apple.mobilesafari")
app.deactivate(3) # 后台3s
app.close() # 关闭
def test_send_keys_callback(c: wda.Client):
def _handle_alert_before_send_keys(client: wda.Client, urlpath: str):
if not urlpath.endswith("/wda/keys"):
return
if client.alert.exists:
client.alert.accept()
print("callback called")
c.register_callback(wda.Callback.HTTP_REQUEST_BEFORE, _handle_alert_before_send_keys)
c.send_keys("hello callback")
def test_error_callback(c: wda.Client):
def err_handler(client: wda.Client, err):
if isinstance(err, wda.WDARequestError):
print("ERROR:", err)
return wda.Callback.RET_ABORT # 直接退出
return wda.Callback.RET_CONTINUE # 忽略错误继续执行
return wda.Callback.RET_RETRY # 重试一下
c.register_callback(wda.Callback.ERROR, err_handler)
c.send_keys("hello callback")
def test_elememt_operation(c: wda.Client):
c(label="DisplayAlert").exists
el = c(label="DisplayAlert").get()
print("accessible:", el.accessible)
print("accessibility_container:", el.accessibility_container)
print("enabled:", el.enabled)
print("visible:", el.visible)
print("label:", el.label)
print("className:", el.className)
el.click()
print("alertExists:", c.alert.exists)
print("alertButtons:", c.alert.buttons())
print("alertClick:", c.alert.click("Dismiss"))
def test_xpath(c: wda.Client):
c.xpath("//Window/Other/Other").exists
def test_invalid_session(c: wda.Client):
app = c.session("com.apple.Preferences")
# kill app here
app.session_id = "no-exists"
app(label="Haha").exists
if __name__ == "__main__":
c = wda.USBClient()
# c.healthcheck() # 恢复WDA状态
# test_error_callback(c)
# test_elememt_operation(c)
# test_preferences(c)
# test_open_safari(c)
# test_xpath(c)
wda.DEBUG = True
test_invalid_session(c)