CucumberJVM template project for running tests in parallel.
This project was based on Selenium-Maven-Template and support for CucumberJVM was added
- One "Runner" class per thread (use profile
parallel
). By "Runner" class is meant RunCukesCheeseTest class in this example.- NOTE - in order to use this approach, you will need to create separate "runner" class per one thread. Tests belonging to one "runner" class will be executed sequentially.
- More on this read here.
- Using cucumber-jvm-parallel-plugin (use profile
parallelPlugin
)- cucumber-jvm-parallel-plugin will automatically generates "runner" classes.
- More on this read here.
./mvnw clean verify -P [nogrid OR grid],[parallel OR parallelPlugin] -Dthreads=[number of parallel threads]
- parallel - when using separate "runner" class per one thread
- parallelPlugin - uses cucumber-jvm-parallel-plugin. Automatically creates separate "runner" class per one thread
- nogrid - execute tests locally
- grid - execute tests on Selenium Grid. Grid Hub can be set in pom by using
seleniumGridUrl
property or in ApplicationProperties file - Thread count can be set via
-Dthreads
argument
For example, invoking
./mvnw clean verify -P parallelPlugin,nogrid -Dthreads=3 -Dbrowser=chrome
will execute tests in parallel 3 threads on local machine and using cucumber-jvm-parallel-plugin plugin. In addition, -Dbrowser
setting will set browser to Chrome.
OR
./mvnw clean verify -DremoteDriver=false -P onerunner -Dthreads=3 -Dbrowser=chrome -DuseTestcontainers=false -DenableVideo=false -DenableVNC=false
Following settings can be changed in lv.iljapavlovs.cucumber.config.ApplicationProperties.java
or overriden by from command line by providing -D{configuration key}={value}
Configuration key | Description |
---|---|
env | environment name |
appUrl | AUT URL |
browser | Browser to use. Available options - chrome, firefox, safari, edge, ie, chrome_headless, firefox_headless |
proxyEnabled | is proxy enabled for Selenium (boolean) |
proxyHost | proxy host |
proxyPort | proxy port |
remoteDriver | should tests be executed on Selenium Grid (boolean) |
seleniumGridRetries | RemoteWebdriver initialization retry count |
seleniumGridUrl | Selenium Grid Hub URL |
waitShortSeconds | timeout for explicit wait - shortest timeout |
waitNormalSeconds | timeout for explicit wait - average timeout |
waitLongSeconds | timeout for explicit wait - longest timeout |
Reports are generated by maven-cucumber-reporting plugin and can be found under target/site/cucumber-reports/cucumber-html-reports
docker-compose -f docker/docker-compose-selenium.yml up
docker-compose scale selenium-hub=1 firefox=5 chrome=5
- Pull desired browser images for testing
docker pull selenoid/vnc:chrome_68.0
Optionally, if you want video recording enabled, then corresponding image needs to be pulled
docker pull selenoid/video-recorder
- Start Selenoid
docker-compose -f docker/docker-compose-selenoid.yml up
docker-compose -f docker/docker-compose-zalenium.yml up --force-recreate
./mvnw clean verify -DremoteDriver=true -P onerunner -Dthreads=3 -Dbrowser=chrome -DuseTestcontainers=false -DenableVideo=false -DenableVNC=false
./mvnw clean verify -Denv=test -DenableVNC=true -DenableVideo=true
-Denv=test
- uses remoteDriver=true
in ApplicationProperties.java
This project uses webdrivermanager tool in order to automate the Selenium browser drivers management in runtime. It will automatically download all needed driver to your local PC if needed with specified version.
-
Parameter Types:
-
Spring Boot and Cucumber Tests
- https://github.com/bcarun/cucumber-samples/tree/master/hello-springboot-cucumber
- Cucumber:
- TypeRegistryConfigurer (CucumberTypeRegistryConfigurer) - from DataTable to Model via Jackson
- cucumber-reporting from
net.masterthought
configuration
1.If you decide to use Cucumber Report plugin configured above, replace ‘@RunWith(Cucumber.class)’ with ‘@RunWith(CucumberReportRunner.class)’ in CucumberTest.java file. 2. CucumberReportRunner.java extends Cucumber.java 3. CucumberReportRunner generates reports from the file at target/cucumber-report.json 4. CucumberReportRunner copies the generated html reports to target/classes/static directory so that the reports are packaged along with the application.
public class CucumberReportRunner extends Cucumber {
// Can be dynamically pulled from CI Server
private static final String PROJECT_NAME = "Hello Cucumber & Spring Boot";
private static final String BUILD_NUMBER = "1.0.0";
private static final String BRANCH_NAME = "master";
public CucumberReportRunner(Class clazz) throws InitializationError {
super(clazz);
}
@Override
public void run(RunNotifier notifier) {
super.run(notifier);
generateReport();
}
public static void generateReport() {
File reportOutputDirectory = new File("target/classes/static");
List<String> jsonFiles = new ArrayList<>();
jsonFiles.add("target/cucumber-report.json");
// set values from respective build tool
Configuration configuration = new Configuration(reportOutputDirectory, PROJECT_NAME);
configuration.setBuildNumber(BUILD_NUMBER);
configuration.addClassifications("Build Number", configuration.getBuildNumber());
configuration.addClassifications("Branch Name", BRANCH_NAME);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
}