-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathtrigger-job.py
44 lines (37 loc) · 1022 Bytes
/
trigger-job.py
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
import requests
import sys
import time
projectId = "ADD YOUR PROJECT ID"
jobId = "ADD YOUR JOB ID"
apiKey = "ADD YOUR API KEY"
agentId = "ADD YOUR AGENT ID"
apiUrl = "https://api.testproject.io/"
url = apiUrl + 'v2/projects/' + projectId + '/jobs/' + jobId + '/run'
headers = {
"accept": "application/json",
"Authorization": apiKey,
"Content-Type": "application/json"
}
body = {
"agentId": agentId,
"browsers": [
"Chrome"
],
"queue": True
}
executionId = requests.post(url, json=body, headers=headers).json()["id"]
url = apiUrl + 'v2/projects/' + projectId + '/jobs/' + jobId + '/executions/'+ executionId + '/state'
headers = {
"accept": "application/json",
"Authorization": apiKey,
}
executionState = requests.get(url, headers=headers).json()["state"]
count = 0
while count < 10:
executionState = requests.get(url, headers=headers).json()["state"]
print(executionState)
if executionState == 'Passed':
exit(1)
time.sleep(2)
count += 1
exit(0)