Show sent request in groovy script in SoapIU - soap

I try to create integration tests in SoapUI:
There are property myId=1234 in property file.
I send soap request (named myRequest) contains <messageId>${myId}</messageId>
This request is valid, because ${myId} is replaced by 1234. I receive response.
In my groovy script I want show sent request, value of <messageId>:
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def request = groovyUtils.getXmlHolder("myRequest#Request");
log.info(request["//messageId"]);
output: ${myId}
Expected output: 1234
Do you have any idea?

It is possible achieve this without using an additional Groovy Script test step by using Script Assertion for the same request step.
Use below Script Assertion to show the request along with values being replace or the actual request being sent to the server.
//Check if you have got the response
assert context.response, "Response is null or empty"
//show the actual request is being sent
log.info context.rawRequest

Related

Postman multiple responses on a single request

I want to run unit tests in my program whenever the api receives a request. the api returns a response once when it has received a valid request, but then later it will send once it's done with the unit tests. The first response is shown in Postman, but not the second repsonse. I can see that it getting send using wireshark though.
These are two separate responses and since this api is what it is, I don't have the power to change it. How can i use Postman to receive the second response as well?
Edit additional information is requested so:
I have in my collection a POST request and when I trigger it I get a response back with a body with:
{
"messageType" : "Response"
"options" : "async"
}
Then the code can see that another response is incoming later, because of the async token.
A bit later another response is received:
{
"messageType" : "Response"
"Tests" : "11 ok tests"
}
But in postman I can't seem to receive the second response, as the transaction is finished after the first one. How can I make postman also receive the second response?

Trying to do some assertion from request, which will be present in response

I am passing the request as in my feature file and i am trying to do assert from request to response.
I have tried must contains queries but i am not sure if i am doing it correct, could you please help.
**Background:**
* configure headers = read('classpath:merchantServiceheaders.js')
Given url MservUrl
And path '/spapis/rest/sp-ms-engine/sp/ms/v1/engine/scanandredact'
Scenario Outline: ACH Low Value Payment Rips Services Summary
]
}***
What i would like to do is assert what i have in my request to what i will get back in response.
Since i am passing subject in request the same subject should be present in response
Possible in 0.9.3: https://github.com/intuit/karate#scenario-outline-enhancements
First change the Examples: column header to data!
And request data
When method post
Then status 200
And match response contains data
In 0.9.2 and earlier, with the Examples: column header as data
* def data = <data>
And request data
When method post
Then status 200
And match response contains data

How to make the search parameters in http request as dynamic in jmeter

http request: http://ipAddress:Port/SomeResource?Param1=value1&Param2=value2&......
so on.
This is a http request sample in jmeter that hits a rest api and gets response in JSON format.
Here the challenge is Param1, param2, param3 .... these search parameters number is not constant it may change depending on the call so i am making a csv file that contains rows that contain search parameters in coma separated format.
CSV file is like
param1,param2
param1,param2,param3
param1
I am using a CSV data configure to pull data from the csv file and put it in the http request
And putting this in http request like
Now if the param is null i don't want see this in http request header
so how to do this in jmeter.
Remove all "Parameters" from the HTTP Request, it should be clean
Add JSR223 PreProcessor as a child of the HTTP Request sampler you would like to parameterize
Put the following code into "Script" area:
1.upto(4, {
if (vars.get('param' + "$it") != null) {
sampler.addArgument(vars.get('param' + "$it"),'someValue')
}
})
Add JSR223 PostProcessor as a child of the request you would like to parameterize
Put the following code into "Script" area:
1.upto(4, {
vars.remove("param" + "$it")
})
That's it, you should now get what you need. You will not see the changes in JMeter GUI, you will only be able to observe them in the runtime using View Results Tree listener

Postman Test Script - Check that the status is NOT 200

I'm creating a script to test my API, I want to check that if the user doesn't enter the correct username and password, the access is denied.
I want my test to pass when the status code is 401. Postman displays a test failure because the status code of my request is not 200.
I actually WANT my response to be 401 in order to pass the test.
Any idea on how to operate ?
Cheers
I tried using this test:
pm.test("Status code is 401", function () {
pm.response.to.have.status(401);
});
This test passes, but Postman is displaying a failed assertion:
response is ok | AssertionError: expected response to have status code
200 but got 401
I just created a new folder and started again from scratch and it worked. I wasn't able to find where the problem was coming from though...
The parent folder may have the "200" test configured in it - thus inheriting it.

Jmeter : How to check for empty text response

I am writing a jmeter framework to validate Rest web services.I have a csv file having the list of URLS , Response code and response messages Eg :
/api/input/checkUploadRequirement application/x-www-form-urlencoded 200 NOTREQUIRED
likewise I have many URL's.Few of the URL's does not return anything and for them I have empty cell\field in the csv file Eg:
/api/input/savedetail sessionTrackingID=58ec9684-dfd-4c8f4796-f897 application/x-www-form-urlencoded 200 .
Now If I validate the empty Text response in Jmeter for above URL, I am getting "Assertion failure message: Response was null"
Please help me to validate empty text response from http request
You can use Size Assertion and test for size of response:
http://jmeter.apache.org/usermanual/component_reference.html#Size_Assertion
You can do it via Beanshell Assertion. If null response is something you expect, substitute Response Assertion with Beanshell Assertion. Use the following code in "Script" area:
if (ResponseData.length != 0) {
Failure = true;
FailureMessage = "Expected empty response, got: " + new String(ResponseData);
}
This code will mark parent sampler as passed if response is empty and fail it if even a single character will be returned.
See How to Use JMeter Assertions in Three Easy Steps guide for advanced information on conditionally setting pass/fail criteria in your JMeter test