Concordion Scope Examples
Demonstrates the usage of different field scopes in Concordion.
With the introduction of examples running as separate JUnit tests in Concordion 2.0.0, Concordion reinitialises the fields in fixture objects for each Concordion example.
This encourages users to keep examples completely independent of each other, ensuring clean state per example and allowing individual examples to be run in isolation. It also makes the specification easier to follow when you can read examples in isolation.
However, we recognise that sometimes you will want to share fields across a specification when the field is expensive to initialise, for example a browser instance or database connection.
This project demonstrates the use of different scopes to share browsers across web tests.
The repository contains multiple branches, where each branch shows a different combination of field scope and runner (serial or parallel). The code includes the use of the ScreenshotExtension to demonstrate the use of extensions in different scopes.
The project uses Selenium Webdriver to run some browser tests. In order to run it, you'll need to have Firefox installed (or modify the code to use a different driver). Selenium WebDriver now requires you to download and unzip the Gecko driver and add it to your path (or set the
webdriver.gecko.driver system property to the absolute path to the gecko driver executable).
To run the project using Firefox:
- Install Firefox (or modify the code to use a different driver)
- Download and unzip the Gecko driver and add it to your path (or set the
webdriver.gecko.driversystem property to the absolute path to the gecko driver executable).
- checkout (or download and unzip) the relevant branch from below
The browser(s) are reused across all specifications, where the specifications are structured as a suite using the run command to invoke child specifications.
- per_suite_serial (download) - a single browser instance is used across all tests.
- per_suite_parallel (download) - initiates a single browser instance per thread across all tests. Note that the parallel runner does not guarantee that the same threads will be used across tests - additional threads may be started and old threads not reused.
A browser is created and destroyed per specification, using Concordion field scoping.
A browser is created and destroyed per example. This is the default scope and ensures clean state for each browser instance.
Note that the parallel tests are using the ParallelRunExtension to run the specifications in parallel. Concordion does not currently support running the individual examples in parallel.
As an alternative the fixtures from Specification Scope above can easily be modified to example scope by changing the value of the
Additional Method Hooks
In some cases, you may wish to use additional method hooks.