简体   繁体   中英

How to Run cucumber Feature files in parallel

I want to run Features files (not scenario) to run in Parallel.

First Feature:

Feature: Refund item for Jeff

  Scenario: 01 Collect Details
    Given Collect Jeff details
    And Collect receipts for purchase
  
  Scenario: 02 Refund
    When Jeff returns the microwave
    Then Jeff should be refunded $100

Second Feature:

Feature: Refund item for Dave

  Scenario: 01 Collect Details
    Given Collect Dave details
    And Collect receipts for purchase
  
  Scenario: 02 Refund
    When Dave returns the microwave
    Then Dave should be refunded $100

I am using Cucumber-java with testng. I am able to run the scenarios in parallel. But I really want to run the Features in Parallel. I already implemented below code for parallel scenario.

public class RunCucumberTest extends AbstractTestNGCucumberTests {

    @Override
    @DataProvider(parallel = true)
    public Object[][] scenarios() {
        return super.scenarios();
    }
}

You can not. Scenarios are intended to be executed independently from each other. Depending on what you are testing, you could turn all scenarios in a feature file into a single scenario.

However you should consider rewriting your scenarios such that they do not depend on the actions in previous scenarios.

Typically this means writing scenarios like:

Scenario: Do a thing
  Given a thing
  When a thing is used
  Then something happens

Scenario: Do another thing next
  Given a thing that was used
  When a thing is used again
  Then something else happens

To implement a thing that was used you can reuse the methods you've already written to implement the steps of the first scenario.

You cannot achive that with TestNg . But. You can achieve that with JUnit4 . Basically That is how parallelisation works for JUnit 4 according to Cucumber specification .

Cucumber can be executed in parallel using JUnit and Maven test execution plugins. In JUnit the feature files are run in parallel rather than scenarios, which means all the scenarios in a feature file will be executed by the same thread. You can use either Maven Surefire or Failsafe plugin to execute the runners.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM