Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/cmccarthyirl/spring-cucumber-testng-parallel-test-harness

This project executes Cucumber tests sequentially or in parallel using TestNG, Spring, Cucumber, Java, Logback and Extent Reports to provide a basic test harness. Rest Assured and Selenium test examples are provided
https://github.com/cmccarthyirl/spring-cucumber-testng-parallel-test-harness

allure allure-reports cucumber extent-report extentreports github-actions io-cucumber java-17 logging parallel rest-api rest-assured rest-assured-framework selenium spark-reports spring-boot test-automation test-framework test-harness testng

Last synced: about 1 month ago
JSON representation

This project executes Cucumber tests sequentially or in parallel using TestNG, Spring, Cucumber, Java, Logback and Extent Reports to provide a basic test harness. Rest Assured and Selenium test examples are provided

Awesome Lists containing this project

README

        

# Cucumber Automated Testing Framework

[![run](https://github.com/cmccarthyIrl/spring-cucumber-testng-parallel-test-harness/actions/workflows/run.yml/badge.svg)](https://github.com/cmccarthyIrl/spring-cucumber-testng-parallel-test-harness/actions/workflows/run.yml)

# Index

Start

| Maven
| Quickstart |

Run

| TestNG
| Command Line
| IDE Support
| Java JDK
| Troubleshooting |

Report

| Configuration
| Environment Switching
| Spark HTML Reports
| Logging |

Advanced

| Before / After Hooks
| JSON Transforms
| Contributing |

# Maven

The Framework uses [Spring Boot Test](https://spring.io/guides/gs/testing-web/), [Cucumber](https://cucumber.io/)
, [Rest Assured](https://rest-assured.io/) and [Selenium](https://www.selenium.dev/) client implementations.

Spring ``:

```xml

...

org.springframework.amqp
spring-rabbit
${spring-rabbit.version}


org.springframework.boot
spring-boot-starter-test


org.springframework
spring-test

...

```

Cucumber & Rest Assured ``:

```xml

...

io.rest-assured
rest-assured
${restassured.version}


io.cucumber
cucumber-java
${cucumber.version}


io.cucumber
cucumber-spring
${cucumber.version}


io.cucumber
cucumber-testng
${cucumber.version}

...

```

Selenium ``:

```xml

...

org.seleniumhq.selenium
selenium-java
${selenium-version}


org.seleniumhq.selenium
selenium-server
${selenium-version}

...

```

# Quickstart

- [Intellij IDE](https://www.jetbrains.com/idea/) - `Recommended`
- [Java JDK 17](https://jdk.java.net/java-se-ri/11)
- [Apache Maven](https://maven.apache.org/docs/3.6.3/release-notes.html)

# TestNG

By using the [TestNG Framework](https://junit.org/junit4/) we can utilize the [Cucumber Framework](https://cucumber.io/)
and the `@CucumberOptions` Annotation Type to execute the `*.feature` file tests

> Right click the `WikipediParallelRunner` class and select `Run`

```java

@CucumberOptions(
features = {
"src/test/resources/feature"
},
plugin = {
"pretty",
"json:target/cucumber/report.json",
"com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"
})
public class WikipediaParallelRunnerTest extends AbstractTestNGCucumberTests {

@Override
@DataProvider(parallel = true)
public Object[][] scenarios() {
return super.scenarios();
}

}
```

# Command Line

Normally you will use your IDE to run a `*.feature` file directly or via the `*Test.java` class. With the `Test` class,
we can run tests from the command-line as well.

Note that the `mvn test` command only runs test classes that follow the `*Test.java` naming convention.

You can run a single test or a suite or tests like so :

```
mvn test -Dtest=WikipediaParallelRunnerTest
```

Note that the `mvn clean install` command runs all test Classes that follow the `*Test.java` naming convention

```
mvn clean install
```

# IDE Support

To minimize the discrepancies between IDE versions and Locales the `` is set to `UTF-8`

```xml

...
UTF-8
UTF-8
...

```

# Java JDK

The Java version to use is defined in the `maven-compiler-plugin`

```xml

...


...

org.apache.maven.plugins
maven-compiler-plugin

17
17


...


...

```

# Configuration

The `AbstractTestDefinition` class is responsible for specifying each Step class as `@SpringBootTest` and
its `@ContextConfiguration`

```java

@ContextConfiguration(classes = {FrameworkContextConfiguration.class})
@SpringBootTest
public class AbstractTestDefinition {
}
```

The `FrameworkContextConfiguration` class is responsible for specifying the Spring `@Configuration`, modules to scan,
properties to use etc

```java

@EnableRetry
@Configuration
@ComponentScan({
"com.cmccarthy.api", "com.cmccarthy.common",
})
@PropertySource("application.properties")
public class FrameworkContextConfiguration {
}
```

# Environment Switching

There is only one thing you need to do to switch the environment - which is to set `` property in the
Master POM.

> By default, the value of `spring.profiles.active` is defined in the `application.properties` file which inherits its
> value from the Master POM property ``

```xml

...

prod

true


prod


...

```

You can then specify the profile to use when running Maven from the command line like so:

```
mvn clean install -DactiveProfile=github-headless
```

Below is an example of the `application.properties` file.

```properties
spring.profiles.active=@activatedProperties@
```

# Extent Reports

The Framework uses [Extent Reports Framework](https://extentreports.com/) to generate the HTML Test Reports

The example below is a report generated automatically by Extent Reports open-source library.

# Allure Reports

The Framework uses [Allure Reports](https://docs.qameta.io/allure/) to generate the HTML Test Reports

The example below is a report generated by Allure Reports open-source library.

To generate the above report navigate to the root directory of the module under test and execute the following command

`mvn allure:serve` or `mvn allure:generate` (for an offline report)

# Logging

The Framework uses [Log4j2](https://logging.apache.org/log4j/2.x/) You can instantiate the logging service in any Class
like so

```java
private final Logger logger=LoggerFactory.getLogger(WikipediaPageSteps.class);
```

you can then use the logger like so :

```java
logger.info("This is a info message");
logger.warn("This is a warning message");
logger.debug("This is a info message");
logger.error("This is a error message");
```

# Before / After Hooks

The [Logback](http://logback.qos.ch/) logging service is initialized from the `Hooks.class`

As the Cucumber Hooks are implemented by all steps we can configure the `@CucumberContextConfiguration` like so :

```java

@CucumberContextConfiguration
public class Hooks extends AbstractTestDefinition {

private static boolean initialized = false;
private static final Object lock = new Object();

@Autowired
private HookUtil hookUtil;
@Autowired
private DriverManager driverManager;

@Before
public void beforeScenario(Scenario scenario) {
synchronized (lock) {
if (!initialized) {
if (!driverManager.isDriverExisting()) {
driverManager.downloadDriver();
}
initialized = true;
}
}
driverManager.createDriver();
}

@After
public void afterScenario(Scenario scenario) {
hookUtil.endOfTest(scenario);
WebDriverRunner.closeWebDriver();
}
}
```

# JSON Transforms

[Rest Assured IO](https://rest-assured.io/) is used to map the `Response` Objects to their respective `POJO` Classes

```xml

io.rest-assured
rest-assured
3.0.0

```

# Troubleshooting

- Execute the following commands to resolve any dependency issues
1. `cd ~/install directory path/spring-cucumber-testng-parallel-test-harness`
2. `mvn clean install -DskipTests`

# Contributing

Spotted a mistake? Questions? Suggestions?

[Open an Issue](https://github.com/cmccarthyIrl/spring-cucumber-testng-parallel-test-harness/issues)