2

I want to use AWS Device Farm for mobile app testing but I cannot see any support for Appium with Serenity BDD & Gradle as per their documentation.

I have seen AWS device farm is supporting the below

Test Type Configuration

Appium JUnit
Appium TestNG
Built-in: Explorer
Built-in: Fuzz
Calabash

Can anyone confirm if the device farm supports Appium with Serenity BDD & Gradle? I couldn't find this answer in their forum.

If it supports, could also share some examples please?

Thanks

Vamc

vamc
  • 125
  • 1
  • 2
  • 13

2 Answers2

2

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

jmp
  • 2,175
  • 2
  • 17
  • 16
  • Thank you for your answer but I have seen that on that link you shared has cucumber with testNG which is with maven. I have serenity with gradle which doesn't work for me as I have tried using the device farm config on build.gradle and device farm plugin was not supported. – vamc Sep 19 '18 at 15:13
  • So it's more a matter of how to package the tests or is it an issue with the Gradle plugin? It should be possible to package the test using Gradle but I would need to spend some more time to author a solution. Also looks like Gradle has automatic conversion https://guides.gradle.org/migrating-from-maven/#automated_conversion So we could run Gradle init in a maven project and that might create the tasks needed – jmp Sep 21 '18 at 03:00
  • Looks like its an issue with gradle plugin as when I rebuild the project, throws an error `The android or android-library has not been applied yet Open File` where open file is a link and on clicking navigates me to the `apply plugin: 'devicefarm'` line on build.gradle and also I'm using serenity framework with gradle which uses serenity-junit and serenity-cucumber and I don't use `@Test` in my scripts. Just was unclear from the comment, as my project is already a gradle project and you are saying to create a maven project and run gradle init right? – vamc Sep 21 '18 at 08:58
  • I thought that might be an option yes. However, sounds like it is an issue with the plugin. I'll try to experiment with it more and let you know what I find. – jmp Sep 21 '18 at 12:22
  • @vamc I just updated the answer(sorry for the delay). Let me know if that helps – jmp Dec 02 '18 at 19:32
  • Thank you for updating the solution with tasks. I can built zip file using the tasks shared here but AWS device farm needs dependencies folder in it which doesn't add up in the zip folder. – vamc Dec 05 '18 at 09:12
  • even though changing to `from sourceSets.main.runtimeClasspath` but still, dependencies are not zipped. – vamc Dec 05 '18 at 10:02
  • If the dependencies are in testCompile then you'll need to use `from sourceSets.test.runtimeClasspath` otherwise if they're in dependencies you'll need to use `from sourceSets.main.runtimeClasspath` – jmp Dec 05 '18 at 12:41
  • @vamc does that make sense? – jmp Dec 05 '18 at 22:34
0

From the above answer, I was able to build zip file without dependencies folder so I struggled to find out how to build zip file with dependencies as device farm expected. Here is the way to add dependencies in build.gradle file and with above tasks(Copied from above), we can see dependencies folder added up in the zip file.

    dependencies {    
            runtime group: 'net.serenity-bdd', name: 'serenity-junit', version: '2.0.18'
            runtime group: 'net.serenity-bdd', name: 'serenity-cucumber', version: '1.9.20'
            runtime group: 'net.serenity-bdd', name: 'serenity-reports-configuration', version: '1.9.43'
            runtime group: 'org.assertj', name: 'assertj-core', version: '3.11.1'
            runtime group: 'ch.qos.logback', name: 'logback-classic', version: '1.2.3'
            runtime group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.0.0' 
        }

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'
    )
}

task getDeps(type: Copy) {
    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
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/'))
}
vamc
  • 125
  • 1
  • 2
  • 13