serenity-bdd / serenity-cucumber

Cucumber integration for the Serenity BDD Reporting library
Other
78 stars 74 forks source link

How can i run feature files with testng suite xml in parallel? #216

Closed qaschevychelov closed 4 years ago

qaschevychelov commented 4 years ago

Hi! I've faced such problem: I'm using 'cucumber-jvm-parallel-plugin' for parallel running feature files. But this approach create JVM per test runner. I decided to use testNG suite xml file, in which i link test runners. But in test runner i need to initialize TestNGCucumberRunner.

If i pass this.getClass() in the TestNGCucumberRunner constructor, then it will throw "[TestNG] WARN cucumber.runtime.SerenityBackend - It looks like you are running a feature using @RunWith(Cucumber.class) instead of @RunWith(CucumberWithSerenity.class). Are you sure this is what you meant to do?"

If i pass CucumberWithSerenity.class in the TestNGCucumberRunner constructor, then it will throw "None of the features at [classpath:net/serenitybdd/cucumber] matched the filters: [@ready]". I think i need somehow to switch classpath from classpath:net/serenitybdd/cucumber to a valid one.

Where did i go wrong?

My pom file: `

org.testng testng 6.9.8 test
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>1.2.5</version>
        <scope>compile</scope>
        <exclusions>
            <exclusion>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>info.cukes</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>1.2.5</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.github.temyers</groupId>
        <artifactId>cucumber-jvm-parallel-plugin</artifactId>
        <version>${cucumber-jvm-parallel-plugin.version}</version>
        <scope>system</scope>
        <systemPath>${android.parallel.custom.plugin.path}</systemPath>
    </dependency>
    <dependency>
        <groupId>ru.mvideo.rtd</groupId>
        <artifactId>core</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>ru.mvideo.rtd</groupId>
        <artifactId>mock</artifactId>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-core</artifactId>
    </dependency>
    <dependency>
        <groupId>net.serenity-bdd</groupId>
        <artifactId>serenity-cucumber</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-simple</artifactId>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>`

My project structure: image

My test runner: `package featureRunners;

import androidUtils.DeviceFinder; import cucumber.api.CucumberOptions; import cucumber.api.testng.AbstractTestNGCucumberTests; import cucumber.api.testng.CucumberFeatureWrapper; import cucumber.api.testng.TestNGCucumberRunner; import net.serenitybdd.cucumber.CucumberWithSerenity; import org.junit.runner.RunWith; import org.junit.runners.model.InitializationError; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import testRail.com.gurock.testrail.APIException; import utils.DevicePreparation; import utils.Updater;

import java.io.File; import java.io.IOException;

/**

My suite xml: image

wakaleo commented 4 years ago

Serenity will only work with the JUnit runner

qaschevychelov commented 4 years ago

i managed to run tests with testng suite xml. I removed a line "@RunWith(CucumberWithSerenity.class)" and pass this.getClass() in the TestNGCucumberRunner constructor. All scenarios go to the Selenium Grid hub. But the hub passes all scenarious to one appium node every time. If i use parallel approach with "cucumber-jvm-parallel-plugin", then selenium grid hub passes scenarious correctly to nodes.

wakaleo commented 4 years ago

I'm not sure if this will work - the CucumberWithSerenity sets up Serenity, so if you don't have it, Serenity won't be enabled. Does the this.getClass() replace this?

qaschevychelov commented 4 years ago

No this.getClass() refers to Cart class. Cart is a testNG runner. In this class i use methods with following annotations: @BeforeClass @Test @DataProvider @AfterClass (from testNG). DataProvider method (barcodes) return all feature files from path "src/test/resources/features/cart" into the method with Test annotation. And @Test method run all scenarious in all feature files. I investegated that when i use TestNGCucumberRunner, JUnit annotation @RunWith is omitted in test runner. But somehow (i dont understand how) first scenario goes to one appium node and runs correctly