Skip to content

Commit ceb7c78

Browse files
committed
Added example / test
1 parent e6a4e20 commit ceb7c78

File tree

2 files changed

+82
-1
lines changed

2 files changed

+82
-1
lines changed

examples/run_testrun.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import argparse
2+
import sys
3+
import time
4+
import json
5+
6+
from testdroid import Testdroid
7+
from testdroid import RequestResponseError
8+
9+
parser = argparse.ArgumentParser(description='Run some tests.')
10+
parser.add_argument('--api-key, -a', dest='api_key', required=True, help='Bitbar API key')
11+
parser.add_argument('--dg-id, -d', dest='dg_id', required=True, help='Device group ID')
12+
parser.add_argument('--framework-id, -f', dest='framework_id', required=True, help='Framework ID')
13+
parser.add_argument('--project-name, -p', dest='project_name', required=True, help='Project name')
14+
parser.add_argument('--app-file', dest='app_file', help='App file path')
15+
parser.add_argument('--cloud-url, -c', dest='cloud_url', help='Cloud endpoint')
16+
parser.add_argument('--os-type, -o', dest='os_type', help='OS type')
17+
parser.add_argument('--test-file', dest='test_file', help='Test file path')
18+
19+
args = parser.parse_args()
20+
print("Cloud endpoint: {}".format(args.cloud_url))
21+
print("OS type: {}".format(args.os_type))
22+
print("Framework ID: {}".format(args.framework_id))
23+
print("Project name: {}".format(args.project_name))
24+
print("Device group ID: {}".format(args.dg_id))
25+
print("App file path: {}".format(args.app_file))
26+
print("Test file path: {}".format(args.test_file))
27+
28+
testdroid = Testdroid(apikey=args.api_key, url=args.cloud_url)
29+
30+
###############################
31+
# Login test
32+
###############################
33+
print(testdroid.get_me()['id'])
34+
35+
###############################
36+
# Create, delete and recreate project
37+
###############################
38+
project = testdroid.create_project(args.project_name)
39+
testdroid.delete_project(project['id'])
40+
try:
41+
delete_project = testdroid.get_project(project['id'])
42+
except RequestResponseError:
43+
pass
44+
else:
45+
print("Project delete failed")
46+
sys.exit(1)
47+
48+
project = testdroid.create_project(args.project_name)
49+
print(project)
50+
51+
###############################
52+
# Upload app and test
53+
###############################
54+
app_file_id = testdroid.upload_file(filename=args.app_file)['id']
55+
test_file_id = testdroid.upload_file(filename=args.test_file)['id']
56+
57+
###############################
58+
# Launch a test run
59+
###############################
60+
run_config = {'osType': args.os_type if args.os_type else "ANDROID",
61+
'frameworkId': args.framework_id,
62+
'projectId': project['id'],
63+
'files': [{'id': app_file_id}, {'id': test_file_id}],
64+
'deviceGroupId': args.dg_id}
65+
testrun = testdroid.start_test_run_using_config(json.dumps(run_config))
66+
print(testrun)
67+
68+
###############################
69+
# Wait until test run is FINISHED
70+
###############################
71+
while True:
72+
run_state = testdroid.get_test_run(project['id'], testrun['id'])['state']
73+
if run_state == "FINISHED":
74+
break
75+
print("Test run state: {}".format(run_state))
76+
time.sleep(5)
77+
78+
###############################
79+
# Download results and delete a project
80+
###############################
81+
testdroid.download_test_run(project['id'], testrun['id'])
82+
testdroid.delete_project(project['id'])

testdroid/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,6 @@ def create_project(self, project_name, project_type=None):
397397
if project_type:
398398
print("Project type is deprecated and not used anymore")
399399
project = self.post(path="me/projects", payload={"name": project_name})
400-
print(project)
401400

402401
logger.info("Project %s: %s created" % (project['id'], project['name']))
403402
return project

0 commit comments

Comments
 (0)