M.Gawad
M.Gawad

Reputation: 65

Saving raw request & response of Soap test step in user defined path

I want to save soap test step raw request & step in a path which is read from configuration file imported in test suite custom properties.

How can I do that?

Using the below script but with fixed location that was defined in the script.

def myOutFile = "D:/TestLog/Online_Test/PostPaidSuccess_Payment_BillInqReq.x‌​ml" 
def response = context.expand( '${BillInq#Request}' ) 
def f = new File(myOutFile) 
f.write(response, "UTF-8")

Upvotes: 1

Views: 1497

Answers (1)

Rao
Rao

Reputation: 21389

I would suggest to avoid additional Groovy Script test step to just store previous step request / response.

Below script assumes that, there is user defined property (REQUEST_PATH) at test suite level with its value(valid file path to store data, path separated by forward slash '/' even on windows).

Instead use Script Assertion for the Billing request step itself(one more step less in the test case)

//Stores raw request to given location using utf-8 encoding
new File(context.testCase.testSuite.getPropertyValue('REQUEST_PATH') as String).write(context.rawRequest,'utf-8')

Actually there is a small difference between context.request and context.rawRequest and the above script using rawRequest.

context.request - will have the variables as it is, not the actual value.

For eg:

<element>${java.util.UUID.randomUUID().toString()}</element>

Where as context.rawRequest - will have the actual value that was sent in the request.

For eg:

<element>4ee36185-9bfb-47d2-883e-65bf6d3d616b</element>

EDIT Based on comments: Please try this for ACCESS DENIED issue

def file = new File(context.testCase.testSuite.getPropertyValue('REQUEST_PATH') as String)
if (!file.canWrite()) {
    file.writable = true
}
file.write(context.rawRequest,'utf-8')

EDIT2 Based on further comments from OP, the request file name should be the current test step name.

//Create filename by concatenating path from suite property and current test stepname
def filename = "${context.testCase.testSuite.getPropertyValue('REQUEST_PATH')}/${context.currentStep.name}.xml" as String
new File(filename).write(context.rawRequest,'utf-8')

Upvotes: 1

Related Questions