1

I am using the Karate framework for testing my REST API. At the beginning of the tests suite I create a new user (tenant) for testing, and I want to delete this user once all tests are finished. To do this, I looked for an option to call to specific feature at the end of the tests suite but I could not find it. It is important that this feature will be executed also when I run single test from Intellij.

perhaps there is a hook like karate.callSingle for the end of the tests?

Here is some workaround that I did for this:

@KarateOptions(features = "classpath:karate/runners", tags = {"@full", "~@ignore"}) // '~@<NAME>' will ignore features which are tagged with '@<NAME>'
public class KarateTestsFull {

    @Test
    public void testRunner() {
        String karateOutputPath = "target/cucumber-html-reports";
        Results results = Runner.parallel( getClass(), Constants.THREADS_FULL, karateOutputPath ); // we use threads 2 in order to avoid server connection error with response 500
        Runner.path("classpath:reusable/delete-tenant.feature").tags("@ignore").parallel(1); // workaround for delete tenant after tests are finished
        KarateHelper.generateReport( karateOutputPath );
        Assert.assertEquals( "Some scenarios did not pass the tests", 0, results.getFailCount() );
    }
}
Shahar Yigal
  • 71
  • 1
  • 1
  • 4

0 Answers0