Search code examples
pom.xmlkarateweb-api-testing

How to use custom path in karate feature file?


In the karate feature file, classpath is - "scr/test/java"

But instead, the detailed "classpath:examples/resources/module1/sub_module/test.json" path, Is there any other way that hides the detailed path? like

Here, My expectation is Instead of

  • def file1 = read(classpath:examples/resources/module1/sub_module/test.json)

I want to use

  • def file1 = read(customclasspath:test.json) or similar to this which can hide the full path details of any file in the feature file.

Solution

  • Just use a variable?

    * def myPath = 'classpath:foo/bar/'
    

    And then later:

    * def file1 = read(myPath + 'test.json')
    

    More hints on variable substitution can be found here: https://stackoverflow.com/a/73230200/143475