loading...

Serenity running in parallel - Serenity part 4/4

cuongld2 profile image cuongld2 Updated on ・3 min read

I'm back with the last part of Serenity, you can definitely check the previous parts in here:
Serenity part 1
Serenity part 2
Serenity part 3

In this blog post, we will go through the setup step for how to run serenity parallel tests with cucumber using maven fail safe plugin with cucumber-jvm-parallel-plugin.

You can definitely check the serenity book for details.

What you will need to do is simply this:

1.POM file:

maven failsafe plugin defined for running parallel test for each test class.

<plugin>
         <artifactId>maven-failsafe-plugin</artifactId>
         <version>2.18</version>
                <configuration>
                    <parallel>classes</parallel>
                    <threadCount>2</threadCount>
                </configuration>
</plugin>

<plugin>
                <groupId>com.github.temyers</groupId>
                <artifactId>cucumber-jvm-parallel-plugin</artifactId>
                <version>4.2.0</version>
                <executions>
                    <execution>
                        <id>generateRunners</id>
                        <phase>generate-test-sources</phase>
                        <goals>
                            <goal>generateRunners</goal>
                        </goals>
                        <configuration>
                            <!-- Mandatory -->
                            <!-- List of package names to scan for glue code. -->
                            <glue>
                                <package>ui.cucumber</package>
                            </glue>
                            <parallelScheme>FEATURE</parallelScheme>
                        </configuration>
                    </execution>
                </executions>
</plugin>

cucumber jvm parallel plugin to generate runners when you execute test.
Without it , the parallel test won't work.

2.Features file defined for the test:
In this test we will run the test for facebook login page and qcCoccoc login page.

  • feature file for facebook login
  @Login
  Scenario Outline: User login successfully with correct
    Given Navigate to facebook login page
    When Login facebook with '<phone>' and '<password>'
    Then Should navigate to facebook homepage
    Examples:
      |phone|password|
      |xxxxx|xxxxxx|
  • feature file for qcCoccoc login

  @Login
  Scenario Outline: Login successfully with email and password
    Given Navigate to quang cao coc coc login site
    When Login with '<email>' and '<password>'
    Then Should navigate to home page site
    Examples:
      |email|password|
      |xxxxx|xxxxx|

3.Tests defined in cucumber format:

  • For facebook login page:
@Steps
    private pages.facebook.LoginPage loginPage_facebook;

    @Given("^Navigate to facebook login page$")
    public void navigateToFacebookLoginPage() {

        loginPage_facebook.navigate();

    }


    @When("^Login facebook with '(.*)' and '(.*)'$")
    public void loginFacebookWithPhoneAndPassword(String phone, String password) {

        loginPage_facebook.login(phone,password);

    }

    @Then("^Should navigate to facebook homepage$")
    public void shouldNavigateToFacebookHomepage() {

        WebDriverWait wait = new WebDriverWait(getDriver(),2);
        wait.until(ExpectedConditions.not(ExpectedConditions.urlContains("login")));
        softAssertImpl.assertAll();

    }

First user navigate to facebook login page, then after fill in the credential details, we will assert whether the url still contain "login"
text or not.

-For qcCoccoc login page, the step is pretty the same:

public class LoginPage extends BaseTest {

    @Steps
    private pages.qcCocCoc.LoginPage loginPage_pageobject;


    @cucumber.api.java.en.Given("^Navigate to quang cao coc coc login site$")
    public void navigateToQuangCaoCocCocLoginSite() {

        loginPage_pageobject.open();

    }

    @When("^Login with '(.*)' and '(.*)'$")
    public void loginWithEmailAndPassword(String email, String password) {

        loginPage_pageobject.login(email,password);

    }

    @Then("^Should navigate to home page site$")
    public void shouldNavigateToHomePageSite() {
        WebDriverWait wait = new WebDriverWait(getDriver(),2);
        wait.until(ExpectedConditions.urlContains("welcome"));
        softAssertImpl.assertAll();

    }

    @Then("^Should prompt with '(.*)'$")
    public void shouldPromptWithErrormessage(String errorMessage) {

        softAssertImpl.assertThat("Verify message error",loginPage_pageobject.getMessageError().contains(errorMessage),true);
        softAssertImpl.assertAll();

    }
}

4.Run the tests:

  • To run the test simply using mvn command line

mvn clean verify -Dcucumber.options="--tags @Login"

This will run the cucumber test has tag @Login

  • To run only the facebook test with serenity report, run command line:

mvn clean verify -Dtest=ui.cucumber.facebook.AcceptanceTest serenity:aggregate

Alt Text

You can check out the source code in github

Leave a heart or comment if you have any!!

Peace!!!

Notes: If you feel this blog help you and want to show the appreciation, feel free to drop by :

This will help me to contributing more valued contents.

Discussion

pic
Editor guide
Collapse
raydebug profile image
raydebug

Can you show an example for running Serenity UI testing in Jenkins which starts the springboot application in localhost(Jenkins)