Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ runLambdaTest {
isFlutter = true //if you are running flutter dart tests
appId = "lt//1234343" //provide this only if you have already uploaded the app
testSuiteId = "lt//1223444" //provide this only if you have already uploaded the app
showUploadProgress = true //enable upload progress tracking in console
}
```

Expand All @@ -50,6 +51,7 @@ uploadApkToLambdaTest {
accessKey = 'yourLambdaTestAccessKey'
appFilePath = 'pathToYourAppFile'
testSuiteFilePath = 'pathToYourTestSuite'
showUploadProgress = true //enable upload progress tracking in console
}
```

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

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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'com.diffplug.spotless' version '6.25.0'
}

version = '1.0.6'
version = '1.0.7'
group = 'io.github.lambdatest'

repositories {
Expand Down
19 changes: 18 additions & 1 deletion src/main/java/io/github/lambdatest/gradle/AppUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class AppUploader {
private String username;
private String accessKey;
private String appFilePath;
private boolean showProgress;

/**
* Creates a new AppUploader instance with the specified credentials and file path.
Expand All @@ -28,6 +29,20 @@ public class AppUploader {
* @param appFilePath The path to the application file to be uploaded
*/
public AppUploader(String username, String accessKey, String appFilePath) {
this(username, accessKey, appFilePath, false);
}

/**
* Creates a new AppUploader instance with the specified credentials, file path, and progress
* tracking option.
*
* @param username The LambdaTest account username
* @param accessKey The LambdaTest account access key
* @param appFilePath The path to the application file to be uploaded
* @param showProgress Whether to display upload progress in the console
*/
public AppUploader(
String username, String accessKey, String appFilePath, boolean showProgress) {
if (username == null) throw new IllegalArgumentException("Username cannot be null");
if (accessKey == null) throw new IllegalArgumentException("Access Key cannot be null");
if (appFilePath == null) throw new IllegalArgumentException("App File Path cannot be null");
Expand All @@ -38,6 +53,7 @@ public AppUploader(String username, String accessKey, String appFilePath) {
this.username = username;
this.accessKey = accessKey;
this.appFilePath = appFilePath;
this.showProgress = showProgress;
}

/**
Expand All @@ -52,7 +68,8 @@ public CompletableFuture<String> uploadAppAsync() {
() -> {
try {
String appId =
UploaderUtil.uploadAndGetId(username, accessKey, appFilePath);
UploaderUtil.uploadAndGetId(
username, accessKey, appFilePath, showProgress, "App");
logger.info("Uploaded app ID: {}", appId);
return appId;
} catch (IOException e) {
Expand Down
48 changes: 41 additions & 7 deletions src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class LambdaTestTask extends DefaultTask {
private String appId;
private String testSuiteId;
private Integer queueTimeout;
private Boolean showUploadProgress;

/**
* Executes the LambdaTest task, which includes uploading the application and test suite,
Expand All @@ -58,37 +59,66 @@ public class LambdaTestTask extends DefaultTask {
*/
@TaskAction
public void runLambdaTest() {
logger.info("Starting LambdaTest task...");
boolean progressEnabled = showUploadProgress != null && showUploadProgress;

if (!progressEnabled) {
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);
if (!progressEnabled) {
logger.info("Uploading app...");
}
AppUploader appUploader =
new AppUploader(username, accessKey, appFilePath, progressEnabled);
appIdFuture = appUploader.uploadAppAsync();
}

if (testSuiteId == null && testSuiteFilePath != null) {
logger.info("Uploading test suite...");
if (!progressEnabled) {
logger.info("Uploading test suite...");
}
TestSuiteUploader testSuiteUploader =
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
new TestSuiteUploader(username, accessKey, testSuiteFilePath, progressEnabled);
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 (!progressEnabled) {
logger.info("App uploaded successfully with ID: {}", appId);
}
}

if (testSuiteIdFuture != null) {
testSuiteId = testSuiteIdFuture.join();
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
if (!progressEnabled) {
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
}
}

// Clear progress display if enabled
if (progressEnabled) {
ProgressTracker.cleanup();
// Show success messages after progress cleanup
if (appIdFuture != null) {
logger.info("App uploaded successfully with ID: {}", appId);
}
if (testSuiteIdFuture != null) {
logger.info("Test suite uploaded successfully with ID: {}", testSuiteId);
}
}
} catch (CompletionException e) {
// Cleanup progress display on error
if (progressEnabled) {
ProgressTracker.cleanup();
}
logger.error("Failed to execute tasks: {}", e);
throw new RuntimeException(e);
}
Expand Down Expand Up @@ -217,4 +247,8 @@ public void setTestSuiteId(String testSuiteId) {
this.testSuiteId = testSuiteId;
}
}

public void setShowUploadProgress(Boolean showUploadProgress) {
this.showUploadProgress = showUploadProgress;
}
}
66 changes: 54 additions & 12 deletions src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,47 +21,85 @@ public class LambdaUploaderTask extends DefaultTask {
private String accessKey;
private String appFilePath;
private String testSuiteFilePath;
private Boolean showUploadProgress;

@TaskAction
public void uploadApkToLambdaTest() {
// Generated after upload of app and test suite
String appId;
String testSuiteId;
String appId = null;
String testSuiteId = null;
CompletableFuture<String> appIdFuture = null;
CompletableFuture<String> testSuiteIdFuture = null;
logger.lifecycle("Starting LambdaTest APK Uploader task...");

boolean progressEnabled = showUploadProgress != null && showUploadProgress;

// Only log to lifecycle if progress is disabled
if (!progressEnabled) {
logger.lifecycle("Starting LambdaTest APK Uploader task...");
}

if (appFilePath != null) {
logger.lifecycle("Uploading app ...");
AppUploader appUploader = new AppUploader(username, accessKey, appFilePath);
if (!progressEnabled) {
logger.lifecycle("Uploading app ...");
}
AppUploader appUploader =
new AppUploader(username, accessKey, appFilePath, progressEnabled);
appIdFuture = appUploader.uploadAppAsync();
}

if (testSuiteFilePath != null) {
logger.lifecycle("Uploading test suite ...");
if (!progressEnabled) {
logger.lifecycle("Uploading test suite ...");
}
TestSuiteUploader testSuiteUploader =
new TestSuiteUploader(username, accessKey, testSuiteFilePath);
new TestSuiteUploader(username, accessKey, testSuiteFilePath, progressEnabled);
testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync();
}

try {
if (appIdFuture != null) {
appId = appIdFuture.join();
logger.lifecycle("\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
if (!progressEnabled) {
logger.lifecycle(
"\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
}
}

if (testSuiteIdFuture != null) {
testSuiteId = testSuiteIdFuture.join();
logger.lifecycle(
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
testSuiteId);
if (!progressEnabled) {
logger.lifecycle(
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
testSuiteId);
}
}

// Clear progress display if enabled
if (progressEnabled) {
ProgressTracker.cleanup();
// Show success messages after progress cleanup
if (appIdFuture != null) {
logger.lifecycle(
"\u001B[32mApp uploaded successfully with ID: {}\u001B[0m", appId);
}
if (testSuiteIdFuture != null) {
logger.lifecycle(
"\u001B[32mTest suite uploaded successfully with ID: {}\u001B[0m",
testSuiteId);
}
}
} catch (CompletionException e) {
// Cleanup progress display on error
if (progressEnabled) {
ProgressTracker.cleanup();
}
logger.error("Failed to execute LambdaTest APK Uploader task : {}", e);
throw new RuntimeException(e);
}

logger.lifecycle("Completed LambdaTest APK Uploader task ...");
if (!progressEnabled) {
logger.lifecycle("Completed LambdaTest APK Uploader task ...");
}
}

// Setter functions for the task
Expand All @@ -80,4 +118,8 @@ public void setAppFilePath(String appFilePath) {
public void setTestSuiteFilePath(String testSuiteFilePath) {
this.testSuiteFilePath = testSuiteFilePath;
}

public void setShowUploadProgress(Boolean showUploadProgress) {
this.showUploadProgress = showUploadProgress;
}
}
Loading
Loading