how to read Rawrequest using Script Assertion while using URI formats in the request ..SOLVED
how to read Rawrequest using Script Assertion while using URI formats in the request ..
My request is in URI format and not Xml. Now i need to read the rawrequest using Script Assertion. I tried this below piece of code. It is working at the Groovy level. But when i used this in Script Assertion (at the teststep level) it is failing.. i'm not getting the result
def request = testRunner.testCase.getTestStepByName("Request").getHttpRequest().getRequestContent()
Solved! Go to Solution.
The testRunner variable is not available in the ScriptAssertion window, you get the messageExchange exchange variable instead, this is the class WsdlResponseMessageExchange, and has the method getResponseContent() which you may find suits your needs.
Note: all the Groovy script editors provide slightly different pre-defined variable, depending on their location in Ready API, these are displayed on the top right of the script window, here is the Script Assertion window:
As you says.. when i use "getResponseContent() it reads the response and displayed.. i just swaped with "getRequestContent()".. Script Assertion is getting passed.. but i didnt get any info.. Take a look at the Screenshot
def requestXML = messageExchange.getRequestContent().toString() log.info requestXML
Sorry, my mistake! I answered if it were a SOAP request, I believe you have a REST request? If so the messageExchange variable is of class RestResponseMessageExchange, I am not sure why the getRequestContent() method is empty (I'm guessing that it's because there is no "content" to your REST request, all the information is in the actual HTTP request)
The following code:
def rawRequest = new String(messageExchange.getRawRequestData(), "UTF-8") log.info(rawRequest)
Seems to get what you may be after. The getRawRequestData() method returns a byte array, and then we use the String class constructor that takes a byte array argument to convert to a string (Not sure if there is a more "Groovy" way of doing this conversion).
Edit: Just wanted to point out that I have made the assumption that the raw request data is UTF-8 I haven't checked this.
Great! This works:)