0

I have the following feature file :

Given I open "google.com" simultaneously in both FF and IE
When I type "stackoverflow" and submit
Then I should see the desired results

How can I run the test on 2 different browsers in parallel ?

I know it can done using TestNG, but I am not using TestNG in my project. I was wondering if there was some other approach.

sanaku
  • 309
  • 2
  • 6
  • 18
  • try generic runner explained in detail here http://stackoverflow.com/a/41100104/2895913 – Sugat Mankar Dec 21 '16 at 13:20
  • There is an alternate answer to your question. Check out the blog post about Selenium-Grid [Run parallel test execution on different browser](http://www.idyllic-software.com/blog/run-parallel-test-execution-on-different-browsers/) – Poonam Pujari Mar 01 '16 at 07:59

3 Answers3

1

I can think of three different different approaches here.

  • Write the scenario as you have done. When you find IE in the first step, create an IE instance. When you see FF in the first step, create a FF instance. Then use both in the following steps.

  • Do not include the browser at all in the steps. Create them and use them in the helper class you will delegate the work to.

  • Create one scenario for each browser. “When I open Google with Firefox…”

If you want to be explicit, use the last approach.

If you your users doesn’t care about the browsers, use the second approach.

I wouldn’t use the first approach myself.

Thomas Sundberg
  • 4,098
  • 3
  • 18
  • 25
1

Identify which approach is best to implement parallel execution - Cucumber-JVM 4 supports parallel execution from cucumber v 4.0.0 and we do not need to create individual runner per feature file and You can implement this with JUnit (Do not need to use TestNG & cucumber-jvm-parallel-plugin)

Steps to implement parallel execution starting from cucumber 4.0.0 -

1.Adding correct set of dependency. I have followed JUnit during the implementation.

<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.Adding Maven-Surefire-Plugin under POM.XML

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

Note - RunCukeTest is the runner file name and remember, TestNG dependency causes Surefire to ignore JUnit wrapper class. Remove all the TestNG dependencies if not required at all or you would need to define 2 execution one for TestNG & other for JUnit and disable one as per your need.

Once everything is done then you would need to pass browser name you want to run from a source like excel, json etc for each scenario.

TheSociety
  • 1,936
  • 2
  • 8
  • 20
0

If you are using cucumber you have to create multiple runners and then use maven to run them in parallel. So creating runner for every step definition is pain, so we have to create runners in run time in target folder.There are two ways to create runners on run time.

  1. Use cucumber JVM parallel plugin here

  2. If you are using the newest version of cucumber there is an awesome plugin called cucable Here

sam
  • 1