Karate API Tests - Using xml instead of json

Viewed 1828

I am able to use json file to have my credentials parsed in the feature file. eg:

 * def credentials = read('classpath:credentials.json')
 * header Authorization = call read('classpath:basic-auth.js') { username: '#(credentials.user)', password: '#(credentials.pwd)' }

Here is the credentials json file:

{
  user: 'abc',
  pwd: 'def'
}

However, When I try using an XML file instead, I am not able to parse it through:

Credentials xml file:

<?xml version="1.0" encoding="UTF-8" ?>
 <credentials>  
   <user>abc</user>
   <pwd>def</pwd>
 </credentials>

I changed the feature file as:

 * def credentials = read('classpath:credentials.xml')
 * header Authorization = call read('classpath:basic-auth.js') { username: '#(<credentials><user></credentials>)', password: '#(<credentials><pwd></credentials>)' }

Do i need to make any changes in the way I am parsing the xml ? Any suggestions would be appreciated. Thanks in advance!!

1 Answers
Related