Search code examples
karate

Reading data from .properties file in Karate DSL


We are trying to co exist with another java project which uses Webdriver etc. As part of this we would like to re use the same .properties file that is being used by other project for our configuration etc. Could some one guide us on reading from .properties file in Karate DSL.


Solution

  • There is nothing built in to Karate - but the solution for you is clear, write a simple Java utility to read a properties file - or since it is so simple, you should be able to do this even in JS, in the karate-config.js itself.

    And also refer this: https://github.com/intuit/karate#calling-java

    I haven't tested the below code, but you get the idea:

    * def stream = read('classpath:myfile.properties')
    * def props = new java.util.Properties()
    * eval props.load(stream)
    

    EDIT: In newer versions of Karate you need to do this instead: https://stackoverflow.com/a/76765153/143475