serenity-bdd / serenity-cucumber

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

Execute one BDD feature file always first #230

Open sudheerah opened 4 years ago

sudheerah commented 4 years ago

Hi there,

Just curious whether there is way to run serenity BDD tests (maven project) in a particular order in command line.

e.g. I have three tests (feature1, feature2 and feature3) and I wanted to run those in CLI in blow order

1. Feature2
2. Feature1 and Feature3 (order doesn't matter)

Using below Maven Dep:

<properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <gherkin.version>5.1.0</gherkin.version>
        <cucumber.version>4.7.2</cucumber.version>
    </properties>
<dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>rest-assured</artifactId>
            <version>RELEASE</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>json-path</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>io.rest-assured</groupId>
            <artifactId>xml-path</artifactId>
            <version>RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.json</groupId>
            <artifactId>json</artifactId>
            <version>20190722</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>gherkin</artifactId>
            <version>${gherkin.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-core</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-picocontainer</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
    </dependencies>
wakaleo commented 4 years ago

Not easily - that would imply there is a dependency between the features, which is considered a pretty big Cucumber anti-pattern. You could do it with test suites and runners, but it would be very clunky.

sudheerah commented 4 years ago

@wakaleo Actually I was trying to implement @BeforeAll with junit. to run setup(). But apparently not working as expected. I tried few solutions. Unfortunately nothing with serenity BDD Solution1 Solution2

wakaleo commented 4 years ago

Why not just use Cucumber hooks?

sudheerah commented 4 years ago

Is there any sample solution you know. I was under impression it is not yet supported. What I read was all these hooks use for within feature files NOT for initial setup before start the suite.

wakaleo commented 4 years ago

https://cucumber.io/docs/cucumber/api/#hooks

sudheerah commented 4 years ago

Not supported global hooks which I am after

Global hooks

Cucumber-JVM does not support global hooks.

wakaleo commented 4 years ago

What problem are you trying to sovle?

sudheerah commented 4 years ago

Need to load my all the mocks before test execution

wakaleo commented 4 years ago

I would use @Before hooks and a ThreadLocal object.

sudheerah commented 4 years ago

If you can send me an example will be much appreciated.

arunahk commented 4 years ago

@sudheerah use TestNG as runner and use @BeforeSuite?