import com.eviware.soapui.support.types.StringToStringMap //Get all th cookies in the response , here the test step name is provided def cookiesList = testRunner.testCase.getTestStepByName("Login").testRequest.response.responseHeaders["Set-Cookie"] log.info cookiesList //Get the second cookie, only this one is must for PA API testing String cookieNew = cookiesList.get(1) log.info "cookie : "+cookieNew // Set the project level property : cookie , its value will updated with cookieNew testRunner.testCase.testSuite.project.setPropertyValue( "cookie", cookieNew ) //Put cookie to a StringMap def cookieMap = new StringToStringMap() cookieMap.put("Cookie",cookieNew) def testSuiteList = testRunner.testCase.testSuite.project.getTestSuiteList() def testCaseList def testStepList for(testSuite in testSuiteList){ log.info "Test suite number : "+testSuiteList.size() testCaseList = testSuite.getTestCaseList() for(testCase in testCaseList){ log.info "Test case number : "+testCaseList.size() testStepList = testCase.getTestStepsOfType(com.eviware.soapui.impl.wsdl.teststeps.RestTestRequestStep.class) log.info "Test step number : "+testStepList.size() for (testStep in testStepList){ log.info "Pass cookie to test step : "+testStep.name testStep.testRequest.setRequestHeaders(cookieMap) } } }
执行结果: