我正在尝试在并行浏览器中运行我的Cucumber项目(两个Runner类),结果很奇怪。当我做一个
mvn verify
首先,它将按顺序运行每个Runner类。第一个将通过,第二个将由于以下错误而失败-
org.openqa.selenium.NoSuchSessionException: Session ID is null. Using WebDriver after calling quit()?
紧接着,它将并行运行两个runner类(就像我希望的那样),所有的都将通过。Maven将报告构建成功。
我没有在中初始化WebDriver
@Before
注释。相反,我在步骤定义类中使用CucumberPicocontainer依赖项注入。我尝试在我的
@After
注释,但这并没有改变结果。请在下面找到一些代码片段,然后找到我的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>