Skip to content

Commit

Permalink
Updated sample code to JUnit 5
Browse files Browse the repository at this point in the history
  • Loading branch information
wakaleo committed Nov 8, 2024
1 parent ae5143f commit 74269d1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 104 deletions.
80 changes: 51 additions & 29 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<name>Sample Serenity BDD project using JUnit</name>
<name>Sample Serenity BDD project using JUnit 5</name>

<properties>
<serenity.version>3.3.2</serenity.version>
<serenity.maven.version>3.3.2</serenity.maven.version>
<serenity.version>4.2.7</serenity.version>
<junit5.version>5.11.3</junit5.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<encoding>UTF-8</encoding>
<tags></tags>
<parallel.tests>4</parallel.tests>
<webdriver.base.url></webdriver.base.url>
</properties>
<dependencies>
Expand All @@ -25,6 +24,12 @@
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit5</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
Expand All @@ -37,32 +42,40 @@
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-ensure</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-screenplay-webdriver</artifactId>
<version>${serenity.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<version>1.2.11</version>
</dependency>
<!-- JUNIT 5 DEPENDENCY-->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<version>3.22.0</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand All @@ -71,14 +84,14 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<version>3.2.5</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<version>3.2.5</version>
<configuration>
<includes>
<include>**/*Test.java</include>
Expand All @@ -88,10 +101,8 @@
</includes>
<systemPropertyVariables>
<webdriver.base.url>${webdriver.base.url}</webdriver.base.url>
<junit.jupiter.extensions.autodetection.enabled>true</junit.jupiter.extensions.autodetection.enabled>
</systemPropertyVariables>
<parallel>classes</parallel>
<threadCount>${parallel.tests}</threadCount>
<forkCount>${parallel.tests}</forkCount>
</configuration>
<executions>
<execution>
Expand All @@ -105,18 +116,22 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<version>3.12.1</version>
<configuration>
<source>8</source>
<target>8</target>
<source>17</source>
<target>17</target>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>net.serenity-bdd.maven.plugins</groupId>
<artifactId>serenity-maven-plugin</artifactId>
<version>${serenity.maven.version}</version>
<version>${serenity.version}</version>
<configuration>
<tags>${tags}</tags>
<tags>${tags}</tags>
<reports>single-page-html</reports>
</configuration>
<executions>
<execution>
Expand All @@ -127,7 +142,14 @@
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-single-page-report</artifactId>
<version>${serenity.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
</project>
17 changes: 0 additions & 17 deletions src/test/java/serenityswag/authentication/LoginActions.java

This file was deleted.

31 changes: 0 additions & 31 deletions src/test/java/serenityswag/authentication/User.java

This file was deleted.

32 changes: 14 additions & 18 deletions src/test/java/serenityswag/authentication/WhenLoggingOn.java
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
package serenityswag.authentication;

import net.serenitybdd.core.Serenity;
import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Steps;
import org.junit.Test;
import org.junit.runner.RunWith;
import net.serenitybdd.annotations.Managed;
import net.serenitybdd.core.annotations.findby.By;
import net.serenitybdd.junit5.SerenityJUnit5Extension;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.openqa.selenium.WebDriver;
import serenityswag.inventory.InventoryPage;

import static org.assertj.core.api.Assertions.assertThat;
import static serenityswag.authentication.User.STANDARD_USER;

@RunWith(SerenityRunner.class)
@ExtendWith(SerenityJUnit5Extension.class)
public class WhenLoggingOn {

@Managed
WebDriver driver;

@Steps
LoginActions login;

InventoryPage inventoryPage;

@Test
public void usersCanLogOnViaTheHomePage() {

login.as(STANDARD_USER);
driver.get("https://www.saucedemo.com");

driver.findElement(By.cssSelector("[data-test='username']")).sendKeys("standard_user");
driver.findElement(By.cssSelector("[data-test='password']")).sendKeys("secret_sauce");
driver.findElement(By.cssSelector("[data-test='login-button']")).click();

// Should see product catalog
Serenity.reportThat("The inventory page should be displayed with the correct title",
() -> assertThat(inventoryPage.getHeading()).isEqualToIgnoringCase("Products")
);

assertThat(driver.findElement(By.cssSelector(".title")).getText())
.isEqualToIgnoringCase("Products");
}
}
9 changes: 0 additions & 9 deletions src/test/java/serenityswag/inventory/InventoryPage.java

This file was deleted.

0 comments on commit 74269d1

Please sign in to comment.