Reputation: 384
I have a karate feature where there is a POST multipart form request with no files. I don't have access to the server to be able to debug it or see how the code is written there. Here is the feature file snippet:
Given url apiurl
And multipart field RI = xmlRIString
And multipart field CI = xmlCIString
And multipart field BI = xmlBaseString
"xmlRIString", "xmlCIString" and "xmlBaseString" are XML strings. This code does not work and I am not 100% sure why. I suspect those fields are empty for some reason.
Here is the request taken out of the Postman logs which works on the server (the request body was modified to not share the sensitive data):
POST /submit HTTP/1.1
User-Agent: PostmanRuntime/7.22.0
Accept: */*
Cache-Control: no-cache
Postman-Token: ceac2d58-dd33-426b-bde5-26a0846d6385
Host: localhost:8001
Content-Type: multipart/form-data; boundary=--------------------------725566702214297796531881
Accept-Encoding: gzip, deflate, br
Cookie: some-cookie-value-here
Content-Length: 47864
Connection: keep-alive
----------------------------postman
Content-Disposition: form-data; name="RI"
<REQUEST_GROUP>some xml here</REQUEST_GROUP>
----------------------------postman
Content-Disposition: form-data; name="CI"
<REQUEST>some xml here</REQUEST>
----------------------------postman
Content-Disposition: form-data; name="BI"
<ABOUT_VERSIONS>some xml here</ABOUT_VERSIONS>
----------------------------postman--
Here is also the cURL request which also works:
curl --location --request POST 'http://localhost:8001/upload' \
--header 'Content-Type: multipart/form-data; boundary=--------------------------725566702214297796531881' \
--form 'RI=<REQUEST_GROUP>some xml here</REQUEST_GROUP>' \
--form 'CI=<REQUEST>some xml here</REQUEST>' \\
--form 'BI=<ABOUT_VERSIONS>some xml here<ABOUT_VERSION>'
So the question I am asking how should I create my karate feature so it results in a request I shared above.
Thanks in advance!
Upvotes: 1
Views: 142
Reputation: 58088
You should be able to figure this out quickly with the cURL command and https://httpbin.org/anything
Try this snippet in Karate:
* url 'https://httpbin.org/anything'
* multipart field RI = '<foo></foo>'
* multipart field CI = '<bar></bar>'
* multipart field BI = '<baz></baz>'
* method post
You can see the server respond with this section:
"form": {
"BI": "<baz></baz>",
"CI": "<bar></bar>",
"RI": "<foo></foo>"
}
And this cURL command gets you the same result:
curl --location --request POST 'https://httpbin.org/anything' \
--form-string 'RI=<foo></foo>' \
--form-string 'CI=<bar></bar>' \
--form-string 'BI=<baz></baz>'
Now you should be able to figure this out, note that sending XML via cURL can be tricky. You can easily tweak your Karate script to match what your working cURL command is doing 100%.
Also in Karate - note that you may need a second step to convert XML to string depending on how you set up your XML parts: https://github.com/karatelabs/karate#type-conversion
But XML variable substitution should work fine:
* def myXml = <foo>hello</foo>
* url 'https://httpbin.org/anything'
* multipart field RI = myXml
* method post
Upvotes: 0