Skip to main content

LambdaTest With Selenide Automation Framework:Perform Automation Testing Faster On Cloud Selenium Grid

Selenide automation framework acts as a wrapper of Selenium WebDriver to help you write crisp and concise UI tests in Java. Selenide automatically takes care of browser shutdown, handling timeouts, test debugging, and StaleElement Exception, so you only focus on improving your business logic.

LambdaTest integration with Selenide automation framework will help you pace your test automation effort even further. Using our on-cloud Selenium Grid you will be able to run your Selenium automation tests with Selenide on more than 2000 real browsers & browser versions running across numerous devices & operating systems.

Prerequisites for running tests using Selenide automation framework#

All the code samples in this documentation can be found in the Selenide LambdaTest Repository on Image GitHub. You can either download or clone the repository to quickly run your tests.

  1. Global Dependencies

    • Make sure you have the latest Java installed in your system. For Windows, you can install it from their official website by clicking here.

    • For Linux, execute the following command in terminal.

      sudo apt-get install openjdk-8-jre
    • For Mac, Java is installed by default on Mac OS X.

    • Install Maven from their official website.

  2. LambdaTest Authentication Credentials

    Be aware of your LambdaTest authentication credentials i.e. your LambdaTest username, access key and HubURL. You need to set them up as your environment variables. You can retrieve them from your LambdaTest automation dashboard by clicking on the key icon near the help button.

  • For Windows user:
set LT_USERNAME="undefined" set LT_ACCESS_KEY="undefined"
  • For macOS/Linux user:
export LT_USERNAME="undefined" export LT_ACCESS_KEY="undefined"

Basic Setup To Run Your Selenide Automation Tests On LambdaTest#

The setup would only be of 3 simple steps.

First, you need to clone the code from our GitHub repository for Selenide test automation. You can use this repository to find all the code that we will be covering in this topic.

package com.lambdatest;
import;import;import java.util.Iterator;import java.util.Map;import java.util.concurrent.TimeUnit;
import org.json.simple.JSONObject;import org.json.simple.parser.JSONParser;import org.openqa.selenium.remote.DesiredCapabilities;import org.openqa.selenium.remote.RemoteWebDriver;import org.testng.annotations.AfterMethod;import org.testng.annotations.BeforeMethod;import org.testng.annotations.Parameters;import static com.codeborne.selenide.Selenide.$;import static;import static com.codeborne.selenide.Selenide.sleep;import static com.codeborne.selenide.Selenide.title;
import org.openqa.selenium.By;import org.testng.Assert;import org.testng.annotations.Test;
import com.codeborne.selenide.WebDriverRunner;
public class LambdaTestSetup {    public RemoteWebDriver driver;    public String status="failed";
    public static String username;    public static String accessKey;    public static String sessionId;
    @BeforeMethod(alwaysRun = true)    @Parameters(value = { "config", "environment" })    public void setUp(String config_file, String environment) throws Exception {        JSONParser parser = new JSONParser();        JSONObject config = (JSONObject) parser.parse(new FileReader("src/test/resources/conf/" + config_file));        JSONObject envs = (JSONObject) config.get("environments");
        DesiredCapabilities capabilities = new DesiredCapabilities();
        Map<String, String> envCapabilities = (Map<String, String>) envs.get(environment);        Iterator it = envCapabilities.entrySet().iterator();        while (it.hasNext()) {            Map.Entry pair = (Map.Entry);            capabilities.setCapability(pair.getKey().toString(), pair.getValue().toString());        }
        Map<String, String> commonCapabilities = (Map<String, String>) config.get("capabilities");        it = commonCapabilities.entrySet().iterator();        while (it.hasNext()) {            Map.Entry pair = (Map.Entry);            if (capabilities.getCapability(pair.getKey().toString()) == null) {                capabilities.setCapability(pair.getKey().toString(),                        (pair.getValue().toString().equalsIgnoreCase("true")                                || (pair.getValue().toString().equalsIgnoreCase("false"))                                        ? Boolean.parseBoolean(pair.getValue().toString())                                        : pair.getValue().toString()));            }        }        capabilities.setCapability("name", this.getClass().getName());
        username = System.getenv("LT_USERNAME");        if (username == null) {            username = (String) config.get("user");        }
        accessKey = System.getenv("LT_ACCESS_KEY");        if (accessKey == null) {            accessKey = (String) config.get("key");        }
        driver = new RemoteWebDriver(                new URL("http://" + username + ":" + accessKey + "@" + config.get("server") + "/wd/hub"), capabilities);        driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);        sessionId = driver.getSessionId().toString();
        WebDriverRunner.setWebDriver(driver);    }
    @Test    public void test() throws Exception {
        Assert.assertEquals(title(), "LambdaTest - Google Search");
        status = "passed";    }
    @AfterMethod(alwaysRun = true)    public void tearDown() throws Exception {        driver.executeScript("lambda-status="+status);        driver.quit();    }

Second, make sure to install the mandatory Selenium dependencies for Maven by running the below command.

mvn compile

Third, and last, you would need to update the *.conf.json files inside the directory src/test/resources/conf with your LambdaTest Username & Access Key.

Executing Tests using Selenide Automation Framework#

If you wish to run a single test, execute the below command.

mvn test -P single

If you wish to run a complete test suite, execute the below command.

mvn test -P suite

Executing Parallel Tests In Selenide Automation Framework#

One of the most important features of LambdaTest Selenium grid is the ability to run your test cases in parallel. What that means is that if you have more than one concurrent session, you can run your test cases on more than one machine at a time, which greatly cuts down your test times. To put it in perspective, if you have 100 test cases each with an average run time of 1 minute, without parallel testing it would take 100 minutes to execute. However, with 2 concurrent sessions, you can run 2 test cases in parallel at a time and can cut down the build's test time to 50 minutes. With four concurrent sessions, it would cut down to 25 minutes. With eight, well you got the picture.

mvn test -P parallel

Want to calculate how many parallel sessions you need? You can find the answer using our Concurrency Calculator.

Test Your Locally Hosted Selenide Tests With LambdaTest#

To help you perform cross browser testing of your locally stored web pages, LambdaTest provides an SSH(Secure Shell) tunnel connection with the name LambdaTest Tunnel. With LambdaTest Tunnel, you can execute a test of your locally hosted tests using Selenide test automation framework on cloud to perform automated cross browser testing on 2000+ browsers offered by Selenium Grid on LambdaTest. So you make sure how well your changes look, even before your customers. Curious to know more about LambdaTest Tunnel?

Follow our documentation on LambdaTest Tunnel to know it all. OS specific instructions to download and setup tunnel binary can be found at the following links.

Download the binary file of:

Once, the tunnel is successfully set up. You can add the below code to your capabilities for testing internal servers on your network.

//Tunnel Capability"tunnel": true

Fast track your automated cross browser testing process with Selenide + LambdaTest integration. Happy testing!

Last updated on