Skip to content

Selenium, Cucumber, Docker, Grafana, ELK, Courgette, Guice, Gradle, Maven, Spring, Telegraf, InfluxDb, Selenoid, Kubernetes, Helm, Moon

Notifications You must be signed in to change notification settings

iljapavlovs/cucumber-examples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cucumber-jvm-parallel-template Build Status

CucumberJVM template project for running tests in parallel.

This project was based on Selenium-Maven-Template and support for CucumberJVM was added

How to run

Execution options

  1. 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.
  2. Using cucumber-jvm-parallel-plugin (use profile parallelPlugin)
    • cucumber-jvm-parallel-plugin will automatically generates "runner" classes.
    • More on this read here.

Command for execution

./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 

Configuration

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

Reporting

Reports are generated by maven-cucumber-reporting plugin and can be found under target/site/cucumber-reports/cucumber-html-reports

Setting up Selenium Grid in Docker Containers

Selenium

docker-compose -f docker/docker-compose-selenium.yml up
Scaling
docker-compose scale selenium-hub=1 firefox=5 chrome=5 

Selenoid - more in [Selenoid Configuration.md](Selenoid Configuration.md)

  1. 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
  1. Start Selenoid
docker-compose -f docker/docker-compose-selenoid.yml up

Zalenium

docker-compose -f docker/docker-compose-zalenium.yml up --force-recreate

Running Tests against these Selenium Grid implementations

 ./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

Driver Download for local execution

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.

Cucumber >1.2.5

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();
  }
}

Releases

No releases published

Packages

No packages published

Languages

  • Java 97.4%
  • Gherkin 2.3%
  • Other 0.3%