I believe that this should be possible using the custom environments option when scheduling a run in Device Farm. Admittedly, I don't have experience with serenity but here is blog which uses cucumber tests.
https://aws.amazon.com/blogs/mobile/testing-mobile-apps-with-cucumber-and-appium-through-testng-on-aws-device-farm/
It looks like serenity is similar or extended from cucumber so in theory this might work.
[Edit]
Here are a few short gradle build tasks which should help to create a test package for Device Farm.
Note: this assumes that the dependencies are structured in the build.gradle file like this:
dependencies {
testCompile(
'net.serenity-bdd:serenity-junit:2.0.18',
'net.serenity-bdd:serenity-cucumber:1.9.20',
'org.assertj:assertj-core:3.11.1',
'ch.qos.logback:logback-classic:1.2.3',
'io.github.bonigarcia:webdrivermanager:3.0.0'
)
}
sample build.gradle code
//source: https://stackoverflow.com/a/27455099/8016330
task getDeps(type: Copy) {
from sourceSets.test.runtimeClasspath
// if you need this from the dependencies in the build.gradle then it should be :
// from sourceSets.main.runtimeClasspath
into 'build/libs/dependency-jars'
}
//packaging tests task which is generated from sample using gradle init
task packageTests(type: Jar) {
dependsOn getDeps
from sourceSets.test.output
classifier = 'tests'
}
//create zip archive
//source: https://stackoverflow.com/a/36883221/8016330
task zip(type: Zip) {
dependsOn packageTests
from 'build/libs/'
include '*'
include '*/*' //to include contents of a folder present inside dependency-jars directory
archiveName 'zip-with-dependencies.zip'
destinationDir(file('build/libs/'))
}
Then you should be able to create the zip file using this command:
./gradlew clean zip
Note: You'll need the clean command otherwise it will package the previous zip archive in the new zip archive.
Hth
-James