diff --git a/build.gradle b/build.gradle index 97afcfb..f6e4de2 100644 --- a/build.gradle +++ b/build.gradle @@ -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 { diff --git a/src/main/java/io/github/lambdatest/gradle/AppUploader.java b/src/main/java/io/github/lambdatest/gradle/AppUploader.java index 4ce322d..4b3b687 100644 --- a/src/main/java/io/github/lambdatest/gradle/AppUploader.java +++ b/src/main/java/io/github/lambdatest/gradle/AppUploader.java @@ -9,8 +9,8 @@ * Handles the asynchronous upload of application files to the LambdaTest platform. This class * manages the upload process and returns the application ID for test execution. * - *

Uses {@link UploaderUtil#uploadAndGetId(String, String, String)} for the actual file upload - * process. + *

Uses {@link UploaderUtil#uploadAndGetId(String, String, String,Boolean)} for the actual file + * upload process. */ public class AppUploader { @@ -19,6 +19,7 @@ public class AppUploader { private String username; private String accessKey; private String appFilePath; + private Boolean isVirtualDevice; /** * Creates a new AppUploader instance with the specified credentials and file path. @@ -26,8 +27,10 @@ public class AppUploader { * @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 isVirtualDevice Boolean indicating if upload is to a virtual device */ - public AppUploader(String username, String accessKey, String appFilePath) { + public AppUploader( + String username, String accessKey, String appFilePath, Boolean isVirtualDevice) { 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"); @@ -35,6 +38,7 @@ public AppUploader(String username, String accessKey, String appFilePath) { this.username = username; this.accessKey = accessKey; this.appFilePath = appFilePath; + this.isVirtualDevice = isVirtualDevice; } /** @@ -49,7 +53,8 @@ public CompletableFuture uploadAppAsync() { () -> { try { String appId = - UploaderUtil.uploadAndGetId(username, accessKey, appFilePath); + UploaderUtil.uploadAndGetId( + username, accessKey, appFilePath, isVirtualDevice); logger.info("Uploaded app ID: {}", appId); return appId; } catch (IOException e) { diff --git a/src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java b/src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java index 44af815..216425d 100644 --- a/src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java +++ b/src/main/java/io/github/lambdatest/gradle/LambdaTestTask.java @@ -45,6 +45,7 @@ public class LambdaTestTask extends DefaultTask { private String appId; private String testSuiteId; private Integer queueTimeout; + private Boolean isVirtualDevice = false; /** * Executes the LambdaTest task, which includes uploading the application and test suite, @@ -66,14 +67,15 @@ public void runLambdaTest() { if (appId == null && appFilePath != null) { logger.info("Uploading app..."); - AppUploader appUploader = new AppUploader(username, accessKey, appFilePath); + AppUploader appUploader = + new AppUploader(username, accessKey, appFilePath, isVirtualDevice); appIdFuture = appUploader.uploadAppAsync(); } if (testSuiteId == null && testSuiteFilePath != null) { logger.info("Uploading test suite..."); TestSuiteUploader testSuiteUploader = - new TestSuiteUploader(username, accessKey, testSuiteFilePath); + new TestSuiteUploader(username, accessKey, testSuiteFilePath, isVirtualDevice); testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync(); } @@ -96,7 +98,14 @@ public void runLambdaTest() { // Execute tests logger.info("Executing tests..."); TestExecutor testExecutor = - new TestExecutor(username, accessKey, appId, testSuiteId, device, isFlutter); + new TestExecutor( + username, + accessKey, + appId, + testSuiteId, + device, + isFlutter, + isVirtualDevice); Map params = new HashMap<>(); if (build != null) params.put("build", build); @@ -217,4 +226,13 @@ public void setTestSuiteId(String testSuiteId) { this.testSuiteId = testSuiteId; } } + + /** + * Sets whether the device used for the test execution is a virtual device. + * + * @param isVirtualDevice true if the device is a virtual device, false otherwise + */ + public void setIsVirtualDevice(Boolean isVirtualDevice) { + this.isVirtualDevice = (isVirtualDevice != null && isVirtualDevice); + } } diff --git a/src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java b/src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java index dc65649..1ef294a 100644 --- a/src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java +++ b/src/main/java/io/github/lambdatest/gradle/LambdaUploaderTask.java @@ -21,6 +21,7 @@ public class LambdaUploaderTask extends DefaultTask { private String accessKey; private String appFilePath; private String testSuiteFilePath; + private Boolean isVirtualDevice = false; @TaskAction public void uploadApkToLambdaTest() { @@ -33,14 +34,15 @@ public void uploadApkToLambdaTest() { if (appFilePath != null) { logger.lifecycle("Uploading app ..."); - AppUploader appUploader = new AppUploader(username, accessKey, appFilePath); + AppUploader appUploader = + new AppUploader(username, accessKey, appFilePath, isVirtualDevice); appIdFuture = appUploader.uploadAppAsync(); } if (testSuiteFilePath != null) { logger.lifecycle("Uploading test suite ..."); TestSuiteUploader testSuiteUploader = - new TestSuiteUploader(username, accessKey, testSuiteFilePath); + new TestSuiteUploader(username, accessKey, testSuiteFilePath, isVirtualDevice); testSuiteIdFuture = testSuiteUploader.uploadTestSuiteAsync(); } @@ -80,4 +82,8 @@ public void setAppFilePath(String appFilePath) { public void setTestSuiteFilePath(String testSuiteFilePath) { this.testSuiteFilePath = testSuiteFilePath; } + + public void setIsVirtualDevice(Boolean isVirtualDevice) { + this.isVirtualDevice = (isVirtualDevice != null && isVirtualDevice); + } } diff --git a/src/main/java/io/github/lambdatest/gradle/TestExecutor.java b/src/main/java/io/github/lambdatest/gradle/TestExecutor.java index e7ed5ee..81ca7bb 100644 --- a/src/main/java/io/github/lambdatest/gradle/TestExecutor.java +++ b/src/main/java/io/github/lambdatest/gradle/TestExecutor.java @@ -24,6 +24,7 @@ public class TestExecutor { private String testSuiteId; private List device; private Boolean isFlutter; + private Boolean isVirtualDevice; /** * Creates a new TestExecutor with the specified configuration. @@ -41,13 +42,15 @@ public TestExecutor( String appId, String testSuiteId, List device, - Boolean isFlutter) { + Boolean isFlutter, + Boolean isVirtualDevice) { this.username = username; this.accessKey = accessKey; this.appId = appId; this.testSuiteId = testSuiteId; this.device = device; this.isFlutter = isFlutter; + this.isVirtualDevice = isVirtualDevice; } /** @@ -70,6 +73,9 @@ public void executeTests(Map params) throws IOException { capabilities.put("app", appId); capabilities.put("testSuite", testSuiteId); capabilities.put("device", device); + if (isVirtualDevice) { + capabilities.put("isVirtualDevice", isVirtualDevice); + } capabilities.putAll(params); logger.info("Capabilities: {}", capabilities); diff --git a/src/main/java/io/github/lambdatest/gradle/TestSuiteUploader.java b/src/main/java/io/github/lambdatest/gradle/TestSuiteUploader.java index a91983e..4aa2635 100644 --- a/src/main/java/io/github/lambdatest/gradle/TestSuiteUploader.java +++ b/src/main/java/io/github/lambdatest/gradle/TestSuiteUploader.java @@ -16,6 +16,7 @@ public class TestSuiteUploader { private String username; private String accessKey; private String testSuiteFilePath; + private Boolean isVirtualDevice; /** * Creates a new TestSuiteUploader instance with the specified credentials and file path. @@ -23,11 +24,14 @@ public class TestSuiteUploader { * @param username The LambdaTest account username * @param accessKey The LambdaTest account access key * @param testSuiteFilePath The path to the test suite file to be uploaded + * @param isVirtualDevice Boolean indicating if upload is to a virtual device */ - public TestSuiteUploader(String username, String accessKey, String testSuiteFilePath) { + public TestSuiteUploader( + String username, String accessKey, String testSuiteFilePath, Boolean isVirtualDevice) { this.username = username; this.accessKey = accessKey; this.testSuiteFilePath = testSuiteFilePath; + this.isVirtualDevice = isVirtualDevice; } /** @@ -42,7 +46,8 @@ public CompletableFuture uploadTestSuiteAsync() { () -> { try { String testSuiteId = - UploaderUtil.uploadAndGetId(username, accessKey, testSuiteFilePath); + UploaderUtil.uploadAndGetId( + username, accessKey, testSuiteFilePath, isVirtualDevice); logger.info("Uploaded test suite ID: {}", testSuiteId); return testSuiteId; } catch (IOException e) { diff --git a/src/main/java/io/github/lambdatest/gradle/UploaderUtil.java b/src/main/java/io/github/lambdatest/gradle/UploaderUtil.java index d692d42..a36ebb8 100644 --- a/src/main/java/io/github/lambdatest/gradle/UploaderUtil.java +++ b/src/main/java/io/github/lambdatest/gradle/UploaderUtil.java @@ -35,10 +35,12 @@ private UploaderUtil() { * @param username The LambdaTest account username * @param accessKey The LambdaTest account access key * @param filePath The path to the file to be uploaded + * @param isVirtualDevice Boolean indicating if the device is virtual * @return The ID of the uploaded file * @throws IOException if there's an error during file upload or response parsing */ - public static String uploadAndGetId(String username, String accessKey, String filePath) + public static String uploadAndGetId( + String username, String accessKey, String filePath, Boolean isVirtualDevice) throws IOException { OkHttpClient client = new OkHttpClient.Builder() @@ -48,15 +50,20 @@ public static String uploadAndGetId(String username, String accessKey, String fi .build(); MediaType mediaType = MediaType.parse("application/octet-stream"); - RequestBody body = + MultipartBody.Builder builder = new MultipartBody.Builder() .setType(MultipartBody.FORM) .addFormDataPart( "appFile", filePath, RequestBody.create(new File(filePath), mediaType)) - .addFormDataPart("type", "espresso-android") - .build(); + .addFormDataPart("type", "espresso-android"); + + if (isVirtualDevice) { + builder.addFormDataPart("isVirtualDevice", String.valueOf(isVirtualDevice)); + } + + RequestBody body = builder.build(); Request request = new Request.Builder() .url(Constants.API_URL)