Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 56903ba

Browse files
Rachit TiwariRachit Tiwari
Rachit Tiwari
authored and
Rachit Tiwari
committedFeb 25, 2025·
Added support for virtual device testing/upload apks
1 parent a8e61ff commit 56903ba

File tree

7 files changed

+64
-17
lines changed

7 files changed

+64
-17
lines changed
 

‎build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
id 'com.diffplug.spotless' version '6.25.0'
55
}
66

7-
version = '1.0.6'
7+
version = '1.0.7'
88
group = 'io.github.lambdatest'
99

1010
repositories {

‎src/main/java/io/github/lambdatest/gradle/AppUploader.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* Handles the asynchronous upload of application files to the LambdaTest platform. This class
1010
* manages the upload process and returns the application ID for test execution.
1111
*
12-
* <p>Uses {@link UploaderUtil#uploadAndGetId(String, String, String)} for the actual file upload
13-
* process.
12+
* <p>Uses {@link UploaderUtil#uploadAndGetId(String, String, String,Boolean)} for the actual file
13+
* upload process.
1414
*/
1515
public class AppUploader {
1616

@@ -19,22 +19,26 @@ public class AppUploader {
1919
private String username;
2020
private String accessKey;
2121
private String appFilePath;
22+
private Boolean isVirtualDevice;
2223

2324
/**
2425
* Creates a new AppUploader instance with the specified credentials and file path.
2526
*
2627
* @param username The LambdaTest account username
2728
* @param accessKey The LambdaTest account access key
2829
* @param appFilePath The path to the application file to be uploaded
30+
* @param isVirtualDevice Boolean indicating if upload is to a virtual device
2931
*/
30-
public AppUploader(String username, String accessKey, String appFilePath) {
32+
public AppUploader(
33+
String username, String accessKey, String appFilePath, Boolean isVirtualDevice) {
3134
if (username == null) throw new IllegalArgumentException("Username cannot be null");
3235
if (accessKey == null) throw new IllegalArgumentException("Access Key cannot be null");
3336
if (appFilePath == null) throw new IllegalArgumentException("App File Path cannot be null");
3437

3538
this.username = username;
3639
this.accessKey = accessKey;
3740
this.appFilePath = appFilePath;
41+
this.isVirtualDevice = isVirtualDevice;
3842
}
3943

4044
/**
@@ -49,7 +53,8 @@ public CompletableFuture<String> uploadAppAsync() {
4953
() -> {
5054
try {
5155
String appId =
52-
UploaderUtil.uploadAndGetId(username, accessKey, appFilePath);
56+
UploaderUtil.uploadAndGetId(
57+
username, accessKey, appFilePath, isVirtualDevice);
5358
logger.info("Uploaded app ID: {}", appId);
5459
return appId;
5560
} catch (IOException e) {

‎src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java

+21-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class LambdaTestTask extends DefaultTask {
4545
private String appId;
4646
private String testSuiteId;
4747
private Integer queueTimeout;
48+
private Boolean isVirtualDevice = false;
4849

4950
/**
5051
* Executes the LambdaTest task, which includes uploading the application and test suite,
@@ -66,14 +67,15 @@ public void runLambdaTest() {
6667

6768
if (appId == null && appFilePath != null) {
6869
logger.info("Uploading app...");
69-
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
70+
AppUploader appUploader =
71+
new AppUploader(username, accessKey, appFilePath, isVirtualDevice);
7072
appIdFuture = appUploader.uploadAppAsync();
7173
}
7274

7375
if (testSuiteId == null && testSuiteFilePath != null) {
7476
logger.info("Uploading test suite...");
7577
TestSuiteUploader testSuiteUploader =
76-
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
78+
new TestSuiteUploader(username, accessKey, testSuiteFilePath, isVirtualDevice);
7779
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
7880
}
7981

@@ -96,7 +98,14 @@ public void runLambdaTest() {
9698
// Execute tests
9799
logger.info("Executing tests...");
98100
TestExecutor testExecutor =
99-
new TestExecutor(username, accessKey, appId, testSuiteId, device, isFlutter);
101+
new TestExecutor(
102+
username,
103+
accessKey,
104+
appId,
105+
testSuiteId,
106+
device,
107+
isFlutter,
108+
isVirtualDevice);
100109
Map<String, String> params = new HashMap<>();
101110

102111
if (build != null) params.put("build", build);
@@ -217,4 +226,13 @@ public void setTestSuiteId(String testSuiteId) {
217226
this.testSuiteId = testSuiteId;
218227
}
219228
}
229+
230+
/**
231+
* Sets whether the device used for the test execution is a virtual device.
232+
*
233+
* @param isVirtualDevice true if the device is a virtual device, false otherwise
234+
*/
235+
public void setIsVirtualDevice(Boolean isVirtualDevice) {
236+
this.isVirtualDevice = (isVirtualDevice != null && isVirtualDevice);
237+
}
220238
}

‎src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class LambdaUploaderTask extends DefaultTask {
2121
private String accessKey;
2222
private String appFilePath;
2323
private String testSuiteFilePath;
24+
private Boolean isVirtualDevice = false;
2425

2526
@TaskAction
2627
public void uploadApkToLambdaTest() {
@@ -33,14 +34,15 @@ public void uploadApkToLambdaTest() {
3334

3435
if (appFilePath != null) {
3536
logger.lifecycle("Uploading app ...");
36-
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
37+
AppUploader appUploader =
38+
new AppUploader(username, accessKey, appFilePath, isVirtualDevice);
3739
appIdFuture = appUploader.uploadAppAsync();
3840
}
3941

4042
if (testSuiteFilePath != null) {
4143
logger.lifecycle("Uploading test suite ...");
4244
TestSuiteUploader testSuiteUploader =
43-
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
45+
new TestSuiteUploader(username, accessKey, testSuiteFilePath, isVirtualDevice);
4446
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
4547
}
4648

@@ -80,4 +82,8 @@ public void setAppFilePath(String appFilePath) {
8082
public void setTestSuiteFilePath(String testSuiteFilePath) {
8183
this.testSuiteFilePath = testSuiteFilePath;
8284
}
85+
86+
public void setIsVirtualDevice(Boolean isVirtualDevice) {
87+
this.isVirtualDevice = (isVirtualDevice != null && isVirtualDevice);
88+
}
8389
}

‎src/main/java/io/github/lambdatest/gradle/TestExecutor.java

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class TestExecutor {
2424
private String testSuiteId;
2525
private List<String> device;
2626
private Boolean isFlutter;
27+
private Boolean isVirtualDevice;
2728

2829
/**
2930
* Creates a new TestExecutor with the specified configuration.
@@ -41,13 +42,15 @@ public TestExecutor(
4142
String appId,
4243
String testSuiteId,
4344
List<String> device,
44-
Boolean isFlutter) {
45+
Boolean isFlutter,
46+
Boolean isVirtualDevice) {
4547
this.username = username;
4648
this.accessKey = accessKey;
4749
this.appId = appId;
4850
this.testSuiteId = testSuiteId;
4951
this.device = device;
5052
this.isFlutter = isFlutter;
53+
this.isVirtualDevice = isVirtualDevice;
5154
}
5255

5356
/**
@@ -70,6 +73,9 @@ public void executeTests(Map<String, String> params) throws IOException {
7073
capabilities.put("app", appId);
7174
capabilities.put("testSuite", testSuiteId);
7275
capabilities.put("device", device);
76+
if (isVirtualDevice) {
77+
capabilities.put("isVirtualDevice", isVirtualDevice);
78+
}
7379
capabilities.putAll(params);
7480

7581
logger.info("Capabilities: {}", capabilities);

‎src/main/java/io/github/lambdatest/gradle/TestSuiteUploader.java

+7-2
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,22 @@ public class TestSuiteUploader {
1616
private String username;
1717
private String accessKey;
1818
private String testSuiteFilePath;
19+
private Boolean isVirtualDevice;
1920

2021
/**
2122
* Creates a new TestSuiteUploader instance with the specified credentials and file path.
2223
*
2324
* @param username The LambdaTest account username
2425
* @param accessKey The LambdaTest account access key
2526
* @param testSuiteFilePath The path to the test suite file to be uploaded
27+
* @param isVirtualDevice Boolean indicating if upload is to a virtual device
2628
*/
27-
public TestSuiteUploader(String username, String accessKey, String testSuiteFilePath) {
29+
public TestSuiteUploader(
30+
String username, String accessKey, String testSuiteFilePath, Boolean isVirtualDevice) {
2831
this.username = username;
2932
this.accessKey = accessKey;
3033
this.testSuiteFilePath = testSuiteFilePath;
34+
this.isVirtualDevice = isVirtualDevice;
3135
}
3236

3337
/**
@@ -42,7 +46,8 @@ public CompletableFuture<String> uploadTestSuiteAsync() {
4246
() -> {
4347
try {
4448
String testSuiteId =
45-
UploaderUtil.uploadAndGetId(username, accessKey, testSuiteFilePath);
49+
UploaderUtil.uploadAndGetId(
50+
username, accessKey, testSuiteFilePath, isVirtualDevice);
4651
logger.info("Uploaded test suite ID: {}", testSuiteId);
4752
return testSuiteId;
4853
} catch (IOException e) {

‎src/main/java/io/github/lambdatest/gradle/UploaderUtil.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ private UploaderUtil() {
3535
* @param username The LambdaTest account username
3636
* @param accessKey The LambdaTest account access key
3737
* @param filePath The path to the file to be uploaded
38+
* @param isVirtualDevice Boolean indicating if the device is virtual
3839
* @return The ID of the uploaded file
3940
* @throws IOException if there's an error during file upload or response parsing
4041
*/
41-
public static String uploadAndGetId(String username, String accessKey, String filePath)
42+
public static String uploadAndGetId(
43+
String username, String accessKey, String filePath, Boolean isVirtualDevice)
4244
throws IOException {
4345
OkHttpClient client =
4446
new OkHttpClient.Builder()
@@ -48,15 +50,20 @@ public static String uploadAndGetId(String username, String accessKey, String fi
4850
.build();
4951

5052
MediaType mediaType = MediaType.parse("application/octet-stream");
51-
RequestBody body =
53+
MultipartBody.Builder builder =
5254
new MultipartBody.Builder()
5355
.setType(MultipartBody.FORM)
5456
.addFormDataPart(
5557
"appFile",
5658
filePath,
5759
RequestBody.create(new File(filePath), mediaType))
58-
.addFormDataPart("type", "espresso-android")
59-
.build();
60+
.addFormDataPart("type", "espresso-android");
61+
62+
if (isVirtualDevice) {
63+
builder.addFormDataPart("isVirtualDevice", String.valueOf(isVirtualDevice));
64+
}
65+
66+
RequestBody body = builder.build();
6067
Request request =
6168
new Request.Builder()
6269
.url(Constants.API_URL)

0 commit comments

Comments
 (0)
Please sign in to comment.