forked from LambdaTest/lambdatest-gradle-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLambdaTestTask.java
220 lines (184 loc) · 7.54 KB
/
LambdaTestTask.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
package io.github.lambdatest.gradle;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.gradle.api.DefaultTask;
import org.gradle.api.tasks.TaskAction;
/**
* Main task class for the LambdaTest Gradle plugin that handles test execution on the LambdaTest
* platform. This task manages the upload of applications and test suites, followed by test
* execution with specified configurations.
*
* <p>This task coordinates between {@link AppUploader}, {@link TestSuiteUploader}, and {@link
* TestExecutor} to manage the complete test execution lifecycle.
*/
public class LambdaTestTask extends DefaultTask {
private static final Logger logger = LogManager.getLogger(LambdaTestTask.class);
private String username;
private String accessKey;
private String appFilePath;
private String testSuiteFilePath;
private List<String> device;
private String build;
private Boolean deviceLog;
private Integer idleTimeout;
private Boolean video;
private Boolean network;
private Boolean tunnel;
private String tunnelName;
private String geoLocation;
private Boolean disableAnimation;
private Boolean clearPackageData;
private Boolean singleRunnerInvocation;
private Boolean globalHttpProxy;
private String fixedIp;
private Boolean isFlutter;
private String appId;
private String testSuiteId;
private Integer queueTimeout;
/**
* Executes the LambdaTest task, which includes uploading the application and test suite,
* followed by test execution on the LambdaTest platform.
*
* @implNote This method handles the task execution in three main phases: 1. Asynchronous upload
* of the application using {@link AppUploader#uploadAppAsync()} 2. Asynchronous upload of
* the test suite using {@link TestSuiteUploader#uploadTestSuiteAsync()} 3. Test execution
* with {@link TestExecutor#executeTests(Map)}
* @throws RuntimeException if any upload or test execution fails
*/
@TaskAction
public void runLambdaTest() {
logger.info("Starting LambdaTest task...");
// Upload app
CompletableFuture<String> appIdFuture = null;
CompletableFuture<String> testSuiteIdFuture = null;
if (appId == null && appFilePath != null) {
logger.info("Uploading app...");
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
appIdFuture = appUploader.uploadAppAsync();
}
if (testSuiteId == null && testSuiteFilePath != null) {
logger.info("Uploading test suite...");
TestSuiteUploader testSuiteUploader =
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
}
// Ensure both uploads are completed before continuing
try {
if (appIdFuture != null) {
appId = appIdFuture.join();
logger.info("App uploaded successfully with ID: {}", appId);
}
if (testSuiteIdFuture != null) {
testSuiteId = testSuiteIdFuture.join();
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
}
} catch (CompletionException e) {
logger.error("Failed to execute tasks: {}", e);
throw new RuntimeException(e);
}
// Execute tests
logger.info("Executing tests...");
TestExecutor testExecutor =
new TestExecutor(username, accessKey, appId, testSuiteId, device, isFlutter);
Map<String, String> params = new HashMap<>();
if (build != null) params.put("build", build);
if (deviceLog != null) params.put("deviceLog", deviceLog.toString());
if (idleTimeout != null) params.put("IdleTimeout", idleTimeout.toString());
if (video != null) params.put("video", video.toString());
if (network != null) params.put("network", network.toString());
if (tunnel != null) params.put("tunnel", tunnel.toString());
if (tunnelName != null) params.put("tunnelName", tunnelName);
if (geoLocation != null) params.put("geoLocation", geoLocation);
if (disableAnimation != null) params.put("disableAnimation", disableAnimation.toString());
if (clearPackageData != null) params.put("clearPackageData", clearPackageData.toString());
if (singleRunnerInvocation != null)
params.put("singleRunnerInvocation", singleRunnerInvocation.toString());
if (globalHttpProxy != null) params.put("globalHttpProxy", globalHttpProxy.toString());
if (fixedIp != null) params.put("fixedIp", fixedIp);
if (queueTimeout != null) params.put("queueTimeout", queueTimeout.toString());
try {
testExecutor.executeTests(params);
} catch (IOException e) {
logger.error("Failed to execute tests: {}", e);
throw new RuntimeException(e);
}
logger.info("LambdaTest task completed.");
}
// setter methods for the properties
public void setUsername(String username) {
this.username = username;
}
public void setAccessKey(String accessKey) {
this.accessKey = accessKey;
}
public void setAppFilePath(String appFilePath) {
this.appFilePath = appFilePath;
}
public void setTestSuiteFilePath(String testSuiteFilePath) {
this.testSuiteFilePath = testSuiteFilePath;
}
public void setDevice(List<String> device) {
this.device = device;
}
public void setBuild(String build) {
this.build = build;
}
public void setDeviceLog(Boolean deviceLog) {
this.deviceLog = deviceLog;
}
public void setIdleTimeout(Integer idleTimeout) {
this.idleTimeout = idleTimeout;
}
public void setVideo(Boolean video) {
this.video = video;
}
public void setNetwork(Boolean network) {
this.network = network;
}
public void setTunnel(Boolean tunnel) {
this.tunnel = tunnel;
}
public void setTunnelName(String tunnelName) {
this.tunnelName = tunnelName;
}
public void setGeoLocation(String geoLocation) {
this.geoLocation = geoLocation;
}
public void setDisableAnimation(Boolean disableAnimation) {
this.disableAnimation = disableAnimation;
}
public void setClearPackageData(Boolean clearPackageData) {
this.clearPackageData = clearPackageData;
}
public void setSingleRunnerInvocation(Boolean singleRunnerInvocation) {
this.singleRunnerInvocation = singleRunnerInvocation;
}
public void setGlobalHttpProxy(Boolean globalHttpProxy) {
this.globalHttpProxy = globalHttpProxy;
}
public void setFixedIp(String fixedIp) {
this.fixedIp = fixedIp;
}
public void setQueueTimeout(Integer queueTimeout) {
this.queueTimeout = queueTimeout;
}
public void setIsFlutter(Boolean isFlutter) {
this.isFlutter = (isFlutter != null && isFlutter);
}
public void setAppId(String appId) {
if (appId != null && !appId.trim().isEmpty()) {
this.appId = appId;
}
}
public void setTestSuiteId(String testSuiteId) {
if (testSuiteId != null && !testSuiteId.trim().isEmpty()) {
this.testSuiteId = testSuiteId;
}
}
}