Home >Java >javaTutorial >How to execute Cucumber feature files in parallel with different browsers and tags?
Problem: Several cucumber feature files, each associated with different tags, need to be executed in parallel, with specific files assigned to specific browsers.
Solution:
Utilizing the open-source cucumber-jvm-parallel-plugin provides a feature-rich solution for parallel cucumber test execution.
Add the following plugin configuration to the project's Maven pom file:
<code class="xml"><dependency> <groupId>com.github.temyers</groupId> <artifactId>cucumber-jvm-parallel-plugin</artifactId> <version>2.1.0</version> </dependency> <plugin> <groupId>com.github.temyers</groupId> <artifactId>cucumber-jvm-parallel-plugin</artifactId> <version>2.1.0</version> <executions> <execution> <id>generateRunners</id> <phase>generate-test-sources</phase> <goals> <goal>generateRunners</goal> </goals> <configuration> <glue>foo, bar</glue> <outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory> <featuresDirectory>src/test/resources/features/</featuresDirectory> <cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir> <format>json</format> <strict>true</monochrome>true</strict> <tags>@chrome,@firefox</tags> <filterFeaturesByTags>false</filterFeaturesByTags> <useTestNG>false</useTestNG> <namingScheme>simple</namingScheme> <parallelScheme>SCENARIO</parallelScheme> </configuration> </execution> </executions> </plugin></code>
Add another plugin that will invoke the runner classes generated by the previous plugin:
<code class="xml"><plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.19</version> <configuration> <forkCount>5</forkCount> <reuseForks>true</reuseForks> <includes> <include>**/*IT.class</include> </includes> </configuration> </plugin></code>
Shared WebDriver Class:
Implement a shared WebDriver class:
<code class="java">public class SharedDriver extends EventFiringWebDriver { // Singleton WebDriver instance private static WebDriver REAL_DRIVER = null; // Closing hook for WebDriver private static final Thread CLOSE_THREAD = new Thread() { @Override public void run() { REAL_DRIVER.close(); } }; // WebDriver setup static { Runtime.getRuntime().addShutdownHook(CLOSE_THREAD); } public SharedDriver() { super(CreateDriver()); } public static WebDriver CreateDriver() { if (REAL_DRIVER == null) REAL_DRIVER = new FirefoxDriver(); setWebDriver(REAL_DRIVER); return REAL_DRIVER; } public static void setWebDriver(WebDriver webDriver) { SharedDriver.REAL_DRIVER = webDriver; } public static WebDriver getWebDriver() { return SharedDriver.REAL_DRIVER; } // Disable closing for shared driver @Override public void close() { if (Thread.currentThread() != CLOSE_THREAD) { throw new UnsupportedOperationException("Closing is handled by shutdown hook."); } super.close(); } }</code>
Considerations:
The above is the detailed content of How to execute Cucumber feature files in parallel with different browsers and tags?. For more information, please follow other related articles on the PHP Chinese website!