SOAPUI Extract data from SOAP Response and use in REST request - rest

I have been looking at the answer to this question:
Pulling details from response to new request SoapUI
which is similar to what I am looking for but I can't get it to work.
I have a small SOAPUI testsuite and I need to extract a value from the response of a SOAP request and then use this value in a subsequent REST request.
The response to my SOAP request is:
<ns0:session xmlns:ns0="http://www.someurl.com/la/la/v1_0">
<token>AQIC5wM2xAAIwMg==#</token>
</ns0:session>
so I need the token to use in my REST request. I know it involves using Property Transfer and some XPath / XQuery but I just can't get it right. At the moment my property transfer window points to Source: SOAP test Property: Response and has data(/session/token/text()) in the text box. In target it has Target: REST testcase Property: newProp and I have Use XQuery checked.
Any help greatly appreciated.
Thanks,
Adrian

I think you just need to declare the namespace ns0 and use it in the XPath. Also, uncheck the XQuery, it is only used when you are using XQuery, not XPath.
Replace your expression with this:
declare namespace ns0='http://www.someurl.com/la/la/v1_0';
/ns0:session/token/text()

Related

load and performance test of the AWS API in jmeter using two post methods

I need to test the load and performance test of the API which is hosted in the AWS API gate way. Im using two post methods to get the final result. first post method will pass the below parameters in json format in the API.
{
propno:"xxxxx",
apikey:"xxxx-xxxx",
user:"xxx"
}
by executing this i will get a reference number and status of the execution
{
reference:"ABxxxxxxxxxna",
status:"ok"
}
Then will pass this reference no in another post method to get the desired result.
{
refno:"ABxxxxxxxxxna",
apikey:"xxxx-xxxx",
user:"xxx"
}
Now i want to perform the load test in Jmeter. Any help would be appreciated.
What is your question exactly?
In JMeter you can send a POST request using HTTP Request sampler, the relevant configuration would be something like:
the refno value can be fetched using JSON Extractor configured like:
next in the second HTTP Request use ${refno} reference to the JMeter Variable
You might also need to add a HTTP Header Manager and configure it to send the Content-Type header with the value of application/json
once done you can
Add more users in the Thread Group according to your NFR/SLA/common sense/whatever
Run your test in command-line non-GUI mode
Generate HTML Reporting Dashboard and analyze the results

Jmeter - Set custom text on request tab using JSR223 sampler

I am creating a script on groovy to be able to send http requests.
To call this script I'm using the JSR223 Sampler
The thing is that I would like to reproduce as much as possible the behaviour that a HTTP Sampler has, meaning that I want to perform the request and also to fill the sampler's info (Response data, Request and Response)
Although I'm able to obtain SampleResult and set Response data and Response, does not seem to exist a method to set our own request string:
https://jmeter.apache.org/api/org/apache/jmeter/samplers/SampleResult.html
Following the docs, the closest method to do what I want is the setRequestHeaders().
If I call that method like this SampleResult.setRequestHeaders("My custom text") something like this appears on the request tab:
File C:\Users\UserName\groovy_file.groovy
Request Headers:
My custom text
Is there any way to print only the string My custom text, on the Request?
EDIT
Sampler must use a script file instead of the script field
The easiest way would be just overwriting the data using prev.samplerData() shorthand from the JSR223 PostProcessor
prev.samplerData = 'put the desired request data here'
where prev stands for the parent SampleResult class instance, check out Top 8 JMeter Java Classes You Should Be Using with Groovy article for more information on the JMeter API shorthands available for the JSR223 Test Elements.
If you don't want the PostProcessor you can still call the same function from your Groovy script like:
SamplerResult.setSamplerData('put the desired request data here')

How can I pass a parameter from XML Response tag in a new GET XML Request in Soap UI?

I have tried to find a solution in this community in different threads but yet to find one that I am looking for.
I am using SoapUI version 5.3.0 My Application have a couple of RESTful APIs. Initially I am sending json request to a WebService and getting back the following XML Response:
<StartDataExtractResult xmlns="http://schemas.datacontract.org/2004/07/AriaTechCore" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<StatusCode>1</StatusCode>
<StatusText>success</StatusText>
<RequestNumber>397</RequestNumber>
</StartDataExtractResult>
As soon as RequestNumber tag is generated. I have to access to 2 more XML EndPoints (where the value of RequestNumber is appended) to know the Status as below:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/396
B.
http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/396
As of now, I have created the 2 seperateTestSteps for the above mentioned XML Endpoints:
A. http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/
B. http://quickextract.quickaudit.in/webs/quickextract.svc/GetRequestStatus/
Now I need to append the value within tag in the GET Request to get back a response from the WebServices.
Update:
I have created a 'Property Transfer' at Testsuite level as "TSreqNum". This 'Property Transfer' is getting updated as per the initial Response. But I am not sure how would I append "TSreqNum" to construct the complete GET Request as:
http://quickextract.quickaudit.in/webs/quickextract.svc/GetExtractionDetails/TSreqNum
Can anyone help me out please?
You can use the property within the URL of the GET request:
http://host:port/path/${#TestSuite#TSreqNum}
The URL gets updated with the property value.

How to produce both xml and json for a rest based service?

I am trying to produce both xml and json from my rest service.
#Produces({"application/xml", "application/json"})
However, when I try to use the service using curl/SOAPUI, I get back either xml or json depending on which is mentioned first. In simple words, only the first method is considered. Is there a workaround?
You should check this link out - oracle docs for #Produces
The spec says that it does indeed default to the first one if that is acceptable as specified by the media type on the request. You should check your soapUI tool and see what headers you are sending. If they are both being sent you will get a response with the first one listed in your #Produces annotation.

Get form parameters from a post request using spray/scala

I'm really new with all this Scala/Spray. With some testing I was able to get parameters from a Get request using the parameters function. However I'm trying to fetch some parameters sent from a POST request on the body of the request. It seems like parameters function is unable to fetch those values.
As an example, I'm trying to get this values "name=john&lastname=smith" from the post request body. What is the best option to get these values?
Thank you
You could use [Form-Field-Filters] to extract parameters from POSTs
[Form-Field-Filters] https://github.com/spray/spray/wiki/Form-Field-Filters
Indeed, the parameters directive only handles things actually in the query-string and not parameters in the body of the request. To get things out of the body, you'll need to use the content directive and then unmarshal the content.
This spray-user thread may be helpful, as it includes some unmarshalling code doing precisely what you're looking for.
As of recent Spray versions, you need to use the Unmarshaller for FormData.