forked from appium/WebDriverAgent
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
55 lines (43 loc) 路 1.67 KB
/
Copy pathrun.py
File metadata and controls
55 lines (43 loc) 路 1.67 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
import subprocess
import signal
import sys
import re
import json
import argparse
parser = argparse.ArgumentParser(description="Get device ID for xcode")
parser.add_argument('--device_id', type=str, help='Specify a device ID to use', required=False)
args = parser.parse_args()
device_id = args.device_id
# otherwise use the most recent used device in xcode
if not device_id:
cmd = "plutil -extract DVTDevicesWindowControllerSelectedDeviceIdentifier raw ~/Library/Preferences/com.apple.dt.Xcode.plist"
result = subprocess.run(cmd, shell=True, capture_output=True)
result.check_returncode()
device_id = result.stdout.decode().strip()
assert len(device_id) > 0
print("馃毃device id:", device_id)
cmd = f"xcodebuild test -allowProvisioningUpdates -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination 'platform=iOS,id={device_id}'"
child_process = subprocess.Popen(
cmd,
shell=True,
stdout=subprocess.PIPE,
text=True,
bufsize=1,
universal_newlines=True,
)
def kill(sig, frame):
print("馃拃 killing the child process")
child_process.send_signal(signal.SIGKILL)
sys.exit(0)
# make sure we kill the child process on ctrl+C
signal.signal(signal.SIGINT, kill)
signal.signal(signal.SIGTERM, kill)
for line in child_process.stdout:
print(line)
# WDA starts the http server and logs its ip and port
m = re.search(r"ServerURLHere->http://([\.\d]+):(\d+)<-ServerURLHere", line)
if m is not None:
wda_host, wda_port = m.group(1), m.group(2)
print("馃敟wda http server", wda_host, wda_port)
with open("/tmp/wda.json", "w") as f:
json.dump({"host": wda_host, "port": wda_port}, f)