黄瓜 - 运行并行方案

时间:2016-03-23 08:14:59

标签: ruby cucumber

我在使用示例表格式的Cucumber中进行了测试。我可以让Cucumber并行运行表格的每一行。

情景大纲:e_5_1用英语2检查定案法院代码

鉴于我导航到客户门户搜索屏幕
当我从行DLN输入NIPostcode<user_row>并访问Penaltiesdisqualifications时 然后点击认可,以便从行<row1><row2>

确认法院描述

然后我退出

  Examples:
    | user_row  | row1      | row2      |
    |   2       |   2       |   51      |
    |   52      |   52      |   98      |
    |   99      |   99      |   148     |
    |   149     |   149     |   198     |

通常情况下,我会说为行号运行test.feature,它会一次遍历每一行,或者使用我可以指定表行所在行的行号。

我可以让它同时并行运行所有4行吗?

提前致谢

2 个答案:

答案 0 :(得分:2)

您可以使用开源插件cucumber-jvm-parallel-plugin,它比现有解决方案有许多优点,但仅适用于java。可在maven repository

获取
   <dependency>
     <groupId>com.github.temyers</groupId>
     <artifactId>cucumber-jvm-parallel-plugin</artifactId>
     <version>2.2.0</version>
   </dependency>
  1. 首先,您需要在项目pom文件中添加此依赖项和插件以及所需的配置。

     <dependencies>
        <dependency>
         <groupId>com.github.temyers</groupId>
         <artifactId>cucumber-jvm-parallel-plugin</artifactId>
         <version>2.2.0</version>
       </dependency>
       <dependency>
          <groupId>net.masterthought</groupId>
          <artifactId>cucumber-reporting</artifactId>
          <version>3.3.0</version>
       </dependency>
    </dependencies>
    
    <plugin>
      <groupId>com.github.temyers</groupId>
      <artifactId>cucumber-jvm-parallel-plugin</artifactId>
      <version>2.2.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>
    
  2. 现在在插件上方添加以下插件,这将调用上面插件生成的跑步者类

        <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>
    
  3. 以上两个插件将为并行运行的黄瓜测试提供魔力(假设您的机器也具有高级硬件支持)。

  4. 严格提供<forkCount>n</forkCount>此处&#39; n&#39;与1)高级硬件支持和2)您可用的节点,即已注册的浏览器实例到HUB相关。

  5. 一个主要且最重要的变化是您的WebDriver类必须 SHARED ,您应该实现driver.quit()方法,因为关闭是照顾通过shutdown hook。

    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());
            }
        }
    }
    
  6. 考虑到您要执行超过50个线程,即同样没有浏览器实例注册到HUB但如果没有足够的内存而Hub将会死,因此为了避免这种危急情况,您应该启动集线器-DPOOL_MAX = 512(或更大),如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

答案 1 :(得分:0)

看看这个。它可能是您问题的解决方案:

https://github.com/grosser/parallel_tests

相关问题