Skip to content

Commit

Permalink
Add yml config usage for gradle plugin (#263)
Browse files Browse the repository at this point in the history
Refactor to decouple params of different scopes;
Add yml config for gradle plugin;
Add type param to testSpec section of yml config, remove extraArgs;
  • Loading branch information
olivershen-wow committed Feb 14, 2023
1 parent ca7a3df commit ca03c47
Show file tree
Hide file tree
Showing 25 changed files with 737 additions and 453 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import com.microsoft.hydralab.compile.UMLImageGenerator

task generateUMLImage(group: 'documentation') {
doFirst {
def scanningDirList = ['agent/doc/UML']
def scanningDirList = ['agent/doc/UML', 'gradle_plugin/doc/UML']
def outputDir = new File(projectDir, 'docs/images/UML')

def generator = new UMLImageGenerator()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ public class TestTaskSpec {
public boolean isPerfTest;
public boolean needUninstall = true;
public boolean needClearData = true;
// todo: remove this field when update overall center-ADO/Gradle plugins compatibility
@Deprecated
public Map<String, String> instrumentationArgs;
public Map<String, String> testRunArgs;
public Set<String> agentIds = new HashSet<>();
public String runningType;
public int maxStepCount = 100;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,12 @@ public static TestTask convertToTestTask(TestTaskSpec testTaskSpec) {
testTask.setTimeOutSecond(testTaskSpec.testTimeOutSec);
testTask.setNeededPermissions(testTaskSpec.neededPermissions);
testTask.setDeviceActions(testTaskSpec.deviceActions);
testTask.setInstrumentationArgs(testTaskSpec.instrumentationArgs);
if (testTaskSpec.instrumentationArgs != null) {
testTask.setInstrumentationArgs(testTaskSpec.instrumentationArgs);
}
else {
testTask.setInstrumentationArgs(testTaskSpec.testRunArgs);
}
testTask.setFileSetId(testTaskSpec.fileSetId);
testTask.setPkgName(testTaskSpec.pkgName);
testTask.setTestPkgName(testTaskSpec.testPkgName);
Expand Down
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 19 additions & 37 deletions gradle_plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,28 @@
This is the Gradle plugin of Hydra Lab.
In order to simplify the onboarding procedure to Hydra Lab for any app, this project packaged the client util and made it an easy way for any app to leverage the cloud testing service of Hydra Lab.

## Prerequisite
Include Hydra Lab plugin dependency in build.gradle of your project:
- Using the plugins DSL:
```
plugins {
id "com.microsoft.hydralab.client-util" version "${plugin_version}"
}
```
- Using legacy plugin application:
```
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.microsoft.hydralab:gradle_plugin:${plugin_version}"
}
}
apply plugin: "com.microsoft.hydralab.client-util"
```
See [Release Notes](https://github.com/microsoft/HydraLab/wiki/Release-Notes) for latest and stable versions.

## Usage
To trigger gradle task for Hydra Lab testing, simply follow below steps:
- Step 1: go to [template](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/src/main/resources/template) page, copy the following files to your repo and modify the content:
- [build.gradle](https://github.com/microsoft/HydraLab/blob/main/gradle_plugin/src/main/resources/template/build.gradle)
- To introduce dependency on this plugin, please copy all content to repository/module you would like to use the plugin in.
- [gradle.properties](https://github.com/microsoft/HydraLab/blob/main/gradle_plugin/src/main/resources/template/gradle.properties)
- According to the comment inline and the running type you choose for your test, you should keep all required parameters and fill in them with correct values.
- Step 2: Build your project/module to enable the Gradle plugin and task
To trigger Hydra Lab testing using Gradle command, simply follow below steps:
- Step 1: go to [template](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/template) page, selectively leverage the following files to your repo and modify the content:
- To introduce dependency on this plugin, please copy according content in [build.gradle](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/template/build.gradle) to your project/module.
- See [release notes](https://github.com/microsoft/HydraLab/wiki/Release-Notes) for version info and version number.
- Update **${plugin_version}** with your selected version.
- According to your project structure, apply one or combination of the following configuration approaches to configure the input parameters of gradle plugin task (see detailed explanation for parameters in [gradle.properties](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/template/gradle.properties))
- **Parameter priority: inline command > gradle.properties > yaml**
- Inline gradle command, set parameters with "-Pxxx=yyy".
- Sample: **gradle [:${MODULE_NAME}:]requestHydraLabTest -PappPath="${PATH_TO_APP}" -PtestAppPath=...**
- [gradle.properties](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/template/gradle.properties)
- Usage:
- Fill in the file, keep only the parameters needed for your test, and remove the redundant ones.
- Keep this file in the same directory as your build.gradle, gradle task will read this file automatically.
- [testSpec.yml](https://github.com/microsoft/HydraLab/tree/main/gradle_plugin/template/testSpec.yml)
- Usage:
- Fill in the file, keep only the parameters needed for your test, and remove the redundant ones.
- Specific the yml file path by inline command "-PymlConfigFile=${PATH_TO_YML}" following the gradle task command.
- Sample: **gradle [:${MODULE_NAME}:]requestHydraLabTest -PymlConfigFile=${PATH_TO_YML} ...**
- Step 2: Build your project/module to enable the gradle plugin and task
- Step 3: Run gradle task requestHydraLabTest
- Use gradle command to trigger the task.
- Override any value in gradle.properties by specify command param "-PXXX=xxx".
- Example command: **gradle requestHydraLabTest -PappApkPath="D:\Test Folder\app.apk"**

## Known issue
- Hard-coded with Azure DevOps embedded variable names, currently may not be compatible to other CI tools when fetching commit related information.

## TODO
**- Add yml configuration file for task param setup.**
4 changes: 3 additions & 1 deletion gradle_plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@ dependencies {
implementation 'org.ow2.asm:asm:7.0'
implementation 'org.ow2.asm:asm-util:7.0'
implementation networkDependencies.okHttp
implementation 'org.yaml:snakeyaml:1.33'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.0.1'
}

// plugin publishing related
version = '1.0.45'
version = '1.1.0'
group = 'com.microsoft.hydralab'
// alter group to this when publish to local, in order to distinguish local version and gradle plugin portal version
//group = 'com.microsoft.hydralab.local'
Expand Down
68 changes: 68 additions & 0 deletions gradle_plugin/doc/UML/gradle_plugin_yaml_config_design.puml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
@startyaml
hydraLabAPIServer:
host: example.center-endpoint.com
schema: https
authToken: xxxxxxxxxx
testSpec:
device:
deviceIdentifier: RANDOMDEVICESERIALNUMBER123
groupTestType: SINGLE
deviceActions:
setUp:
- deviceType: Android
method: setProperty
args:
- xxx
- xxx
- deviceType: Android
method: pushFileToDevice
args:
- xxx
tearDown:
- deviceType: Android
method: setProperty
args:
- xxx
- deviceType: Android
method: pullFileFromDevice
args:
- xxx
triggerType: API
runningType: INSTRUMENTATION
appPath: ABSOLUTE_PATH_TO_APP_FILE
pkgName: app.pkg.name
testAppPath: ABSOLUTE_PATH_TO_TEST_APP_FILE
testPkgName: test_app.pkg.name
teamName: Default
testRunnerName: androidx.test.runner.AndroidJUnitRunner
testScope: CLASS
testSuiteName: test.suite.class.name
frameworkType: JUNIT4
runTimeOutSeconds: 1000
queueTimeOutSeconds: 500
needUninstall: true
needClearData: true
neededPermissions:
- android.permission.READ_CONTACTS
- android.permission.WRITE_CONTACTS
attachmentConfigPath: ABSOLUTE_PATH_TO_ATTACHMENT_CONFIG_FILE
attachmentInfos:
- fileName: a.json
filePath: ABSOLUTE_PATH_TO_A_JSON
fileType: COMMON
loadType: COPY
loadDir: DIR_TO_COPY_A_TO
- fileName: b.json
filePath: ABSOLUTE_PATH_TO_A_JSON
fileType: COMMON
loadType: COPY
loadDir: DIR_TO_COPY_B_TO
artifactTag: artifact_file_name_tag
testRunArgs:
key1: value1
key2: value2
exploration:
maxStepCount: 100
testRound: -1

@endyaml

0 comments on commit ca03c47

Please sign in to comment.