我在src / test / resources / feature /中有以下功能文件(单独的功能文件),我想并行运行它们。就像:一个功能文件必须在chrome中执行,而另一个功能文件必须在firefox中执行,如@Tags名称所述。
Feature: Refund item
@chrome
Scenario: Jeff returns a faulty microwave
Given Jeff has bought a microwave for $100
And he has a receipt
When he returns the microwave
Then Jeff should be refunded $100
Feature: Refund Money
@firefox
Scenario: Jeff returns the money
Given Jeff has bought a microwave for $100
And he has a receipt
When he returns the microwave
Then Jeff should be refunded $100
有人可以帮助我实现这一点吗?我使用的是cumul-java 1.2.2版本,并且使用AbstractTestNGCucumberTests作为运行程序。另外,让我知道如何使用功能文件动态创建Test Runner,并使它们并行运行。
<dependency>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>2.1.0</version>
</dependency>
首先,你需要在项目pom文件中添加具有所需配置的此插件。
<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>
<!-- Mandatory -->
<!-- comma separated list of package names to scan for glue code -->
<glue>foo, bar</glue>
<outputDirectory>${project.build.directory}/generated-test-sources/cucumber</outputDirectory>
<!-- The directory, which must be in the root of the runtime classpath, containing your feature files. -->
<featuresDirectory>src/test/resources/features/</featuresDirectory>
<!-- Directory where the cucumber report files shall be written -->
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<!-- comma separated list of output formats json,html,rerun.txt -->
<format>json</format>
<!-- CucumberOptions.strict property -->
<strict>true</strict>
<!-- CucumberOptions.monochrome property -->
<monochrome>true</monochrome>
<!-- The tags to run, maps to CucumberOptions.tags property you can pass ANDed tags like "@tag1","@tag2" and ORed tags like "@tag1,@tag2,@tag3" -->
<tags></tags>
<!-- If set to true, only feature files containing the required tags shall be generated. -->
<filterFeaturesByTags>false</filterFeaturesByTags>
<!-- Generate TestNG runners instead of default JUnit ones. -->
<useTestNG>false</useTestNG>
<!-- The naming scheme to use for the generated test classes. One of 'simple' or 'feature-title' -->
<namingScheme>simple</namingScheme>
<!-- The class naming pattern to use. Only required/used if naming scheme is 'pattern'.-->
<namingPattern>Parallel{c}IT</namingPattern>
<!-- One of [SCENARIO, FEATURE]. SCENARIO generates one runner per scenario. FEATURE generates a runner per feature. -->
<parallelScheme>SCENARIO</parallelScheme>
<!-- This is optional, required only if you want to specify a custom template for the generated sources (this is a relative path) -->
<customVmTemplate>src/test/resources/cucumber-custom-runner.vm</customVmTemplate>
</configuration>
</execution>
</executions>
</plugin>
现在在上方插件下方添加下方插件,它将调用由上方插件生成的运行器类
<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>
上面的两个插件可以并行运行黄瓜测试(只要你的机器还具有高级硬件支持)。
<forkCount>n</forkCount>
此处严格提供的 “ n”与1)高级硬件支持和2)可用节点(即注册到HUB的浏览器实例)成正比。
一个主要的和最重要的变化是你的webdriver类必须是SHARED,你应该不执行driver.quit()方法,如封闭是照管关闭挂钩。
import cucumber.api.Scenario;
import cucumber.api.java.After;
import cucumber.api.java.Before;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.events.EventFiringWebDriver;
public class SharedDriver extends EventFiringWebDriver {
private static WebDriver REAL_DRIVER = null;
private static final Thread CLOSE_THREAD = new Thread() {
@Override
public void run() {
REAL_DRIVER.close();
}
};
static {
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
}
public SharedDriver() {
super(CreateDriver());
}
public static WebDriver CreateDriver() {
WebDriver webDriver;
if (REAL_DRIVER == null)
webDriver = new FirefoxDriver();
setWebDriver(webDriver);
return webDriver;
}
public static void setWebDriver(WebDriver webDriver) {
this.REAL_DRIVER = webDriver;
}
public static WebDriver getWebDriver() {
return this.REAL_DRIVER;
}
@Override
public void close() {
if (Thread.currentThread() != CLOSE_THREAD) {
throw new UnsupportedOperationException("You shouldn't close this WebDriver. It's shared and will close when the JVM exits.");
}
super.close();
}
@Before
public void deleteAllCookies() {
manage().deleteAllCookies();
}
@After
public void embedScreenshot(Scenario scenario) {
try {
byte[] screenshot = getScreenshotAs(OutputType.BYTES);
scenario.embed(screenshot, "image/png");
} catch (WebDriverException somePlatformsDontSupportScreenshots) {
System.err.println(somePlatformsDontSupportScreenshots.getMessage());
}
}
}
考虑到你要执行50个以上的线程,即没有向HUB注册相同的浏览器实例,但是如果Hub没有足够的内存,它将死掉,因此,为避免这种严重情况,你应该使用-DPOOL_MAX = 512(或更大)来启动Hub如grid2文档中所述。
Really large (>50 node) Hub installations may need to increase the jetty threads by setting -DPOOL_MAX=512 (or larger) on the java command line.
java -jar selenium-server-standalone-<version>.jar -role hub -DPOOL_MAX=512
使用Cucumber,我们创建了由不同场景组成的不同功能文件。我们记住的一件事是,每个场景都独立于所有其他场景。 问:我们可以对所有的特征文件或场景进行并行执行吗?
这是我的
我在src/test/resources/feature/中有以下功能文件(单独的功能文件),我想并行运行它们。比如:一个功能文件必须在chrome中执行,另一个必须在另一个chrome实例中执行,如@Tags name所述。 我正在使用Java1.2。5版本,AbstractTestNGCucumberTests作为runner。我可以运行一个功能文件,但当我尝试使用cucumber jvm并行
在cucumber测试中,我想在不改变特性文件的情况下跳过一些特性文件,比如添加额外的标记。虽然标签可以排除功能文件运行,但我不能修改这些文件。是否有方法在maven pom.xml中进行配置?或者我可以使用带有特殊特性参数的@cucumberoptions吗? 一种方法是使用Maven插件为每个特性文件生成一个Junit Runner类。然后,通过,我们可以指定排除或包含以排除或包含那些Juni
我不能在不同浏览器的browserstack中并行运行特性文件(java-maven-intellij)。我能够在我的JUnit框架中实现并行测试,但不知道如何在cucumber Java中实现。你能帮忙吗? 目前,我能够在browserstack上执行测试,但只能在一个浏览器上执行。请看附件
我想为每个特定的功能文件指定特定的设置和拆卸步骤。我已经看到了允许代码在每个场景之前执行的钩子,以及在每个功能之前执行代码的钩子。但是我想指定代码在所有场景为一个特定功能运行之前和之后运行一次。 这有可能吗?