0

I have a REST API project in SOAP UI which contains 20 test cases in a test suite. I want to add some header value and sslkeystore in every test step. Here is my code.

import com.eviware.soapui.support.types.StringToStringMap

testCaseList = testSuite.getTestCases()
         testCaseList.each
           {
             testCase = testSuite.getTestCaseByName(it.key)
             restTestSteps = testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)//only RestTestRequest steps

             restTestSteps.each
              {
                it.getRestRequest().setHttpHeader("TEST2")
                it.testRequest.setSslKeystore("**************")

                }
             }

Above code "TEST2" contains the header value that I want to add to every test cases. I have configured TEST2 in ws-security configuration under outgoing ws-security configuration. But in above code I am getting following error:

groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.getRestRequest() is applicable for argument types: () values: [] Possible solutions: getTestRequest(), getHttpRequest()

Anybody help me please how can I add header value in every test steps.

Rao
  • 20,781
  • 11
  • 57
  • 77
Mohammad Hasan
  • 123
  • 1
  • 6
  • 22
  • `header` is something which can be added to test steps, but not for test case. By the way, it is not sure from the above description that where is the `TEST2` present (in which test case)? How it is going to get the response for that step first? – Rao Oct 10 '17 at 21:52
  • @Rao Sorry for mistake it should be test steps...I edited my post...Here TEST2 is name where i set up header value like username and password that should be added to every test steps. From soup ui double click project > Ws-security configuration > outgoing Ws-security configuration> click + sign where we can add wss entry like username and password... So finally I need to add these two values (username and password) to add every test steps in test suite. – Mohammad Hasan Oct 10 '17 at 23:13
  • Are you using ReadyAPI? – Rao Oct 11 '17 at 02:12
  • Yes I am using ReadyAPI – Mohammad Hasan Oct 11 '17 at 04:52

2 Answers2

1

If you want to add header value and sslkeystore in every test step, then add these values as Properties OR Custom Properties in Project. Then assign these values in each step. Are you willing to do this with groovy script?

1

If you want to set the header values for each step in a test case, you can create a groovy test step that will do this. Place the groovy step at the beginning of the test case and it will work even if you change or add new steps. I'm sure you could tweak the getAllHttpSteps to include all test cases in the suite as well, and place this as the first test run.

/**
 * This script populates all http requests in a test case with headers: 
 */
import com.eviware.soapui.support.types.StringToStringMap
// make a list of all http rest requests
getAllHttpSteps=testRunner.testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep)
// iterate through the list of requests and populate the request headers
for (step in getAllHttpSteps)
{
    def headers = new StringToStringMap()
     headers.put("SomeHeader", "SomeHeaderValue")
     headers.put("sslKeystore", "keystoreValue")
}
DustinR
  • 26
  • 1
  • 3