Serenity BDD is an open-source framework that enables you to write cleaner and maintainable tests faster. It provides support for automated web testing. It lets you generate comprehensive test reports, tracks your automated tests, keeps project status tabs, and creates more versatile and easy-to-maintain tests.
This document will help you run Serenity automation tests on LambdaTest cloud Selenium Grid. LambdaTest enables you to run your Serenity automated tests across 2000+ real browsers for desktop & mobile combination.
This documentation will help you in:
Note: Clone the Serenity Github Repository.
Before starting running your Selenium tests with Serenity, ensure you have the following things installed.
1 2 3 4 5 |
<dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-core</artifactId> <version>${serenity.version}</version> </dependency> |
You can install it by running the following command in the terminal.
1 |
mvn install |
serenity.properties
file with your LambdaTest Username and Access Key.
1 2 |
set LT_USERNAME="YOUR_USERNAME" set LT_ACCESS_KEY="YOUR ACCESS KEY" |
1 2 |
export LT_USERNAME="YOUR_USERNAME" export LT_ACCESS_KEY="YOUR ACCESS KEY" |
To run your first Serenity Test on LambdaTest Selenium Grid, let’s understand our test case scenario, the test case below checks for the word “LambdaTest” on Google and tests if the title of the resultant page is “LambdaTest-Google Search”.
1 2 3 4 5 6 |
Feature: Google's Search Functionality Scenario: Can find search results When I type query as "LambdaTest" And I submit Then I should see title "LambdaTest - Google Search" |
Following below is the GooglePage.java file for the above Test Case Scenario.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//GooglePage.java package com.lambdatest.cucumber.pages; import static org.assertj.core.api.Assertions.assertThat; import org.openqa.selenium.support.FindBy; import net.serenitybdd.core.pages.WebElementFacade; import net.thucydides.core.annotations.DefaultUrl; import net.thucydides.core.pages.PageObject; @DefaultUrl("https://www.google.com/ncr") public class GooglePage extends PageObject { @FindBy(name = "q") WebElementFacade search; @FindBy(name = "btnK") WebElementFacade searchButton; public void searchForString(String searchString) { search.sendKeys(searchString); } public void submitForm() throws Exception { searchButton.click(); Thread.sleep(5000); } public void titleShouldMatch(String matchTitle) { assertThat(this.getTitle()).containsIgnoringCase(matchTitle); } } |
Below is the LambdaTestSerenityDriver.java file that shows the integration of Serenity with LambdaTest.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
//LambdaTestSerenityDriver.java package com.lambdatest; import java.net.URL; import java.util.Iterator; import org.openqa.selenium.WebDriver; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; import net.thucydides.core.util.EnvironmentVariables; import net.thucydides.core.util.SystemEnvironmentVariables; import net.thucydides.core.webdriver.DriverSource; public class LambdaTestSerenityDriver implements DriverSource { public WebDriver newDriver() { EnvironmentVariables environmentVariables = SystemEnvironmentVariables.createEnvironmentVariables(); String username = System.getenv("LT_USERNAME"); if (username == null) { username = (String) environmentVariables.getProperty("lt.user"); } String accessKey = System.getenv("LT_ACCESS_KEY"); if (accessKey == null) { accessKey = (String) environmentVariables.getProperty("lt.key"); } String environment = System.getProperty("environment"); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability("plugin","Serenity LambdaTest Plugin"); Iterator it = environmentVariables.getKeys().iterator(); while (it.hasNext()) { String key = (String) it.next(); if (key.equals("lt.user") || key.equals("lt.key") || key.equals("lt.grid")) { continue; } else if (key.startsWith("lt_")) { capabilities.setCapability(key.replace("lt_", ""), environmentVariables.getProperty(key)); } else if (environment != null && key.startsWith("environment." + environment)) { capabilities.setCapability(key.replace("environment." + environment + ".", ""), environmentVariables.getProperty(key)); } } try { String url = "https://" + username + ":" + accessKey + "@" + environmentVariables.getProperty("lt.grid") + "/wd/hub"; return new RemoteWebDriver(new URL(url), capabilities); } catch (Exception e) { System.out.println(e); return null; } } public boolean takesScreenshots() { return false; } } |
Now run the following command in your terminal/cmd to run your Single Serenity Test on LambdaTest Grid.
1 |
mvn verify -P single |
Visit your Automation dashboard. You will find your single Serenity test is executed successfully.
Parallel Testing is among the most stimulating features of the LambdaTest Selenium Grid. You can run more than one test case concurrently through parallel testing. This means that parallel testing will allow you to run a whole range of automation test cases. So you’re running a single test scenario across multiple browsers, or you might run different test scenarios across the same browser, but with different browser versions.
To run parallel tests with Serenity,we will run single.feature
test case in four different environments Chrome, Firefox, IE, and Safari.
For ParallelChromeTest.java:
1 2 3 4 5 6 |
//Running Parallel Test On Chrome @RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/features/single.feature") public class ParallelChromeTest extends LambdaTestSerenityTest { } |
For ParallelFirefoxTest.java:
1 2 3 4 5 6 |
//Running Parallel Test On Firefox @RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/features/single.feature") public class ParallelFirefoxTest extends LambdaTestSerenityTest { } |
For ParallelIETest.java:
1 2 3 4 5 6 |
//Running Parallel Test On Internet Explorer @RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/features/single.feature") public class ParallelIETest extends LambdaTestSerenityTest { } |
For ParallelSafariTest.java:
1 2 3 4 5 6 |
//Running Parallel Test On Safari @RunWith(CucumberWithSerenity.class) @CucumberOptions(features = "src/test/resources/features/single.feature") public class ParallelSafariTest extends LambdaTestSerenityTest { } |
Now run the following command in your terminal/cmd to run your Parallel Serenity Test on LambdaTest Grid.
1 |
mvn verify -P parallel |
Visit your Automation dashboard. You will find your Parallel Serenity tests are executed successfully.
Note: Get your test coverage by using our Concurrency Test Calculator to know how many concurrent sessions you need.
With Lambda Tunnel, you can perform Serenity tests of your locally hosted websites across 2000+ browsers/OS combinations running on real devices and operating systems. Lambda Tunnel allows you to test your website or web-pages for cross-browser compatibility before making them live.
Lambda Tunnel has several protocols including Web Socket, HTTPS, SSH(Encrypted Shell), etc to help you develop a secure and specialized tunnel connection between your device and LambdaTest cloud servers over corporate firewalls.
For more information, visit our Lambda Tunnel documentation.
To perform the Serenity test you would have to download the tunnel binary. You can find OS-specific instructions to download and set up tunnel binary at the following links.
You would need to update the serenity.properties
file by setting the tunnel capibility lt_tunnel
to true
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
//serenity.properties webdriver.timeouts.implicitlywait = 5000 serenity.use.unique.browser = false serenity.dry.run=false #serenity.take.screenshots=AFTER_EACH_STEP lt.user=salmank lt.key=123456789abcdefghijklmnopqrstuv lt.grid=hub.lambdatest.com #You can add more capability with a prefix 'lt_' as below #For example to use lt_network as true use below capability lt_build=Serenity-Selenium-Sample lt_debug=true lt_console=false lt_visual=false lt_tunnel=true //tunnel capibility #You can add more capability with a prefix 'environment.{environment}.' as below #Check valid capabilities here - https://www.lambdatest.com/capabilities-generator/ environment.single.browser=Chrome environment.single.browserVersion=78 environment.single.platform=Windows 10 environment.parallel_1.browser=Chrome environment.parallel_1.browserVersion=78 environment.parallel_1.platform=Windows 10 environment.parallel_2.browser=firefox environment.parallel_2.browserVersion=68 environment.parallel_2.platform=Windows 8.1 environment.parallel_3.browser=Safari environment.parallel_3.browserVersion=12 environment.parallel_3.platform=MacOS Mojave environment.parallel_4.browser=Internet Explorer environment.parallel_4.browserVersion=11 environment.parallel_4.platform=Windows 7 #environment.parallel_5.deviceName=Galaxy S10 |
Now run the following command in your terminal/cmd to run your local Serenity Test.
1 |
mvn test -P local |
Visit your Automation dashboard. You will find your Local Serenity tests are executed successfully. You can find the blue tunnel icon on the right corner that ensures the tunnel is active.
That’s all! You have successfully executed your Serenity Automation Tests. In case you come across any doubts, feel free to reach out through our 24/7 chat support or you can also drop a mail to support@lambdatest.com.
Happy testing!