Using multiple tags to run in karate options

Viewed 11371

Let's say I have 4 feature files which is written in karate version 0.9.0. I am tagging feature 1 with @F1, feature 2 with @F2, feature 3 with @F3, feature 4 with @F4.

On the other hand, I have a runner class which is placed in the root all of those feature files. Now I want to run @F1, @F2 AND @F3 but not @F4 tags.

I am using KarateOptions as below:

@KarateOptions(tags = {"@F1", "@F2", "@F3", "~@F4"} )

Apparently, I am doing something wrong since there are no any output is being appeared in my cucumber-html-reports file.

Thanks in advance.

EDIT 1: Here is my whole runner class code:

@KarateOptions(tags = {"@F1", "@F2", "@F3", "~@F4"} )
public class TestRunnerAutomation {

@Test
public void testParallel() {
    Results results = Runner.parallel(getClass(), 5);
    generateReport(results.getReportDir());
    assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}

public static void generateReport(String karateOutputPath) {
    Collection<File> jsonFiles = FileUtils.listFiles(new File(karateOutputPath), new String[] {"json"}, true);
    List<String> jsonPaths = new ArrayList(jsonFiles.size());
    jsonFiles.forEach(file -> jsonPaths.add(file.getAbsolutePath()));
    Configuration config = new Configuration(new File("target"), "demo");
    ReportBuilder reportBuilder = new ReportBuilder(jsonPaths, config);
    reportBuilder.generateReports();
}
}
1 Answers

For running tests using tags with multiple conditions, we need to use logic conditions in tags.

AND:

To run every feature that has both @F1 and @F2 tags.

{"@F1", "@F2"}

OR:

To run every feature that has either of the @F1 and @F2 tags (runs both)

{"@F1,@F2"}

Combining OR and AND:

To run feature that has either of @F1,@F2,@F3 tags but not @F4 tag

{"@F1,@F2,@F3","~@F4"}

Related