Sourabh Chapali
Sourabh Chapali

Reputation: 391

Karate - How to use karate-config.js variables in java file?

I have a DB utils java file where I need to load DB username password based on environment I am running the code on , and these environment values I need to import from karate-config.js . How to achieve this ?

Upvotes: 1

Views: 953

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

Just use embedded expressions ! So if you have dbusername and dbpassword set in karate-config.js:

* def config = { username: '#(dbusername)', password: '#(dbpassword)', url: 'jdbc:h2:mem:testdb', driverClassName: 'org.h2.Driver' }
* def DbUtils = Java.type('com.mycompany.DbUtils')
* def db = new DbUtils(config)

Upvotes: 2

Related Questions