Skip to content

Commit a676b3c

Browse files
Fixes: Add progress tracking for app uploads (#28)
1 parent 3a442cd commit a676b3c

File tree

9 files changed

+460
-26
lines changed

9 files changed

+460
-26
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ runLambdaTest {
3939
isFlutter = true //if you are running flutter dart tests
4040
appId = "lt//1234343" //provide this only if you have already uploaded the app
4141
testSuiteId = "lt//1223444" //provide this only if you have already uploaded the app
42+
showUploadProgress = true //enable upload progress tracking in console
4243
}
4344
```
4445

@@ -50,6 +51,7 @@ uploadApkToLambdaTest {
5051
accessKey = 'yourLambdaTestAccessKey'
5152
appFilePath = 'pathToYourAppFile'
5253
testSuiteFilePath = 'pathToYourTestSuite'
54+
showUploadProgress = true //enable upload progress tracking in console
5355
}
5456
```
5557

@@ -68,6 +70,7 @@ The following capabilities are supported:
6870
- `build`: Set the name of the Espresso test build. Example: My Espresso Build.
6971
- `geoLocation`: Set the geolocation country code if you want to enable the same in your test. Example - FR.
7072
- `tunnel`, `tunnelName`: Set tunnel as true and provide the tunnelName such as NewTunnel as needed if you are running a tunnel.
73+
- `showUploadProgress`: Display real-time upload progress in the console with percentage and data transferred. Example: true.
7174

7275
- `appFilePath` : Path of your app file (this will be uploaded to LambdaTest)
7376

build.gradle

Lines changed: 1 addition & 1 deletion
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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ public class AppUploader {
1919
private String username;
2020
private String accessKey;
2121
private String appFilePath;
22+
private boolean showProgress;
2223

2324
/**
2425
* Creates a new AppUploader instance with the specified credentials and file path.
@@ -28,6 +29,20 @@ public class AppUploader {
2829
* @param appFilePath The path to the application file to be uploaded
2930
*/
3031
public AppUploader(String username, String accessKey, String appFilePath) {
32+
this(username, accessKey, appFilePath, false);
33+
}
34+
35+
/**
36+
* Creates a new AppUploader instance with the specified credentials, file path, and progress
37+
* tracking option.
38+
*
39+
* @param username The LambdaTest account username
40+
* @param accessKey The LambdaTest account access key
41+
* @param appFilePath The path to the application file to be uploaded
42+
* @param showProgress Whether to display upload progress in the console
43+
*/
44+
public AppUploader(
45+
String username, String accessKey, String appFilePath, boolean showProgress) {
3146
if (username == null) throw new IllegalArgumentException("Username cannot be null");
3247
if (accessKey == null) throw new IllegalArgumentException("Access Key cannot be null");
3348
if (appFilePath == null) throw new IllegalArgumentException("App File Path cannot be null");
@@ -38,6 +53,7 @@ public AppUploader(String username, String accessKey, String appFilePath) {
3853
this.username = username;
3954
this.accessKey = accessKey;
4055
this.appFilePath = appFilePath;
56+
this.showProgress = showProgress;
4157
}
4258

4359
/**
@@ -52,7 +68,8 @@ public CompletableFuture<String> uploadAppAsync() {
5268
() -> {
5369
try {
5470
String appId =
55-
UploaderUtil.uploadAndGetId(username, accessKey, appFilePath);
71+
UploaderUtil.uploadAndGetId(
72+
username, accessKey, appFilePath, showProgress, "App");
5673
logger.info("Uploaded app ID: {}", appId);
5774
return appId;
5875
} catch (IOException e) {

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

Lines changed: 41 additions & 7 deletions
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 showUploadProgress;
4849

4950
/**
5051
* Executes the LambdaTest task, which includes uploading the application and test suite,
@@ -58,37 +59,66 @@ public class LambdaTestTask extends DefaultTask {
5859
*/
5960
@TaskAction
6061
public void runLambdaTest() {
61-
logger.info("Starting LambdaTest task...");
62+
boolean progressEnabled = showUploadProgress != null && showUploadProgress;
63+
64+
if (!progressEnabled) {
65+
logger.info("Starting LambdaTest task...");
66+
}
6267

6368
// Upload app
6469
CompletableFuture<String> appIdFuture = null;
6570
CompletableFuture<String> testSuiteIdFuture = null;
6671

6772
if (appId == null && appFilePath != null) {
68-
logger.info("Uploading app...");
69-
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
73+
if (!progressEnabled) {
74+
logger.info("Uploading app...");
75+
}
76+
AppUploader appUploader =
77+
new AppUploader(username, accessKey, appFilePath, progressEnabled);
7078
appIdFuture = appUploader.uploadAppAsync();
7179
}
7280

7381
if (testSuiteId == null && testSuiteFilePath != null) {
74-
logger.info("Uploading test suite...");
82+
if (!progressEnabled) {
83+
logger.info("Uploading test suite...");
84+
}
7585
TestSuiteUploader testSuiteUploader =
76-
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
86+
new TestSuiteUploader(username, accessKey, testSuiteFilePath, progressEnabled);
7787
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
7888
}
7989

8090
// Ensure both uploads are completed before continuing
8191
try {
8292
if (appIdFuture != null) {
8393
appId = appIdFuture.join();
84-
logger.info("App uploaded successfully with ID: {}", appId);
94+
if (!progressEnabled) {
95+
logger.info("App uploaded successfully with ID: {}", appId);
96+
}
8597
}
8698

8799
if (testSuiteIdFuture != null) {
88100
testSuiteId = testSuiteIdFuture.join();
89-
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
101+
if (!progressEnabled) {
102+
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
103+
}
104+
}
105+
106+
// Clear progress display if enabled
107+
if (progressEnabled) {
108+
ProgressTracker.cleanup();
109+
// Show success messages after progress cleanup
110+
if (appIdFuture != null) {
111+
logger.info("App uploaded successfully with ID: {}", appId);
112+
}
113+
if (testSuiteIdFuture != null) {
114+
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
115+
}
90116
}
91117
} catch (CompletionException e) {
118+
// Cleanup progress display on error
119+
if (progressEnabled) {
120+
ProgressTracker.cleanup();
121+
}
92122
logger.error("Failed to execute tasks: {}", e);
93123
throw new RuntimeException(e);
94124
}
@@ -217,4 +247,8 @@ public void setTestSuiteId(String testSuiteId) {
217247
this.testSuiteId = testSuiteId;
218248
}
219249
}
250+
251+
public void setShowUploadProgress(Boolean showUploadProgress) {
252+
this.showUploadProgress = showUploadProgress;
253+
}
220254
}

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

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,85 @@ public class LambdaUploaderTask extends DefaultTask {
2121
private String accessKey;
2222
private String appFilePath;
2323
private String testSuiteFilePath;
24+
private Boolean showUploadProgress;
2425

2526
@TaskAction
2627
public void uploadApkToLambdaTest() {
2728
// Generated after upload of app and test suite
28-
String appId;
29-
String testSuiteId;
29+
String appId = null;
30+
String testSuiteId = null;
3031
CompletableFuture<String> appIdFuture = null;
3132
CompletableFuture<String> testSuiteIdFuture = null;
32-
logger.lifecycle("Starting LambdaTest APK Uploader task...");
33+
34+
boolean progressEnabled = showUploadProgress != null && showUploadProgress;
35+
36+
// Only log to lifecycle if progress is disabled
37+
if (!progressEnabled) {
38+
logger.lifecycle("Starting LambdaTest APK Uploader task...");
39+
}
3340

3441
if (appFilePath != null) {
35-
logger.lifecycle("Uploading app ...");
36-
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
42+
if (!progressEnabled) {
43+
logger.lifecycle("Uploading app ...");
44+
}
45+
AppUploader appUploader =
46+
new AppUploader(username, accessKey, appFilePath, progressEnabled);
3747
appIdFuture = appUploader.uploadAppAsync();
3848
}
3949

4050
if (testSuiteFilePath != null) {
41-
logger.lifecycle("Uploading test suite ...");
51+
if (!progressEnabled) {
52+
logger.lifecycle("Uploading test suite ...");
53+
}
4254
TestSuiteUploader testSuiteUploader =
43-
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
55+
new TestSuiteUploader(username, accessKey, testSuiteFilePath, progressEnabled);
4456
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
4557
}
4658

4759
try {
4860
if (appIdFuture != null) {
4961
appId = appIdFuture.join();
50-
logger.lifecycle("\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
62+
if (!progressEnabled) {
63+
logger.lifecycle(
64+
"\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
65+
}
5166
}
5267

5368
if (testSuiteIdFuture != null) {
5469
testSuiteId = testSuiteIdFuture.join();
55-
logger.lifecycle(
56-
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
57-
testSuiteId);
70+
if (!progressEnabled) {
71+
logger.lifecycle(
72+
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
73+
testSuiteId);
74+
}
75+
}
76+
77+
// Clear progress display if enabled
78+
if (progressEnabled) {
79+
ProgressTracker.cleanup();
80+
// Show success messages after progress cleanup
81+
if (appIdFuture != null) {
82+
logger.lifecycle(
83+
"\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
84+
}
85+
if (testSuiteIdFuture != null) {
86+
logger.lifecycle(
87+
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
88+
testSuiteId);
89+
}
5890
}
5991
} catch (CompletionException e) {
92+
// Cleanup progress display on error
93+
if (progressEnabled) {
94+
ProgressTracker.cleanup();
95+
}
6096
logger.error("Failed to execute LambdaTest APK Uploader task : {}", e);
6197
throw new RuntimeException(e);
6298
}
6399

64-
logger.lifecycle("Completed LambdaTest APK Uploader task ...");
100+
if (!progressEnabled) {
101+
logger.lifecycle("Completed LambdaTest APK Uploader task ...");
102+
}
65103
}
66104

67105
// Setter functions for the task
@@ -80,4 +118,8 @@ public void setAppFilePath(String appFilePath) {
80118
public void setTestSuiteFilePath(String testSuiteFilePath) {
81119
this.testSuiteFilePath = testSuiteFilePath;
82120
}
121+
122+
public void setShowUploadProgress(Boolean showUploadProgress) {
123+
this.showUploadProgress = showUploadProgress;
124+
}
83125
}

0 commit comments

Comments
 (0)