How to run Serenity BDD tests in Edge Browser

HOME

Serenity BDD has strong WebDriver integration and manages WebDriver instances. It is not needed to create or close the WebDriver instance of the Serenity Tests.

Serenity uses a library WebDriver Manager, which manages the driver for us. We don’t need to explicitly download and configure the WebDriver binaries for us.

webdriver {
  capabilities {
    browserName = "MicrosoftEdge"
    "ms:edgeOptions" {
      args = ["test-type", "ignore-certificate-errors", "headless",
        "incognito", "disable-infobars", "disable-gpu", "disable-default-apps", "disable-popup-blocking"]
    }
  }
}

edge {
    webdriver {
      capabilities {
        browserName = "MicrosoftEdge"
        "ms:edgeOptions" {
          args = ["start-maximized", "test-type", "ignore-certificate-errors",
            "incognito", "disable-infobars", "disable-gpu", "disable-default-apps", "disable-popup-blocking"]
        }
      }
    }
  }

@Managed annotation in Serenity will manage the WebDriver instance, including opening the appropriate driver at the start of each test, and shutting it down when the test is finished. @Managed provides an option for the user to select the WebDriver driver to the run the tests in it. The possible values are firefox, chrome, iexplorer, phantomjs, appium, safari, edge, and htmlunit. There are multiple ways to manage the WebDriver. One of the way is shown below:

In the below program, the tests are running on the Edge browser. The driver name is mentioned with @Managed annotation.

import net.serenitybdd.annotations.Managed;
import net.serenitybdd.annotations.Steps;
import net.serenitybdd.annotations.Title;
import net.serenitybdd.core.Serenity;
import net.serenitybdd.junit.runners.SerenityRunner;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(SerenityRunner.class)
public class EdgeTests {

    private String userName;
    private String passWord;
    private String errorMessage;

    @Managed(driver = "edge")
    WebDriver driver;

    @Steps
    NavigateActions navigate;

    @Steps
    StepLoginPage loginPage;


    @Test
    @Title("Login to application with invalid credential generates error message")
    public void invalidCredentials() {

        // Given
        navigate.toTheHomePage();

        // When
        loginPage.inputUserName("Admin");
        loginPage.inputPassword("admin");
        loginPage.clickLogin();

        // Then
        Serenity.reportThat("Passing invalid credentials generates error message",
                () -> assertThat(assertThat(loginPage.errorMessage()).isEqualToIgnoringCase("Invalid Credentials")));

    }

}

NavigateActions

import net.serenitybdd.annotations.Step;
import net.serenitybdd.core.steps.UIInteractionSteps;

public class NavigateActions extends UIInteractionSteps {

    @Step
    public void toTheHomePage() {
        openPageNamed("loginForm");
    }
}

import net.serenitybdd.annotations.Step;
import net.serenitybdd.core.pages.PageObject;
import net.serenitybdd.core.pages.WebElementFacade;
import org.openqa.selenium.support.FindBy;

public class StepLoginPage extends PageObject {

    @FindBy(name = "username")
    WebElementFacade username;

    @FindBy(name = "password")
    WebElementFacade password;

    @FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[3]/button")
    WebElementFacade submitButton;

    @FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/div/div[1]/div[1]/p")
    WebElementFacade errorMessage;

    @FindBy(xpath = "//*[@id='app']/div[1]/div/div[1]/div/div[2]/div[2]/form/div[4]/p")
    WebElementFacade linkText;

    @Step("Enter Username")
    public void inputUserName(String userName) {
        username.sendKeys((userName));
    }

    @Step("Enter Password")
    public void inputPassword(String passWord) {
        password.sendKeys((passWord));
    }

    @Step("Click Submit Button")
    public void clickLogin() {
        submitButton.click();
    }

    @Step("Error Message on unsuccessful login")
    public String errorMessage() {
        String actualErrorMessage = errorMessage.getText();
        return actualErrorMessage;
    }

    @Step("Click Forget Password Link")
    public void clickForgetPasswordLink() {
        linkText.click();

        System.out.println("Clicked on Forgot Password Link");
    }

}

Congratulations!! We are able to run the Serenity tests using edge browser.

Serenity BDD Tutorials

HOME

Serenity BDD is an open-source library that aims to make the idea of living documentation a reality.
Serenity BDD helps you write cleaner and more maintainable automated acceptance and regression tests faster. Serenity also uses the test results to produce illustrated, narrative reports that document and describe what your application does and how it works. Serenity tells you not only what tests have been executed, but more importantly, what requirements have been tested

Basics of Serenity

Chapter 1 How to run Serenity BDD tests in Chrome Browser
Chapter 2 How to run Serenity BDD tests in Edge Browser
Chapter 3 Testing of Web Application using Serenity with JUnit4
Chapter 4 Integration of Serenity with JUnit5
Chapter 5 Manual Tests in Serenity with JUnit5
Chapter 6 Integration of Serenity with Rest Assured
Chapter 7 Data Driven Tests in Serenity with JUnit
Chapter 8 Data Driven Tests using CSV file in Serenity
Chapter 9 Implicit Wait in Serenity
Chapter 10 Explicit Wait in Serenity

Serenity with Cucumber

Chapter 1 Serenity BDD with Cucumber and JUnit4 for Web Application
Chapter 2 Serenity BDD with Cucumber for SpringBoot Application
Chapter 3 Serenity BDD with Cucumber and Rest Assured
Chapter 4 Testing of SpringBoot REST Application using Rest Assured for GET Method
Chapter 5 Serenity Report for Web Application with Cucumber6 and Junit
Chapter 6 Integration of Serenity with Cucumber and JUnit5
 Chapter 7 Testing of SpringBoot Application with Serenity BDD, Cucumber and JUnit5 – NEW

Serenity Reports

Chapter 1 Serenity Report for Web Application with Cucumber6 and Junit
Chapter 2 Serenity Emailable HTML Report
Chapter 3 Serenity Emailable Report in Gradle
Chapter 4 How to report Manual Tests in Serenity Report
Chapter 5 How to attach Test Evidence to Manual Tests in Serenity Report
Chapter 6 How to manage screenshots in Serenity Report
Chapter 7 How to generate Serenity Report in customized path

Serenity with Gradle

Chapter 1 Serenity BDD with Gradle and Cucumber for Web Application
Chapter 2 Serenity BDD with Cucumber and Rest Assured in Gradle

Serenity with CI/CD

Chapter 1 Serenity with Jenkins
Chapter 2 How to create Jenkins pipeline for Serenity tests
Chapter 3 How to run Serenity tests with GitHub Actions
Chapter 4 Run Serenity Tests in GitLab CI/CD

Parallel Testing

Chapter 1 Parallel Execution of Cucumber with Serenity and JUnit5