Android configuration parameters for the Gradle Plugin | Virtual devices

When running your Android instrumentation tests with the Perfecto Gradle Plugin against virtual devices in Perfecto, you can add configuration information for the test execution at the following levels:

  • Configuration file (recommended): A JSON-formatted file listing parameter assignments. For a full configuration file example, see the fullConfigFileVirtualDevices.json in our Espresso project on GitHub.
  • Within the module's build.gradle file: In the perfectoGradleSettings clause, include Authentication parameters and indicate the location of the configuration file.
  • On the command-line: Include any of the parameters in the format: -P<paramName>="<paramvalue>"

The following sections list the parameters for the different categories.

Perfecto Lab authentication parameters

Parameter

Possible Values

Meaning

cloudURL


The URL of the Perfecto Lab to connect to, but without the .app notation.

For example: mobilecloud.perfectomobile.com (but not mobilecloud.app.perfectomobile.com)

securityToken

Security Token

Tester's personal security token for the Perfecto Lab.

These parameters may be set in the format shown in the following sample code snippets:

Copy
Configuration file format
"cloudURL": "mobilecloud.perfectomobile.com""securityToken": "<security_token>"
Copy
build.gradle file format
perfectoGradleSettings { 
    cloudURL "mobilecloud.perfectomobile.com" 
    securityToken "<security_token>" 
} 
Copy
Command line format
> gradle perfecto-android-inst-vd -PcloudURL="mobilecloud.perfectomobile.com" -PsecurityToken="<security_token>"

Device selection parameters

You can select specific devices or specify a number of random devices.

Select specific devices

You can select to use the following parameters to specify a list of devices. Obtain the values for the following parameters based on the matrix of supported simulators. For details, see Supported emulator devices and OS versions.

If no device selection parameters are set, the plugin will select the default Android device.

Parameter

Possible Values

Meaning

model


Device model - for example: Pixel 6, Galaxy S22

platformName

Android

Device operating system

platformVersion


Operating system or browser version

These parameters may be set in the configuration file, in the following format:

Copy
Single device selection
"devices": [ 
    {
    "platformName" : "Android",
    "model": "pixel 6",
    "platformVersion": "13"
    }
]
Copy
Multiple device selection
"devices" : [
    {
        "platformName" : "Android",
        "model": "pixel 5",
        "platformVersion": "12"
    },
    {
        "platformName" : "Android",
        "model": "galaxy.*",
        "platformVersion": "13"
     },
     {}
]

Specify a number of random devices

When using Espresso, you can use the following parameter, in place of the devices clause, to indicate that the specified number of Android devices should be selected and the Espresso tests run on the devices in parallel.

Parameter

Possible Values

Meaning

numOfDevices

number in range [1,100]

Number of Android devices to select. If numOfDevices is outside the range, will default to select a single device.

This parameters may be set in either the configuration file, the perfectoGradleSettings clause of the build.gradle file, or on the command line, in the following format:

Copy
"numOfDevices" : 45

Application parameters

Parameter

Possible Values

Meaning

failBuildOnFailure

 true | false

Report a failure to the Gradle console if any test fails. Default is false.

apkPath


Path to the application apk file. Use this field if the run is not part of your application build or apk file is output to a non-standard folder (other than "app") by the build process. See Format of apkPath/testApkPath values below.

testApkPath


Path to the test APK. Use this field if the run is not part of your application build or your APK is output to a different locationlocation than the default. See Format of apkPath/testApkPath values below.

shard

true | false

Indicates that test runs should use the Sharding tests capability of the Android JUnitRunner. The number of shards to create is equal to the number of devices selected by the configuration.

Default: false

When activating the plugin, as a standalone activation, supply both the apkPath and testApkPath parameters.

Format of apkPath/testApkPath values

The path parameters indicate the location of the apk files of the application and the test-application. These may be located in either the local workstation storage or in the Perfecto Lab Repository. To differentiate between these locations, use the following format to indicate a location in the Repository:

repository://[PUBLIC | PRIVATE]:<app name>

Repository item must have .apk type indicator.

The "repository://" prefix is mandatory for Repository locations.

Selective testing parameters

In addition, there are filter parameters that limit the test scenarios executed during the run:

Parameter

Possible Values

Meaning

testSize

large | medium | small

Runs a test method annotated by size. The annotations are @LargeTest,
@MediumTest, and @SmallTest.
See examples below.

testClassNames


Array of class names that you wish to run. If not specified, all the classes will run.

Format:

  • Configuration file -
    "testClassNames":["Class","Class",...]
  • Command line -
    -PtestClassNames="Class;Class;..."

testMethodNames


Array of method names that you wish to run. If not specified, all methods will run. 

Format:

  • Configuration file -
    "testMethodNames":["Class#Method","Class#Method",...]
  • Command line -
    -PtestMethodNames="Class#Method;Class#Method;..."

testTimeout

number of milliseconds

An amount of time allocated to each test case.

If a test case exceeds the timeout, it will be reported as "failed". The full test set will continue with the next test case.

Important: Use only either testClassNames or testMethodNames, not both.

These parameters may be set:

  • In the configuration file, in the following format:

    Copy
    "testApkPath": "Users/usern/AndroidStudioProjects/Playground/app/build/outputs/apk/app-debug-AndroidTest.apk",
    "apkPath": "Users/usern/AndroidStudioProjects/Playground/app/build/outputs/apk/app-debug.apk",
    "testSize": "small",
    "testMethodNames": ["com.perfectomobile.com.DemoClass#demoMethod","com.perfectomobile.com.DemoClass#demoMethod2"]
  • In the perfectoGradleSettings clause of the build.gradle file:

    Copy
    perfectoGradleSettings { 
        ...
        testApkPath "Users/usern/AndroidStudioProjects/Playground/app/build/outputs/apk/app-debug-AndroidTest.apk"    apkPath "Users/usern/AndroidStudioProjects/Playground/app/build/outputs/apk/app-debug.apk" 
    } 
  • In the command line, in the following format:

    Copy
    gradle perfecto-android-inst-vd ... -PapkPath="Users/usern/AndroidStudioProjects/Playground/app/build/outputs/apk/app-debug.apk" -PtestSize="large"

Pre-execution and post-execution parameters

The following parameters control whether the application and test apk files are uninstalled from the devices, either prior to installing the latest version or at the end of the tests:

Parameter

Sub-parameter

Possible Values

Meaning

installationDetails



The parameters in this Clause affect the installation phase of the test run.


grantAll

true | false

If the parameter is set (true), then the application is granted all Android permissions listed in the application manifest.

Note: Applicable to Android 6.0 or later.

preExecution



The parameters in this Clause affect the device used for the test run.

-

screenOrientation

landscape| portrait

Configures how to orient the device when executing the tests. This affects the application display, test execution, dashboard display, and report video.

These parameters may be configured:

  • In the configuration file, in the following format:

    Copy
    "installationDetails" : {"grantAll" : true}
    "preExecution" : {"screenOrientation" : "PORTRAIT"}
  • In the perfectoGradleSettings clause of the module's build.gradle file:

    Copy
    perfectoGradleSettings { 
        ...
        preExecution {
            screenOrientation "PORTRAIT"
        }
        installationDetails {
            grantAll true
        }
     } 

Screenshot parameters

Screenshots are an important tool for analyzing the test actions, these may be snapped by the Espresso test code, or the plugin can be configured to add screenshots when the test run ends.  The following parameters specify when the plugin takes a screenshot:

Parameter

Possible Values

Meaning

takeScreenshotOnTestEnd

true | false

Save screenshot of device at end of the test executions, regardless of the test result status.

takeScreenshotOnTestFailure

true | false

Save screenshot of device at end of the test executions, if the test result status is a failure status.

These parameters may be set in the configuration filebuild.gradle file, or the command-line.

Reporting parameters

The following parameters are used by Smart Reporting to classify the execution report and make it easy to identify the reports for the execution.

Parameter

Possible Values

Meaning

tags


Set of tags to associate with the execution

jobName


CI identification of the build, used for classification of the report in the CI Dashboard.

jobNumber


CI Job Number of the build

projectName


Name of the project - for classification

projectVersion


Version number assigned to the project for this build

branch


Branch name. like additional tag.

These parameters may be set:

  • In the configuration file, in the following format:

    Copy
    "tags" : ["plugin", "espresso", "demo"],
    "projectName": "playground",
    "projectVersion": "1.5",
    "jobName": "newFeature",
    "jobNumber": "45"
  • In the perfectoGradleSettings clause of the build.gradle file:

    Copy
    perfectoGradleSettings { 
        ...
        projectName "playground"    projectVersion "1.5"} 
  • In the command line, in the following format:

    Copy
    gradle perfecto-android-inst-vd ... -Ptags="plugin;espresso;demo" -PjobName="newFeature"

Export the execution report

The Perfecto toolset generates a test execution report that can be exported for analysis. It is recommended to:

  1. Use these configuration parameters to define tagsjobName, and jobNumber for the test execution.
  2. Export the report data using these information items with the Smart ReportingPublic API.

Location of the configuration file

The plugin execution reads the configuration file whose location is indicated by the configFileLocation parameter that may be supplied:

  • In the perfectoGradleSettings clause of the build.gradle file.

    Copy
    perfectoGradleSettings { 
        ...
        configFileLocation "C:\temp\Espresso\ConfigFile.json" 
    } 
  • Or in the command line

    Copy
    gradle perfecto-android-inst-vd ... -PconfigFileLocation="C:\temp\Espresso\ConfigFile.json"

If the parameter is not supplied:

  • If running in Android Studio project - default location is <project dir>/src/main/assets/perfecto/instrumentedTest/configFile.json
  • If running in Standalone mode or the file is not found at the default location, then tests will run on a randomly selected available Android device.
  • The application and test-application identification parameters (apkPath and testApkPath) must be supplied in either the build.gradle file or on the command line.