【发布时间】:2018-08-04 04:54:03
【问题描述】:
我正在尝试在并行浏览器中运行我的黄瓜项目(两个运行器类),但结果很奇怪。当我执行mvn verify 时,首先它将按顺序运行每个跑步者类。由于以下错误,第一个将通过,第二个将失败 -
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
然后,它将并行运行两个运行器类(就像我想要的那样),一切都会顺利通过。 maven 会报告 Build Success。
我没有在 @Before 注释中初始化 webdriver。相反,我在我的步骤定义类中使用 cucumber-picocontainer 依赖注入。我尝试在 @After 注释中交换 driver.close() 和 driver.quit() ,但这并没有改变结果。请在下面找到一些代码 sn-ps,然后是我的 POM。非常感谢。
public class GivenSteps {
WebDriver driver;
CustomWaits waits;
public GivenSteps(DependencyInjection dependencyInjection) {
this.driver = dependencyInjection.getDriver();
this.waits = dependencyInjection.getWaits();
}
挂钩 -
public class Hooks {
WebDriver driver;
public Hooks(DependencyInjection dependencyInjection) {
this.driver = dependencyInjection.getDriver();
}
@Before("@setup")
public void setUp() {
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
}
@After("@destroy")
public void tearDown() throws Throwable {
//driver.close();
driver.quit();
}
依赖注入 -
public class DependencyInjection {
private static String browserType = Settings.BROWSER.getValue();
private static WebDriver driver = null;
private static CustomWaits waits = null;
public WebDriver getDriver() {
if (driver == null) {
driver = utilities.DriverFactory.createDriver(browserType);
}
return driver;
}
POM.xml -
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<exclude>
**/*Runner.java
</exclude>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>
<package>test.java.stepDefinitions</package>
</glue>
<outputDirectory>target/generated-test-sources/cucumber</outputDirectory>
<featuresDirectory>src/test/resource/</featuresDirectory>
<cucumberOutputDir>target/Reports/</cucumberOutputDir>
<namingPattern>Runner{c}</namingPattern>
<!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per
scenario. FEATURE generates a runner per feature. -->
<parallelScheme>FEATURE</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.19.1</version>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<forkCount>10</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/*Runner.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
【问题讨论】:
标签: maven selenium parallel-processing cucumber maven-failsafe-plugin