-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathTestExecutor.java
74 lines (63 loc) · 2.46 KB
/
TestExecutor.java
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
package io.github.lambdatest.gradle;
import com.google.gson.Gson;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import okhttp3.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class TestExecutor {
private static final Logger logger = LogManager.getLogger(TestExecutor.class);
private String username;
private String accessKey;
private String appId;
private String testSuiteId;
private List<String> device;
private Boolean isFlutter;
public TestExecutor(
String username,
String accessKey,
String appId,
String testSuiteId,
List<String> device,
Boolean isFlutter) {
this.username = username;
this.accessKey = accessKey;
this.appId = appId;
this.testSuiteId = testSuiteId;
this.device = device;
this.isFlutter = isFlutter;
}
public void executeTests(Map<String, String> params) throws IOException {
try {
OkHttpClient client = new OkHttpClient();
Gson gson = new Gson();
MediaType mediaType = MediaType.parse("application/json");
Map<String, Object> capabilities = new HashMap<>();
capabilities.put("app", appId);
capabilities.put("testSuite", testSuiteId);
capabilities.put("device", device);
capabilities.putAll(params);
logger.info("Capabilities: {}", capabilities);
String url =
(isFlutter == null || !isFlutter)
? Constants.BUILD_URL
: Constants.FLUTTER_BUILD_URL;
RequestBody body = RequestBody.create(gson.toJson(capabilities), mediaType);
Request request =
new Request.Builder()
.url(url)
.addHeader("Authorization", Credentials.basic(username, accessKey))
.addHeader("Content-Type", "application/json")
.post(body)
.build();
Response response = client.newCall(request).execute();
logger.info("Running Tests");
logger.info(response.body().string());
} catch (IOException e) {
logger.error("Error executing tests: {}", e.getMessage());
throw new RuntimeException(e);
}
}
}