Execute tests in pCloudy device cloud
Download the sample app
wget https://github.com/testvagrant/ekam-examples/blob/master/app/swaglabs.apk
pCloudy Configuration
Make sure you have a pCloudy account. Please refer here
To run a test on pCloudy, we need the respective account’s UserName and AccessKey.
Where to find it?
Login into pCloudy
Click on the profile icon and Settings
- Get the Access Key from Device/Browser settings and User Name is same as your login username.
Create a cloud configuration file
Create pCloudy.json
file under the cloud_config
folder
pCloudy.json
{
"username": "<provide your username>",
"accessKey": "<probide your access key>",
"url": "https://device.pcloudy.com/appiumcloud/wd/hub",
"apiHost": "https://device.pcloudy.com/"
}
Specify app name and capabalities
Let us specify the name of the app & few mandatory desired capabilities to launch the application
Create file resources/mobile/pcloudy_mobilefeed.json
file & edit properties as below
{
"desiredCapabilities": [
{
"app": "sample.apk",
"platformName": "android",
"automationName": "UiAutomator2"
}
]
}
Filter devices for test execution
While executing tests in cloud devices, we often want to filters the devices/OS of our choice. We can pass this information by creating a file under resource/mobile
as shown below
Under resources/mobile
create a file pcloudy_device_filters.json
and specify devices to execute tests on.
{
"platformVersion": {
"include": [
],
"operator": "",
"exclude": []
},
"model": {
"include": [
"Samsung_GalaxyA12_Android_11.0.0_334bc"
],
"exclude": []
}
}
Update config
Let us update mobile.remote.properties
config. Or you could choose to create a new configuration file most suitable to you.
Let us add below properties:
- mobile.target : Set to android to execute tests against android
- mobile.feed : Feed file having app name and other capabalities
- mobile.filters : File specifying devices to use for test execution
- cloud.config.dir : Folder having cloud provider details
- mobile.hub : File having hub config for cloud (
pCloudy
in this case) - mobile.remote.uploadapp : Set to
true
to upload the app to BrowserStack
Open mobile.remote.properties
file. Or you could choose to create a new configuration file most suitable to you.
Add properties as below:
# Target mobile platform eg: android | ios
mobile.target: android
# Feed file having desiredCapabilities
mobile.feed: pcloudy_mobilefeed
# Filters to chose devices for test execution
mobile.filters: pcloudy_device_filters
# Folder name under resources having cloud configurations
cloud.config.dir: cloud_config
# cloud provider eg: browserstack | kobiton | etc
mobile.hub: pCloudy
# Upload app before execution <true | false>
mobile.remote.uploadapp: true
Execute tests
Execute tests by specifying the config
./gradlew runMobileTests -Dconfig=mobile.remote
Monitor the “REPORTS” section in pCloudy for execution details
Avoid clear text credentials in cloud config file
It is not a good practice to specify clear text passwords in any of the source files and configurations. Pass the password as a command-line argument.
- Use this syntax
"${env: <arg name>}"
for the required fields in the pcloudy.json file, provided an example below:
{
"username": "${env:PCLOUDY_USERNAME}",
"accessKey": "${env:PCLOUDY_ACCESS_KEY}",
"url": "https://device.pcloudy.com/appiumcloud/wd/hub",
"apiHost": "https://device.pcloudy.com/"
}
- Pass these system properties to Gradle task:
systemProperties = [
config: System.getProperty("config"),
PCLOUDY_USERNAME: System.getProperty("PCLOUDY_USERNAME"),
PCLOUDY_ACCESS_KEY: System.getProperty("PCLOUDY_ACCESS_KEY")
]
- The complete Gradle task
task runMobileTests(type: Test) {
filter {
excludeTestsMatching "*.web.*"
excludeTestsMatching "*.api.*"
excludeTestsMatching "*.db.*"
}
systemProperties = [
config: System.getProperty("config"),
PCLOUDY_USERNAME: System.getProperty("PCLOUDY_USERNAME"),
PCLOUDY_ACCESS_KEY: System.getProperty("PCLOUDY_ACCESS_KEY")
]
outputs.upToDateWhen { false }
useTestNG {
parallel = "methods"
threadCount Integer.parseInt(System.getProperty("sessions", "2"))
includeGroups System.getProperty("tags", "mobile")
testLogging.showStandardStreams = true
useDefaultListeners true
outputDirectory = file("$buildDir/" + System.getProperty('tags', 'NONE'))
}
}
Execute the test in terminal or CI as below:
./gradlew runMobileTests -Dconfig=mobile.remote -DPCLOUDY_USERNAME=<username> -DPCLOUDYACCESS_KEY=<access_key>