0
votes

I am new to cucumber testing framework. My goal is to run scenario files in parallel using Junit and Maven. I have followed the following steps : https://cucumber.io/docs/guides/parallel-execution/

I have two feature files

Feature 1 :

    Feature: Scenarios feature file One

  Scenario: Scenario Number One
    When request is sent to fetch data with user one
    Then check the result

Feature 2 :

Feature: Scenarios feature file One

      Scenario: Scenario Number Two
        When request is sent to fetch data with user two
        Then check the result

I also have a runner file as follow :

@RunWith(Cucumber.class)
@CucumberOptions(features = { "classpath:features" },
        strict = true,
        glue = {"integration.cucumber.step"},
        plugin = {"pretty", "html:target/report/cucumber", "json:target/report/cucumber/cucumber.json"},
        tags = {"not @Disabled"}
        )
public class CucumberTests {
}

My POM is as follows :

    <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>         
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <parallel>methods</parallel>
                        <useUnlimitedThreads>true</useUnlimitedThreads>
                    </configuration>
                </plugin>
       </plugins>  
 <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>test</scope>
            <version>4.12</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.4.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.4.0</version>
            <scope>test</scope>
        </dependency>

When I run cucumber tests by mvn clean install, both the Scenarios run with different threads. But I run using runner file created (CucumberTests) both the run with same thread. How do I make them run with different threads using runner class ?

1

1 Answers

0
votes

if you want to run that in parallel by Test class , then the test class needs to be extended to TestNG , try this out

public class CucumberTests  extends AbstractTestNGCucumberTests{

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

You have utilized the methods approach in parallel - with plugin - there is also option of classesAndMethods , do explore it

<configuration>
    <parallel>classesAndMethods</parallel>
    useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>