Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run after all cucumber tests

Is there a way to run a method after all of the cucumber tests have been run?

The @After annotation would run after every individual test, right? I wan't something that would only run once, but at the very end.

like image 243
user7637341 Avatar asked Mar 08 '17 14:03

user7637341


People also ask

How do you run multiple test cases in Cucumber?

Cucumber can be executed in parallel using TestNG and Maven test execution plugins by setting the dataprovider parallel option to true. In TestNG the scenarios and rows in a scenario outline are executed in multiple threads. One can use either Maven Surefire or Failsafe plugin for executing the runners.

Do Cucumber tests run in order?

Cucumber feature files are run in Alphabetical order by feature file name as default. But if you want to try something different by changing the order i.e. by changing the order of the scenarios -- order = random etc.

How do I run multiple tags in Cucumber?

We can define each scenario with a useful tag. Later, in the runner file, we can decide which specific tag (and so as the scenario(s)) we want Cucumber to execute. Tag starts with “@”. After “@” you can have any relevant text to define your tag like @SmokeTests just above the scenarios you like to mark.


1 Answers

You could use the standard JUnit annotations.

In your runner class write something similar to this:

@RunWith(Cucumber.class)
@Cucumber.Options(format = {"html:target/cucumber-html-report", "json-pretty:target/cucumber-json-report.json"})
public class RunCukesTest {

    @BeforeClass
    public static void setup() {
        System.out.println("Ran the before");
    }

    @AfterClass
    public static void teardown() {
        System.out.println("Ran the after");
    }
}
like image 86
Morvader Avatar answered Sep 18 '22 12:09

Morvader