Skip to content

Commit

Permalink
Merge pull request #28 from anurag1408/master
Browse files Browse the repository at this point in the history
Adding support for running instrumentation and appium tests in custom Mode, Also added support for running appium Python Tests from the plugin
  • Loading branch information
nikhil-dabhade authored Nov 21, 2018
2 parents 6bc84be + e1f3bb6 commit 4022376
Show file tree
Hide file tree
Showing 8 changed files with 137 additions and 16 deletions.
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,19 @@ Appium

* [Appium JUnit](http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-appium-java-junit.html)
* [Appium TestNG](http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-appium-java-testng.html)
* [Appium Python](http://docs.aws.amazon.com/devicefarm/latest/developerguide/test-types-android-appium-python.html)

Device Farm provides support for Appium Java TestNG and JUnit for Android.
Device Farm provides support for Appium Java TestNG , Appium Java JUnit and Appium Java python for Android.

You can choose to `useTestNG()` or `useJUnit()`.
You can choose to `useTestNG()` or `useJUnit()` or `usePython()`.

JUnit is the default and does not need to be explicitly specified.

```gradle
appium {
tests file("path to zip file") // Required
useTestNG() // or useJUnit()
useTestNG() // or useJUnit() or usePython()
testSpecName "My Test Spec Name" // if you want to use Custom Mode // Optional
}
```

Expand Down Expand Up @@ -234,6 +236,7 @@ When running an instrumentation test in gradle the apk generated from your andro
```gradle
instrumentation {
filter "test filter per developer docs" // Optional
testSpecName "My Test Spec Name" // if you want to use Custom Mode // Optional
}
```

Expand Down
4 changes: 2 additions & 2 deletions aws-devicefarm-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ dependencies {

compile 'com.android.tools.build:builder-test-api:0.5.2'
compile 'org.apache.commons:commons-lang3:3.4'
compile 'com.amazonaws:aws-java-sdk:1.11.240'
compile 'com.amazonaws:aws-java-sdk:1.11.408'
testCompile 'org.testng:testng:6.8.8'
testCompile 'com.android.tools.build:gradle:3.0.0'
testCompile 'org.jmockit:jmockit:1.19'
Expand All @@ -49,7 +49,7 @@ test {
}

group 'com.amazonaws'
version '1.4-SNAPSHOT'
version '1.4'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
*/
public class DeviceFarmServer extends TestServer {

private static final String RUNPARAM_VIDEO_RECORDING = "video_recording";
private static final String RUNPARAM_APP_PERF_MONITORING = "app_performance_monitoring";

private final DeviceFarmExtension extension;
Expand Down Expand Up @@ -105,17 +104,25 @@ public void uploadApks(final String variantName, final File testPackage, final F

final String extraDataArn = uploadExtraDataZip(project);

// For few frameworks , you can specify a testSpec
final Upload testSpec = utils.findTestSpecByName(extension.getTest().getTestSpecName(), project);
if (testSpec != null) {
logger.lifecycle(String.format("Using TestSpec \"%s\", \"%s\"", testSpec.getName(), testSpec.getArn()));
}

final ScheduleRunTest runTest = new ScheduleRunTest()
.withParameters(extension.getTest().getTestParameters())
.withType(extension.getTest().getTestType())
.withFilter(extension.getTest().getFilter())
.withTestPackageArn(uploadTestPackageIfNeeded(project, testPackage));
.withTestPackageArn(uploadTestPackageIfNeeded(project, testPackage))
.withTestSpecArn(testSpec == null ? null: testSpec.getArn());


runTest.addParametersEntry(RUNPARAM_VIDEO_RECORDING, Boolean.toString(extension.getVideoRecording()));
runTest.addParametersEntry(RUNPARAM_APP_PERF_MONITORING, Boolean.toString(extension.getPerformanceMonitoring()));

final ExecutionConfiguration executionConfiguration = new ExecutionConfiguration()
.withJobTimeoutMinutes(extension.getExecutionTimeoutMinutes());
.withJobTimeoutMinutes(extension.getExecutionTimeoutMinutes())
.withVideoCapture(extension.getVideoRecording());

final ScheduleRunConfiguration configuration = new ScheduleRunConfiguration()
.withAuxiliaryApps(getAuxAppArns(auxApps))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
import com.amazonaws.services.devicefarm.model.ListDevicePoolsResult;
import com.amazonaws.services.devicefarm.model.ListProjectsRequest;
import com.amazonaws.services.devicefarm.model.ListProjectsResult;
import com.amazonaws.services.devicefarm.model.ListUploadsRequest;
import com.amazonaws.services.devicefarm.model.ListUploadsResult;
import com.amazonaws.services.devicefarm.model.Project;
import com.amazonaws.services.devicefarm.model.Upload;
import com.amazonaws.services.devicefarm.model.UploadStatus;

import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -46,13 +52,77 @@ public DeviceFarmUtils(final AWSDeviceFarm api, final DeviceFarmExtension extens
*/
public List<Project> getProjects() {

final ListProjectsResult result = api.listProjects(new ListProjectsRequest());
List<Project> projects = new ArrayList<Project>();
ListProjectsResult result = api.listProjects(new ListProjectsRequest());
projects.addAll(result.getProjects());
while (result.getNextToken() != null) {
ListProjectsRequest request = new ListProjectsRequest();
request.setNextToken(result.getNextToken());
result = api.listProjects(request);
projects.addAll(result.getProjects());
}
return projects;
}

/**
* Get Device Farm uploads for a given Device Farm project.
*
* @param project
* Device Farm Project.
* @return A List of the Device Farm uploads.
*/
public List<Upload> getUploads(Project project) {

List<Upload> uploads = new ArrayList<Upload>();
ListUploadsResult result = api.listUploads(new ListUploadsRequest().withArn(project.getArn()));
uploads.addAll(result.getUploads());
while (result.getNextToken() != null) {
ListUploadsRequest request = new ListUploadsRequest();
request.setNextToken(result.getNextToken());
result = api.listUploads(request);
uploads.addAll(result.getUploads());
}
return uploads;
}

/**
* Get Device Farm TestSpecs for a given Device Farm project.
*
* @param project Device Farm Project.
* @return A List of the Device Farm TestSpecs.
*/
public List<Upload> getTestSpecs(Project project) {
List<Upload> allUploads = getUploads(project);
List<Upload> testSpecUploads = new ArrayList<Upload>();
for (Upload upload : allUploads) {
if (upload.getType().contains("TEST_SPEC")
&& UploadStatus.SUCCEEDED.toString().equals(upload.getStatus())) {
testSpecUploads.add(upload);

}
}
return testSpecUploads;
}

if (result == null) {
return new ArrayList<>();
} else {
return result.getProjects();
/**
* Get Device Farm testSpec by name.
*
* @param testSpecName String name of the Device Farm testSpec.
* @param project Device Farm project
* @return The Device Farm project.
*/
public Upload findTestSpecByName(final String testSpecName, Project project) {

if (StringUtils.isBlank(testSpecName)) {
return null;
}
for (Upload upload : getTestSpecs(project)) {
if (upload.getName().equals(testSpecName)) {
return upload;
}
}

throw new DeviceFarmException(String.format("testSpec '%s' not found.", testSpecName));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import com.amazonaws.services.devicefarm.model.UploadType
/**
* JUNIT by default.
*/
class AppiumTest extends ConfiguredTest implements TestPackageProvider {
class AppiumTest extends ConfiguredTest implements TestPackageProvider, CustomMode {

{
testType = TestType.APPIUM_JAVA_JUNIT
Expand All @@ -43,6 +43,14 @@ class AppiumTest extends ConfiguredTest implements TestPackageProvider {
this.testPackageUploadType = UploadType.APPIUM_JAVA_JUNIT_TEST_PACKAGE
}

/**
* Configure for python
*/
void usePython() {
testType = TestType.APPIUM_PYTHON
this.testPackageUploadType = UploadType.APPIUM_PYTHON_TEST_PACKAGE
}

@Override
boolean isValid() { TestPackageProvider.super.isValid() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,13 @@ abstract class ConfiguredTest {
return null;
}

String getTestSpecName() {
if (this instanceof CustomMode) {
return ((CustomMode) this).getTestSpecName();
}

return null;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Copyright 2015-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
// You may not use this file except in compliance with the License.
// A copy of the License is located at
//
// http://aws.amazon.com/apache2.0
//
// or in the "license" file accompanying this file. This file is distributed
// on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
// express or implied. See the License for the specific language governing
// permissions and limitations under the License.
//
package com.amazonaws.devicefarm.extension

/**
* Marks tests that have filter
*/
trait CustomMode {

String testSpecName

void testSpecName(String val) { testSpecName = val }
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package com.amazonaws.devicefarm.extension
import com.amazonaws.services.devicefarm.model.TestType
import com.amazonaws.services.devicefarm.model.UploadType

class InstrumentationTest extends ConfiguredTest implements TestPackageProvider, HasFilter {
class InstrumentationTest extends ConfiguredTest implements TestPackageProvider, HasFilter, CustomMode {

{
testType = TestType.INSTRUMENTATION
Expand Down

0 comments on commit 4022376

Please sign in to comment.