-
Notifications
You must be signed in to change notification settings - Fork 1
/
Pollingtocheckthestatusts
76 lines (58 loc) · 3.16 KB
/
Pollingtocheckthestatusts
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
import java.io.IOException;
import com.testsigma.customfunc.common.CustomTestStep;
import com.testsigma.customfunc.common.TestsigmaCustomFunctions;
import com.testsigma.customfunc.result.ResultConstants;
import com.testsigma.customfunc.result.TestStepResult;
import com.testsigma.testengine.exceptions.TestEngineException;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
public class apicall extends TestsigmaCustomFunctions{
@CustomTestStep
public TestStepResult tiggerapicall(String planid) throws TestEngineException, IOException, InterruptedException{
final OkHttpClient client = new OkHttpClient().newBuilder()
.build();
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, "{\r\n\"executionId\": \""+planid+"\"\r\n}");
Request request = new Request.Builder()
.url("https://app.testsigma.com/api/v1/execution_results/")
.method("POST", body)
.addHeader("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2MjIyZTZjZi1mMDcwLTRhYzItODg2Yy05ZTg0MWU4ZWEyNTgiLCJkb21haW4iOiJ0ZXN0c2lnbWEuY29tIn0.fAzjbNeSZsoVUxXmsbHjERsbqDZgyaN0ai8gwOI8NJGYuHpOeNhTbBtCVLc3nL2xkGn5rCBDWmeU_3iIB_Gvug")
.addHeader("Content-Type", "application/json")
.build();
Response response = client.newCall(request).execute();
String rp=response.body().string();
final String runid=rp.substring(rp.indexOf("id")+4, rp.indexOf("executionId")-2);
for(int i=1;i<=60;i++) {
Request request2 = new Request.Builder()
.url("https://app.testsigma.com/api/v1/execution_results/"+runid+"")
.method("GET", null)
.addHeader("Authorization", "Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiI2MjIyZTZjZi1mMDcwLTRhYzItODg2Yy05ZTg0MWU4ZWEyNTgiLCJkb21haW4iOiJ0ZXN0c2lnbWEuY29tIn0.fAzjbNeSZsoVUxXmsbHjERsbqDZgyaN0ai8gwOI8NJGYuHpOeNhTbBtCVLc3nL2xkGn5rCBDWmeU_3iIB_Gvug")
.addHeader("Content-Type", "application/json")
.build();
Response response2;
try {
response2 = client.newCall(request2).execute();
String rp2=response2.body().string();
Thread.sleep(10000);
driver.getTitle();
if (rp2.contains("SUCCESS") || (rp2.contains("FAILURE")) ||(rp2.contains("ABORTED"))) {
TestStepResult result=new TestStepResult();
result.setMessage("Waited Until The other Test plan has executed");
result.setStatus(ResultConstants.SUCCESS);
break;
}
}
catch (IOException e1)
{
e1.printStackTrace();
}
}
TestStepResult result=new TestStepResult();
result.setMessage("Waited For Testplan with id="+planid+"with runid "+runid+"");
result.setStatus(ResultConstants.SUCCESS);
return result;
}
}