Execute Web Tests on LambdaTest cloud

Pre-Requisite

Make sure you have a LambdaTest account. Please refer here

LambdaTest Configuration

To run a test on LambdaTest, we need the respective account’s UserName and AccessKey.

Where to find it?

  1. Login into LambdaTest Dashboard

  2. Click on the profile icon and choose Account Settings. Open Password & Security Tab.

  3. Get the Username and Access Key

Create a cloud configuration file

Create lambdatest.json file under the cloud_config folder

lambdatest.json

{
 "username": "<provide your username>",
 "accessKey": "<provide your access key>",
 "hub": "hub.lambdatest.com"
}

Specify LambdaTest as a hub in configuration

Open web.remote.properties file. Or you could choose to create a new configuration file most suitable to you.

add cloud.config.dir and web.hub property

# cloud provider eg: browserstack | lambdatest | etc
web.hub: lambdatest

Execute tests

Execute tests by specifying the config

./gradlew clean runWebTests -Dconfig=web.remote

Monitor the “Web Automation” page in LambdaTest 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.

  1. Use this syntax "${env: <arg name>}" for the required fields in the lambdatest.json file, provided an example below:
{
  "username": "${env:LAMBDATEST_USERNAME}",
  "accessKey": "${env:LAMBDATEST_ACCESS_KEY}",
  "hub": "hub.lambdatest.com"
}
  1. Pass these system properties to Gradle task:
    systemProperty "config", System.getProperty("config")
    systemProperty "LAMBDATEST_USERNAME", System.getProperty("LAMBDATEST_USERNAME")
    systemProperty "LAMBDATEST_ACCESS_KEY", System.getProperty("LAMBDATEST_ACCESS_KEY")
  1. The complete Gradle task
task runWebTests(type: Test) {
    filter {
        excludeTestsMatching "*.mobile.*"
        excludeTestsMatching "*.api.*"
        excludeTestsMatching "*.db.*"
    }
    
    systemProperty "config", System.getProperty("config")
    systemProperty "LAMBDATEST_USERNAME", System.getProperty("LAMBDATEST_USERNAME")
    systemProperty "LAMBDATEST_ACCESS_KEY", System.getProperty("LAMBDATEST_ACCESS_KEY")

    outputs.upToDateWhen { false }
    useTestNG {
        parallel = "methods"
        threadCount Integer.parseInt(System.getProperty("sessions", "2"))
        includeGroups System.getProperty("tags", "web")
        testLogging.showStandardStreams = true
        useDefaultListeners true
        outputDirectory = file("$buildDir/" + System.getProperty('tags', 'NONE'))
    }
}

Execute the test in terminal or CI as below:

./gradlew runWebTests -Dconfig=web.remote -DLAMBDATEST_USERNAME=<username> -DLAMBDATEST_ACCESS_KEY=<access_key>