Cucumber Selenium - 并行浏览器测试

时间:2016-02-28 22:36:15

标签: selenium webdriver cucumber parallel-testing

我有以下功能文件:

var twilio = require('twilio')(twilioAccountSid, twilioAuthToken);

如何在两个不同的浏览器上并行运行测试?

我知道它可以使用TestNG完成,但我没有在我的项目中使用TestNG。我想知道是否有其他方法。

3 个答案:

答案 0 :(得分:1)

我可以在这里想到三种不同的方法。

  • 按照您的方式编写方案。在第一步中找到IE时,创建一个IE实例。在第一步中看到FF时,创建一个FF实例。然后在以下步骤中使用它们。

  • 请勿在步骤中包含浏览器。创建它们并在您将委派工作的助手类中使用它们。

  • 为每个浏览器创建一个方案。 “当我用Firefox打开Goog​​le时......”

如果您想要明确,请使用最后一种方法。

如果您的用户不关心浏览器,请使用第二种方法。

我不会自己使用第一种方法。

答案 1 :(得分:1)

确定哪种方法最适合实现并行执行-Cucumber-JVM 4支持cumber v 4.0.0中的并行执行,我们不需要为每个功能文件创建单独的运行器,您可以实现这一点与JUnit一起使用(不需要使用TestNG和cucumber-jvm-parallel-plugin)

从黄瓜4.0.0开始实施并行执行的步骤-

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>

2。在POM.XML下添加Maven-Surefire-Plugin

<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>

注意-RunCukeTest是运行程序文件名,请记住,TestNG依赖关系导致Surefire忽略JUnit包装器类。如果根本不需要,请删除所有TestNG依赖项,否则您将需要为TestNG定义2个执行,为JUnit定义2个执行,并根据需要禁用一个。

每件事都做完之后,您需要为每种情况传递要从excel,json等来源运行的浏览器名称。

答案 2 :(得分:0)

如果使用的是黄瓜,则必须创建多个运行程序,然后使用maven并行运行它们。因此,为每个步骤定义创建运行器很麻烦,因此我们必须在运行时在目标文件夹中创建运行器。有两种方法可以在运行时创建运行器。

  1. 使用黄瓜JVM并行插件here

  2. 如果您使用的是最新版本的黄瓜,那么有一个很棒的插件叫做cucable Here