Created
March 22, 2018 20:18
-
-
Save RoshanNindrai/efe80a1d7e5c1e05b71345c9259ca9ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import subprocess | |
import sys, os | |
from multiprocessing import Pool | |
def pre_req(workspace_path): | |
if '.xcworkspace' in workspace_path and os.path.exists(workspace_path): | |
device_ids = list_device_ids() | |
run_xcuitest(workspace_path, device_ids) | |
else: | |
print('Please provide a valid path to a xcworkspace') | |
def run_xcuitest(workspace_path, devices): | |
# Create a multiprocessing Pool | |
pool = Pool() | |
parameters = [] | |
for device in devices: | |
parameters.append((workspace_path, device)) | |
process_log = pool.map(execute_xcuitest, parameters) | |
#pool.close() | |
#pool.join() | |
def execute_xcuitest(data): | |
workspace_path = data[0] | |
device_id = data[1] | |
xcui_test_command = 'xcodebuild -workspace {workspace_path} -scheme UIKitCatalogUITest -destination id={device_id} test'.format(workspace_path=workspace_path, | |
device_id=device_id).split(" ") | |
print(xcui_test_command) | |
test_logs = subprocess.Popen(xcui_test_command, | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
print('-----------{device_id}--------------'.format(device_id=device_id)) | |
error_log = test_logs.stderr.read() | |
print('xxxxxxxxxxxxxxxxxx') | |
print(error_log) | |
print('xxxxxxxxxxxxxxxxxx') | |
print(test_logs.stdout.read()) | |
print('-------------------------') | |
# Call instruments to get all devices | |
def list_device_ids(): | |
start = "["; end = "]" | |
instrument_command = 'instruments -s devices' | |
black_list = ['Known', 'Simulator', 'MacBook'] | |
device_list = subprocess.Popen(instrument_command.split(" "), | |
stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
device_list_string = device_list.stdout.read() | |
physical_devices = [] | |
for device in device_list_string.splitlines(): | |
if not any(x in device for x in black_list): | |
physical_devices.append(device[device.find(start)+len(start):device.rfind(end)]) | |
return physical_devices | |
def main(): | |
if len(sys.argv) > 1: | |
pre_req(sys.argv[1]) | |
else: | |
print('Please provide a path to the workspace') | |
exit(1) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WE can just call multiple --destination instead of separate processes, but this is just a POC on running xcodebuild command in parallel