I\'ve a need where I should use dynamic values in the features of my karate tests.
I\'ve came accross with some of the questions and answers like this: How to read input
I am providing a simplified example below, but am sure you will find the answers to your questions here. It is easy to loop over data and build XML in Karate using the karate.set(varName, xPath, value)
API:
* table users
| accountNo | subsID | mobile | subsType |
| '113888572' | '113985218890' | '1135288836' | 'asd' |
| '113888573' | '113985218891' | '1135288837' | 'qwe' |
| '113888582' | '113985218810' | '1135288846' | 'asd' |
* def xml =
* def fun =
"""
function(u, i) {
var base = '/users/user[' + (i + 1) + ']/';
karate.set('xml', base + 'account', u.accountNo);
karate.set('xml', base + 'mobile', u.mobile);
karate.set('xml', base + 'type', u.subsType);
}
"""
* eval karate.forEach(users, fun)
* match xml ==
"""
113888572
1135288836
asd
113888573
1135288837
qwe
113888582
1135288846
asd
"""