我在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
有人可以协助我实现这个目标。我使用的是cucumber-java 1.2.2版本,而AbstractTestNGCucumberTests则用作跑步者。另外,让我知道如何使用功能文件动态创建测试运行器并使它们并行运行。
更新:4.0.0版本可在maven中央存储库中获得,其中包含大量更改.for more details go here.
更新:maven中央存储库提供2.2.0版本。
您可以使用开源插件qazxsw poi,它比现有解决方案有许多优点。可在maven qazxsw poi购买
cucumber-jvm-parallel-plugin
<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>
<!-- 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>
这里'n'与1)高级硬件支持和2)您可用的节点,即注册浏览器实例到HUB成正比。 <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>
所述。
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());
}
}
}
grid2 documentation如果你所期望的是能够并行运行多个功能,那么你可以尝试执行以下操作:
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
设置为AbstractTestNGCucumberTests注释方法。由于TestNG的默认parallel=true
是@DataProvider
,现在您已指示TestNG并行运行dataprovider-thread-count
,您应该开始看到您的要素文件并行执行。
但据我所知,Cucumber报告本质上不是线程安全的,因此您的报告可能会出现乱码。
黄瓜不支持开箱即用的并行执行。我试过了,但不友好。
10
features
要充分利用TestNG,您可以使用Testng的第三方扩展link框架。它支持多种cucumber-jvm-parallel-plugin,包括使用QAF的小黄瓜。在使用带有QAF的BDD时,您可以利用每个TestNG功能,包括数据提供程序,以不同方式(组/测试/方法)和TestNG侦听器的并行执行配置。
QAF将每个场景视为TestNG测试,并将场景大纲视为TestNG数据驱动测试。由于qaf提供了内置的驱动程序管理和资源管理,因此您无需为驱动程序管理或资源管理编写单行代码。您需要做的就是根据您的要求创建TestNG xml配置文件,以便在一个或多个浏览器上运行并行方法(方案)或组或xml测试。
它使不同的可能bdd syntax。下面是解决此问题的xml配置,它将在两个浏览器中并行运行场景。您还可以将每个浏览器的线程数配置为标准TestNG xml配置。
GherkinFactory
更多关于最新的configuration combinations支持<suite name="AUT Test Automation" verbose="0" parallel="tests">
<test name="Test-on-chrome">
<parameter name="scenario.file.loc" value="resources/features" />
<parameter name="driver.name" value="chromeDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
<test name="Test-on-FF">
<parameter name="scenario.file.loc" value="resources/features" />
<parameter name="driver.name" value="firefoxDriver" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
</suite>
,它来自QAF BDD,Jbehave和小黄瓜。它支持来自qaf bdd的元数据作为标记和来自小黄瓜的例子。您可以利用BDDTestFactory2
在BDD中使用元数据在XML / JSON / CSV / EXCEL / DB中提供测试数据。