0
votes

I want to get the value of the "Accept" Header from a SoapUI request. Then I want to store it in a TestCase property.

That is what I'm trying to do from a Groovy script TestStep:

//Get Accept Header from request (if Accept Header does not exist default to empty string)
def acceptHeader = context.testCase.getTestStepAt(0).testRequest.requestHeaders.get("Accept", "")

//Set Accept Header Value to current TestCase properties
testRunner.testCase.setPropertyValue("acceptHeaderSet", acceptHeader)

The first TestStep of the TestCase is a REST Request and the second TestStep is the mentioned script.

Each time that I run the TestCase the default value is set (it seems that it does not find any header)

Any idea about what is happening? Is this a bug in the SoapUI tool?

Thanks in advance.

2

2 Answers

1
votes

This works for me: testRunner.getResults()[0].getRequestHeaders()["Accept"]

This will only work if you run the entire testcase, otherwise there are no results to get. Maybe your method ran into a similar issue.

0
votes

I would try to settle such situation using properties. Just define property (e.g. on project level) and then change its value. Like described here Script access to properties