RequestFilter.filterRequest Script not triggered during test run
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
RequestFilter.filterRequest Script not triggered during test run
Hi All,
I'm trying to use a RequestFilter.filterRequest event handler to update my json test request when it contains a "null" value (inside double quotes) and replace it with null (without quotes). The reason the double quote gets added to my request payload is because i'm sending null as a value from my datasource step. The datasource step has multiple rows of data to handle all possible flavors of data (null, blank, maxlength, minlength etc) for the given field.
This is how my json request looks if i send null from my datasource step. I need to remove the wrapped quotes around null.
"key": "null",
I'd like to replace the above as follows.
"key": null,
Below is my event handler code added to RequestFilter.filterRequest
=================
def TestStep = context.getCurrentStep()
def RestStepName = TestStep.getLabel()
def reqContent = context.expand('${'+RestStepName+'#RawRequest}')
def content = reqContent.replaceAll("\"null\"", "null")
context.requestContent = content
log.info(context.requestContent)
When i log the context.requestContent using a groovy step, i get the encoded request but when the actual request gets submitted, "null" gets sent with double quotes instead of null (without quotes).
I also tried SubmitLister.beforeSubmit event with same code but the test step runs indefinitely (not sure what is the problem there).
I'm at a loss how to handle the above scenario. Please help
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Is it possible to use "Request" instead of "RawRequest" in your case?, I tried your code to remove "" for null using "Request" it worked for me.
EX:
def rawRequest = testRunner.testCase.getTestStepByName("GetREST").getPropertyValue("Request")
def content = rawRequest.replaceAll("\"null\"", "null")
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Tried Request instead of RawRequest and that doesnt work either..
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code snippet is doing the replace properly but when the actual test step is executed, the replaced value is NOT fed into the submitted request.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If youre struggling to get the event handler to sort it (even though from what youve described id expect it to successfully convert the text null into wellformed null datatype), you could import into a Properties step and change the datatype that way?
I appreciate this is far less efficient than using events as youd need to do this for each testcase that has a wellformed null in there, but it would work.
Ta
Rich
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Could you please explain more on "you could import into a Properties step and change the datatype that way?"..
I could'nt follow what you are suggesting..
