問題: 需要並行執行多個Cucumber 特徵文件,每個特徵檔案與不同的標籤相關聯,將特定文件指派給特定瀏覽器。
解決方案:
利用開源cucumber-jvm-parallel-plugin提供了一個功能-用於並行黃瓜測試執行的豐富解決方案。
將下列外掛程式設定加入專案的Maven pom 檔案:
<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>
新增另一個插件,該插件將呼叫上一個插件產生的運行器類別:
<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>
共享WebDriver 類別:
實作共用WebDriver 類別:
<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>
實作共用WebDriver 類別:
以上是如何在不同瀏覽器和標籤下並行執行Cucumber特徵檔?的詳細內容。更多資訊請關注PHP中文網其他相關文章!