2016-06-23 9 views
0

キュウリでの並列テストを使用して2つのテストケースを実行する必要があります。キュウリでの並列テストの実行方法

私が今行っているのは、2つのテストケースです。 1つはgoogle.comを開き、もう1つはyoutube.comを開きます。私はpom.xmlに特定の依存関係を追加し、いくつかの設定を行いました。

また、ランナークラスも追加しました。

これは、Googleのテストケース、ランナークラスと機能ファイルの内容です:

package com.cucumber.learning; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import cucumber.api.java.en.Given; 

public class GoogleTest { 

public static WebDriver driver = new FirefoxDriver(); 

@Given("go to google") 
public static void main() { 

    driver.get("https://www.google.co.in/?gfe_rd=cr&ei=iHJrV_DiJ8SL8QfEipjgBg"); 

} 

} 

グーグルランナークラス

package com.cucumber.learning; 

import org.junit.runner.RunWith; 
import cucumber.api.CucumberOptions; 
import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@CucumberOptions(
    features = "src/test/resources/com/cucumber/learning" 
    //,glue={"stepDefinition"} 
    ) 

public class GoogleRunnerIT { 

} 

Googleの機能ファイル:[機能ファイル名:1.google.feature]

@Google 
Feature: Google test 

Scenario: navigate to google 
Given go to google 

youtube.comのテストケースでも上記と同様のコードを作成しました。 I「は 『Mavenのテスト』として実行」を使用してEclipseで上記プロジェクトを実行すると

<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.bdd</groupId> 
<artifactId>CucumberModule</artifactId> 
<version>0.0.1-SNAPSHOT</version> 
<url>http://maven.apache.org</url> 
<dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.11</version> 
    </dependency> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-junit</artifactId> 
     <version>1.1.7</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>cucumber-java</artifactId> 
     <version>1.1.7</version> 
     <type>jar</type> 
    </dependency> 
    <dependency> 
     <groupId>info.cukes</groupId> 
     <artifactId>gherkin</artifactId> 
     <version>2.12.1</version> 
    </dependency> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.53.0</version> 
    </dependency> 
</dependencies> 
<build> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.18.1</version> 
      <dependencies> 
       <dependency> 
        <groupId>org.apache.maven.surefire</groupId> 
        <artifactId>surefire-junit47</artifactId> 
        <version>2.18.1</version> 
       </dependency> 
      </dependencies> 
      <executions> 
       <execution> 
        <id>acceptance-test</id> 
        <phase>integration-test</phase> 
        <goals> 
         <goal>test</goal> 
        </goals> 
        <configuration> 
         <includes> 
          <include>**/*RunnerIT.class</include> 
         </includes> 
         <parallel>all</parallel> 
         <threadCountSuites>2</threadCountSuites> 
         <useUnlimitedThreads>true</useUnlimitedThreads> 
         <testFailureIgnore>true</testFailureIgnore> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
    </plugins> 
</build> 
</project> 

は、Iビルド成功メッセージを受信するが、何のブラウザが開いていない:

のpom.xmlコードは以下のように示されていますまたはテストケースが実行中であることを示します。

ご協力いただきまして誠にありがとうございます。前もって感謝します。

コンソールエラー:JUnitのための

[INFO] Scanning for projects... 
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.bdd:CucumberModule:jar:0.0.1-SNAPSHOT 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 39, column 12 
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
[WARNING] 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building CucumberModule 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ CucumberModule --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory /home/test/workspace/customparalleltesting/src/main/resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ CucumberModule --- 
[INFO] No sources to compile 
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ CucumberModule --- 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] Copying 3 resources 
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ CucumberModule --- 
[INFO] Nothing to compile - all classes are up to date 
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) @ CucumberModule --- 
[INFO] Surefire report directory: /home/test/workspace/customparalleltesting/target/surefire-reports 
[INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider 
[INFO] parallel='none', perCoreThreadCount=true, threadCount=0, useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, threadCountMethods=0, parallelOptimized=true 

------------------------------------------------------- 
T E S T S 
------------------------------------------------------- 
Running com.cucumber.learning.YoutubeTest 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.003 sec <<< FAILURE! - in com.cucumber.learning.YoutubeTest 
initializationError(com.cucumber.learning.YoutubeTest) Time elapsed: 0.001 sec <<< ERROR! 
cucumber.runtime.CucumberException: 

Classes annotated with @RunWith(Cucumber.class) must not define any 
Step Definition or Hook methods. Their sole purpose is to serve as 

エントリポイント。ステップ定義とフックは、独自のクラスで と定義する必要があります。これにより、それらをフィーチャー間で再利用することができます。 問題のクラス:クラスcom.cucumber.learning.YoutubeTest

at  cucumber.runtime.junit.Assertions.assertNoCucumberAnnotatedMethods(Assertions.java:13) 
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:55) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) 
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) 
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) 
at org.junit.runner.Computer.getRunner(Computer.java:40) 
at org.junit.runner.Computer$1.runnerForClass(Computer.java:31) 
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101) 
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87) 
at org.junit.runners.Suite.<init>(Suite.java:80) 
at org.junit.runner.Computer.getSuite(Computer.java:28) 
at org.junit.runner.Request.classes(Request.java:75) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:97) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:78) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:54) 
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:144) 
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) 
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) 
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 

Running com.cucumber.learning.GoogleTest 
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0 sec <<< FAILURE! - in com.cucumber.learning.GoogleTest 
initializationError(com.cucumber.learning.GoogleTest) Time elapsed: 0 sec <<< ERROR! 

cucumber.runtime.CucumberException:

Classes annotated with @RunWith(Cucumber.class) must not define any 
Step Definition or Hook methods. Their sole purpose is to serve as 
    an entry point for JUnit. Step Definitions and Hooks should be defined 
in their own classes. This allows them to be reused across features. 
Offending class: class com.cucumber.learning.GoogleTest 

at cucumber.runtime.junit.Assertions.assertNoCucumberAnnotatedMethods(Assertions.java:13) 
at cucumber.api.junit.Cucumber.<init>(Cucumber.java:55) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) 
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) 
at java.lang.reflect.Constructor.newInstance(Constructor.java:526) 
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:29) 
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:21) 
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26) 
at org.junit.runner.Computer.getRunner(Computer.java:40) 
at org.junit.runner.Computer$1.runnerForClass(Computer.java:31) 
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59) 
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:101) 
at org.junit.runners.model.RunnerBuilder.runners(RunnerBuilder.java:87) 
at org.junit.runners.Suite.<init>(Suite.java:80) 
at org.junit.runner.Computer.getSuite(Computer.java:28) 
at org.junit.runner.Request.classes(Request.java:75) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.createRequestAndRun(JUnitCoreWrapper.java:97) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.executeEager(JUnitCoreWrapper.java:78) 
at org.apache.maven.surefire.junitcore.JUnitCoreWrapper.execute(JUnitCoreWrapper.java:54) 
at org.apache.maven.surefire.junitcore.JUnitCoreProvider.invoke(JUnitCoreProvider.java:144) 
at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:203) 
at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:155) 
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:103) 


Results : 

Tests in error: 
GoogleTest.initializationError » Cucumber 

Classes annotated with @RunWith(Cu... 
YoutubeTest.initializationError » Cucumber 

Classes annotated with @RunWith(C... 

Tests run: 2, Failures: 0, Errors: 2, Skipped: 0 

[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 2.375 s 
[INFO] Finished at: 2016-06-23T16:21:53+05:30 
[INFO] Final Memory: 10M/218M 
[INFO] ------------------------------------------------------------------------ 
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.18.1:test (default-test) on project CucumberModule: There are test failures. 
[ERROR] 
[ERROR] Please refer to /home/test/workspace/customparalleltesting/target/surefire-reports for the individual test results. 
[ERROR] -> [Help 1] 
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. 
[ERROR] Re-run Maven using the -X switch to enable full debug logging. 
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles: 
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException 
+0

[キュウリの機能ファイルをどのように並列実行するか]の可能な複製(http://stackoverflow.com/questions/41034116/how-to-execute-cucumber-feature-file-parallel) –

+0

http: /stackoverflow.com/a/41100104/2895913 –

答えて

1

セットアップで正しくない多くのものがありますが、あなたはブラウザをインスタンス化する必要がありますcucumber runnerクラスからすべてのステップ定義を実行して、別々に実行する必要がある場合はどのようにして実行すればよいのでしょうか?

package com.cucumber.learning; 

import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import cucumber.api.java.en.Given; 

    public class GoogleTest extends GoogleRunnerIT { 


@Given("go to google") 
public static void main() { 

public static WebDriver driver = new FirefoxDriver(); 

driver.get("https://www.google.co.in/?gfe_rd=cr&ei=iHJrV_DiJ8SL8QfEipjgBg"); 

} 

} 

しかし、効率的な方法は、アプリケーションのURLをインスタンス化して渡すためのランナークラスに共通のメソッドを作成することです。

+0

GoogleTest.javaとYoutubeTest.java [extend YoutubeRunnerIT]の両方であなたが言及したことをメソッド内でインスタンス化しましたか?まだ実行できません。あなたがレビューするために質問に受け取ったコンソールエラーを追加しています。 –

+0

あなたのキュウリランナークラスでは、接着剤は何らかの理由でコメントされていますか? –

+0

いいえ、理由はありません。 –

0

例以下のように、それは並列で4つのテストクラスを実行しますforkCount = 4でのmaven-確実なプラグイン の構成タグにforkCountを入れてRunnerIT

で終わってみ
<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.18.1</version> 
     <dependencies> 
      <dependency> 
       <groupId>org.apache.maven.surefire</groupId> 
       <artifactId>surefire-junit47</artifactId> 
       <version>2.18.1</version> 
      </dependency> 
     </dependencies> 
     <executions> 
      <execution> 
       <id>acceptance-test</id> 
       <phase>integration-test</phase> 
       <goals> 
        <goal>test</goal> 
       </goals> 
       <configuration> 
        <includes> 
         <include>**/*RunnerIT.class</include> 
        </includes> 
        <forkCount>4</forkCount> 
        <parallel>all</parallel> 
        <threadCountSuites>2</threadCountSuites> 
        <useUnlimitedThreads>true</useUnlimitedThreads> 
        <testFailureIgnore>true</testFailureIgnore> 
       </configuration> 
      </execution> 
     </executions> 
    </plugin> 

リファレンスから: -
https://opencredo.com/running-cucumber-jvm-tests-in-parallel/

+0

私は2つのRunnerIT.classを持っているのでforkCount = 2を追加しましたが、動作しません。テストは実行されますが、実行は並列ではありません。テストは次々と実行されています]。 –

0

あなたはステップ定義クラス
で実行されるメソッドのシグネチャと注釈を変更できます


メインメソッドで定義されているステップ定義で疑義があります。

+0

あなたが言ったことは、まだ動作していないと試してみました。 –

関連する問題