karatelabs / karate

Test Automation Made Simple
https://karatelabs.github.io/karate
MIT License
8.32k stars 1.95k forks source link

Using feature files and test resources from custom locations #1978

Closed visasimbu closed 2 years ago

visasimbu commented 2 years ago

I have 2000 repos in my bitbucket which is segregated on 10 projects. Each repo has code which is written in IBM Integration bus/ACE. Means it is not Java application. This will expose a API. We plan to use Karate framework as our continuous testing in Jenkins pipeline.

So I have created one Java project with Runner Java class for POC. This worked!

Public class TestRunner {
     @Karate.Test
     Karate testFullPath(){
         return Karate.run("classpath:mypackage/path/sometest.feature");
         //return Karate.run("file:D:\\some\\path\\sometest.feature");
     }
}

With the plan of keeping this Karate framework Java project in separate repo. Maintaining all the feature files of 2000 in another separate repo for feature file maintainability.

When I try to pass the feature file from external drive like

return Karate.run("file:D:\\some\\path\\sometest.feature");

it fails with error message saying "java.nio.file.InvalidPathExceptino: IIlegal char <:> at index 4: file:D:\some\path\sometest.feature" ...

Is it possible to call the feature files which is reside outside of Java project ? Please help me on this.

I have tried below 2 options to fix the problem.

1) I tried to use the Runner by using below snippet. This also returns exacts same error.

@Test
public void testSelected() {
  List < String > tags = Arrays.asList("~@skipme");
  List < String > features = Arrays.asList("file:D:\\some\\path\\sometest.feature");
  String karateOutputPath = "target/surefire-reports";
  Results results = Runner.path(features)
    .tags(tags)
    .outputCucumberJson(true)
    .reportDir(karateOutputPath).parallel(5);
  DemoTestParallel.generateReport(karateOutputPath);
  assertTrue(results.getErrorMessages(), results.getFailCount() == 0);
}
  1. Explored and found the karate netty standalone jar file. I have downloaded the JAR file from maven repo and executed directly. Even when I run the jar file using java -jar karate-1.2.0.RC2.jar demoAPI.feature. I am getting error as "Exception in thread main java.lang.NoClassDefFoundError: org/sl4j/LoggerFactory ..."

It seems it was expecting its dependecy of slf4j. How can I download all its dependencies and execute standalone JAR.

ptrthomas commented 2 years ago

@visasimbu for anyone to help you, a working example is required. please re-read this and follow the instructions exactly as presented: https://github.com/karatelabs/karate/wiki/How-to-Submit-an-Issue

the only way we support re-use of feature files from a different "project" is a) via the classpath and b) via java artifacts (typically JAR files). it does require advanced knowledge of Karate and perhaps there is scope for more contributions to open-source. I'm afraid I can't help more than this.

maybe you can read these discussions that may help:

https://stackoverflow.com/a/58339662/143475 https://stackoverflow.com/a/56553194/143475

If those don't help, please assume that what you are asking for is not supported by Karate. It certainly is not a priority for the project developers.