How to run Karate tests using maven with dynamic tags

Tags: , ,



I want to execute Karate tests using maven and pass the tags dynamically to the execution. I’m using junit4 and i tried both of the approaches – parallel and simple with @RunWith annotation.

@RunWith

package karate;

import com.intuit.karate.KarateOptions;
import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;

@RunWith(Karate.class)
@KarateOptions(features = "classpath:karate")
public class KarateTestIT {
}

Using this approach I’m able to pass the tags to the execution dynamically, but if the karate test fails the maven build is still successful.

Parallel

package karate;

import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import org.testng.annotations.Test;

import static org.junit.Assert.assertTrue;

public class KarateTestIT {

    @Test
    public void testParallel() {
        Results results = Runner.path("classpath:karate").tags().parallel(5);
        assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
    }
}

Using the parallel approach the maven build fails if the karate test fails. But I’m unable to pass the tags to the test via maven command options.

I’m running tests with command

mvn test -Dkarate.options="--tags @tag"
mvn test -Dkarate.options="--tags ~@tag"

Am I missing on something? Is there a way to achieve both dynamic tags and failure of maven build in case of karate test fail?

Answer

Most likely you ran into this bug: Karate 0.9.5 : Can’t get command line options in parallel execution

Can you try with 0.9.6.RC3 and confirm ?



Source: stackoverflow