Cucumber 黄瓜平行试运行
我目前正在尝试用cucumber实现并行测试运行。我设法用sure fire插件同时运行两个不同的跑步者。现在,我想检查是否可以并行多次运行SingleRunner文件 我有SignUpRunnerTest.java,所以我需要在几个平台上并行运行它。可能吗 这是我的跑步者档案Cucumber 黄瓜平行试运行,cucumber,cucumber-jvm,maven-surefire-plugin,Cucumber,Cucumber Jvm,Maven Surefire Plugin,我目前正在尝试用cucumber实现并行测试运行。我设法用sure fire插件同时运行两个不同的跑步者。现在,我想检查是否可以并行多次运行SingleRunner文件 我有SignUpRunnerTest.java,所以我需要在几个平台上并行运行它。可能吗 这是我的跑步者档案 import cucumber.api.CucumberOptions; import cucumber.api.cli.Main; import cucumber.api.junit.Cucumber; import
import cucumber.api.CucumberOptions;
import cucumber.api.cli.Main;
import cucumber.api.junit.Cucumber;
import java.util.List;
import javax.management.MXBean;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized.Parameter;
import org.junit.runners.Parameterized.Parameters;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty", "html:target/html/", "json:target/cucumber.json", "junit:TEST-all.xml"},
features = "src/test/java/resources/features/Search.feature", glue = {"com.browserstack.stepdefs"})
public class SignUpeRunnerTest {
}
无流道进近
public class SignUpeRunnerTest {
@Test
public void test2() {
Main.main(new String[]{"--threads", "4","-g", "com.browserstack.stepdefs", "src/test/java/resources/features/"});
}
}
工厂级
`导入org.openqa.selenium.WebDriver
public final class DriverFactory {
private static ThreadLocal<WebDriver> drivers = new ThreadLocal();
//To quit the drivers and browsers at the end only.
private static List<WebDriver> storedDrivers = new ArrayList();
static {
Runtime.getRuntime().addShutdownHook(new Thread(){
public void run(){
storedDrivers.stream().forEach(WebDriver::quit);
}
});
}
private DriverFactory() {}
public static WebDriver getDriver() {
return drivers.get();
}
public static void addDriver(WebDriver driver) {
storedDrivers.add(driver);
drivers.set(driver);
}
public static void removeDriver() {
storedDrivers.remove(drivers.get());
drivers.remove();
}
}
}
这是我的POM文件
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.browserstack</groupId>
<artifactId>cucumber-jvm-java-browserstack</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>cucumber-jvm-java-browserstack</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<cucumber.jvm.parallel.version>2.2.0</cucumber.jvm.parallel.version>
<surefire.maven.plugin.version>2.19.1</surefire.maven.plugin.version>
<acceptance.test.parallel.count>4</acceptance.test.parallel.count>
</properties>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.gfk.senbot/senbot-maven-plugin -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>4</threadCount>
<reuserForks>false</reuserForks>
<testErrorIgnore>true</testErrorIgnore>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*RunnerTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
4.0.0
com.browserstack
java浏览器堆栈
0.0.1-快照
罐子
java浏览器堆栈
http://maven.apache.org
UTF-8
2.2.0
2.19.1
4.
黄瓜
黄瓜爪哇
4.2.3
黄瓜
黄瓜刺柏
4.2.3
测试
朱尼特
朱尼特
4.12
测试
黄瓜
数据表
1.1.12
黄瓜
黄瓜试验
4.2.3
黄瓜
黄瓜皮容器
4.2.3
测试
org.seleniumhq.selenium
硒爪哇
3.0.1
测试
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
方法
4.
假的
真的
真的
**/*RunnerTest.java
info.cukes依赖项(非常旧),仅支持cucumber版本1.2.5,2016年9月12日后不再支持cucumber版本
另一方面,io.cucumber依赖项支持cucumber从v2.0.x版开始,直到目前最新的v4.3.x版。(cucumber JVM 4.0为实现并行执行提供了很大的灵活性),下面是使用io.cucumber实现并行执行的步骤(这里您不需要为每个功能文件创建单独的运行程序&也不需要使用任何旧的插件,比如jvm并行插件)
1.添加正确的依赖项集。我在实现过程中遵循了JUnit。
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
黄瓜
黄瓜爪哇
4.2.3
黄瓜
黄瓜刺柏
4.2.3
测试
朱尼特
朱尼特
4.12
测试
黄瓜
数据表
1.1.12
黄瓜
黄瓜皮容器
4.2.3
测试
2.在POM.XML下添加Maven Surefire插件
org.apache.maven.plugins
maven surefire插件
3.0.0-M3
方法
1.
假的
真的
真的
**/*RunCukeTest.java
Cucumber功能文件可以在不使用任何运行程序的情况下通过Cucumber.api.cli包main类中的main()方法来执行。请参考此方法,使用此可能会起作用。不过需要一些更改
将的代码复制到新类中,并将其重命名为其他名称,例如NewBSTest
。该类将用于运行测试
selenium和cucumber代码访问为每个线程创建的驱动程序的方式需要进行一些更改
需要使用工厂将驱动程序存储在NewBSTest
中的ThreadLocal
变量中。您可以参考此
在您创建的NewBSTest
类中,删除第30行-公共WebDriver驱动程序;
。更改第94行,将创建的RemoteWebDriver添加到ThreadLocal变量中。类似于DriverFactory.addDriver(driver)
。添加DriverFactory.removeDriver()
在方法tearDown()
第98行中,可能是第一行。将现有驱动程序.quit()更改为DriverFactory.getDriver().quit()
5.移除驱动器工厂中的关机挂钩,BrowserStack将退出实际的驱动器
现在,在selenium或cucumber代码中,您可以使用DriverFactory.getDriver()
访问驱动程序。这将严重影响现有代码
在NewBSTest
类中添加这样的测试方法。希望这能起作用,相同的功能将在每个配置的browserstack环境中执行
您可能已经得到了这个问题的答案。要并行运行测试用例,需要在下面的链接中提供额外的设置-
根据这个链接,如果您使用的是surefire插件,那么runner类的包名应该是并行的
对于选择设备类型,您可以为功能文件添加标记,并在钩子之前进一步获取标记。我认为选择功能可能有更好的方法。下面的逻辑对我有用-
@之前(订单=2)
公共void启动浏览器(场景sc)
{
String browser=“firefox”;
//
ArrayList s=(ArrayList)sc.getSourceTagNames()
如果有人能帮上忙,我很高兴..thanksanyone?可以帮你复制和重命名现有的runner类文件,你需要多少次。保留所有选项。现在你有多个相同的runner,但名称不同。这就变成了你已经在用的情况。你也应该考虑更新cucumber版本。你正在使用非常旧的版本。@Grasshopp呃,谢谢你的回复,实际上我不想重复所有的跑步者课程。相反,我想在10个不同的平台上并行测试一个跑步者课程。我实际上实现了
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.3</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>datatable</artifactId>
<version>1.1.12</version>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>4.2.3</version>
<scope>test</scope>
</dependency>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M3</version>
<configuration>
<parallel>methods</parallel>
<threadCount>1</threadCount>
<reuserForks>false</reuserForks>
<testErrorIgnore>true</testErrorIgnore>
<testFailureIgnore>true</testFailureIgnore>
<includes>
<include>**/*RunCukeTest.java</include>
</includes>
</configuration>
</plugin>
@Test
public void test() {
Main.main(new String[]{""-g", "stepdef", "src/test/resources/features/"});
}
//scenarios having this tag will be ignored and not run
if(s.contains("@chrome"))
browser = "chrome";
else if(s.contains("@firefox"))
browser = "firefox";
driverfactory=new DriverFactory();
driver=driverfactory.init_driver(browser);
}