Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XML request templating #48

Closed
venkatesgopi opened this issue Apr 25, 2017 · 5 comments
Closed

XML request templating #48

venkatesgopi opened this issue Apr 25, 2017 · 5 comments
Assignees
Milestone

Comments

@venkatesgopi
Copy link

venkatesgopi commented Apr 25, 2017

Do you have any option for SOAP XML request template and reusing example table
In the below example there are two place holders one for filling firstName and lastname
i will define EXAMPLE table with firstName and lastName alone but i dont define AGE in that case AGE tag should be get removed.

Sample
XML request format

<query>
<name>
<firstname>${firstName}</firstname>
<lastname>${lastName}</lastname>
</name>
<age>${age}</age>
</query>

Could you please provide solution for this scenario

@ptrthomas
Copy link
Member

That is a great question and for the time being I don't have a great solution for the conditional age tag other than using a JavaScript function, but I see a gap where manipulating XML inside JS may not be supported fully yet.

The way Karate is designed, you can certainly achieve this if you call some Java code. Take a look at Java interop. Meanwhile I will consider this as a feature request.

Hope you are aware that XML templating works exactly like JSON where any element (or attribute) values in the #() form will evaluate expressions within the brackets.

@venkatesgopi
Copy link
Author

venkatesgopi commented Apr 25, 2017

thanks for the prompt reply. i tried <SubjectName>#(name)</SubjectName> but stil its got failed with below log line. any clue?

Examples:
|name|
|venkat|
|gopi|

00:10:26.991 [main] WARN com.intuit.karate.Script - embedded xml-text script eval failed: script failed: (name)

@ptrthomas
Copy link
Member

Try something like this:

* def name = '<name>'
* def query = <SubjectName>#(name)</SubjectName>

@ptrthomas ptrthomas added this to the v0.4.0 milestone Apr 30, 2017
@ptrthomas
Copy link
Member

@venkatesgopi not sure if you are watching this ticket, but can you try this example:

https://github.com/intuit/karate/blob/3450222b44dec17dacff46a8087db0a199d19547/karate-junit4/src/test/java/com/intuit/karate/junit4/demos/xml-and-xpath.feature

This should work in version 0.4.0-SNAPSHOT

I'd like to know if this works for you.

@venkatesgopi
Copy link
Author

Thanks lot for the support. i will check and get back to you very soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants