2016-12-08 5 views
3

src/test/resources/feature /に以下のフィーチャーファイル(別個のフィーチャーファイル)がありますので、それらを並行して実行したいと思います。 1つの機能ファイルはchromeで実行する必要があり、もう1つは@Tags nameで述べたようにfirefoxで実行する必要があります。キュウリフィーチャーファイルの並列実行方法

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 

誰かがランナーとして使用してキュウリ-javaの1.2.2バージョン、およびAbstractTestNGCucumberTestsを使用してthis.I'mを達成するために私を助けることができます。また、フィーチャーファイルを使用してテストランナーを動的に作成し、それらを並行して実行する方法を教えてください。

+0

何をここで達成しようとしていますか?最終目標は何ですか? – k1133

+0

さまざまなブラウザで機能ファイルを並行して実行したいと思います。私はどこで私はブラウザの互換性テストを行う必要があるアプリケーションがあります。これまでは、ブラウザの互換性を検証するためのシーケンス実行がありました。私はちょうどキュウリ - jvm - パラレルプラグインについて聞いたが、それを実装する方法をあまり知らない。ダイナミックにランナーをつくり、シナリオや機能に応じて並列実行できるようになると聞いています。 – ArrchanaMohan

+0

あなたはmavenとsurefireプラグインを試すことができます。利用可能なランナーを個別に実行する複数のスレッドを使用します。 Google cucmber java maven parallel。記事のリンクを使用していましたが、何とか削除されました – Grasshopper

答えて

6

更新: 4.0.0のバージョンは、変更の束とともにmavenセントラルリポジトリにあります。 for more details go here.

更新: 2.2.0バージョンは、Mavenセントラルリポジトリで入手できます。

オープンソースプラグインcucumber-jvm-parallel-pluginを使用できます。このプラグインは、既存のソリューションに比べて多くの利点があります。 Mavenのrepository

<dependency> 
    <groupId>com.github.temyers</groupId> 
    <artifactId>cucumber-jvm-parallel-plugin</artifactId> 
    <version>2.1.0</version> 
    </dependency> 
  1. 最初に利用可能な、あなたのプロジェクトの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> 
    
  2. 今も、あなたのマシンに提供真下(並列に実行されているキュウリのテストのために魔法を行います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>が提供されています。ここで 'n'は1)高度なハードウェアサポートと2)利用可能なノード、つまりHUBへのブラウザインスタンスの登録に比例します。

  5. 一つの主要かつ最も重要な変更はwebdriverをクラスはを共有する必要がありますし、終値はシャットダウンフックで世話をしているようあなたがないは、driver.quit()メソッドを実装する必要があります。あなたは50個の以上のスレッドを実行したい考慮

    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. は、ブラウザインスタンスの同じNOが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

+0

多くのあなたの入力のためのmankar sugat。非常に便利です。 – ArrchanaMohan

+0

私は本当に得意ではありません。なぜ 'maven-surefire-plugin'のフォークを指定する必要があるのなら、' cucumber-jvm-parallel-plugin'を追加する必要がありますか? – olyv

4

キュウリは、そのままの状態での並列実行をサポートしていません。 私は試しましたが、親切ではありません。

  1. これを並列に呼び出すには、mavenの機能を使用する必要があります。参照link
  2. カスタムプラグインを使用して並行して実行するgithubプロジェクトもあります。 あなたが期待しているすべてが並列に複数の機能を実行できるようにしている場合、あなたは次のことをやって試すことができますcucumber-jvm-parallel-plugin
+0

ありがとうbharathクマール。それは多くの助けになります。 – ArrchanaMohan

+0

これは、並列キュウリのjson出力ファイルを1つのレポート(https://github.com/rajatthareja/ReportBuilder)に照合する方法です。また、Rubyの場合、parallel_cucumberモジュールをRakefileに入れても、問題なく並列処理ができるようです。 – djangofan

1

を参照してください。

  • テストプロジェクトにクラスAbstractTestNGCucumberTestsを複製し、設定属性parallel=true@DataProvider注釈付きメソッド。 TestNGのからデフォルトdataprovider-thread-count以来

10で、今あなたが並列にfeaturesを実行するために、TestNGのを指示していることを、あなたはあなたの機能ファイルを並行して実行されます見て開始する必要があります。

しかし、Cucumberレポートは本質的にスレッドセーフではないため、レポートが文字化けして表示されることがあります。

+0

あなたの入力に感謝krishnana mahadevan。 – ArrchanaMohan

関連する問題