Created
January 22, 2017 03:04
-
-
Save imadi/3540184759c99175c7c36d532bff7b0a to your computer and use it in GitHub Desktop.
Using session id in between requests in SoapUI using groovy script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def testStep= testRunner.runTestStepByName("User") | |
| def response = testStep.response | |
| def cookies = response.responseHeaders["Set-Cookie"].toString() | |
| String cookie = cookies.split(";")[0] | |
| def regex = /(JSESSIONID=[A-Za-z0-9.]+)/ | |
| matcher = ( cookies =~ regex ) | |
| def jsessionId | |
| if(matcher.find()){ jsessionId = matcher[0][0] } | |
| log.info("sessionId : " + jsessionId) | |
| //get UserAddress | |
| testStep = testRunner.testCase.testSuite.getTestCaseByName("Login").getTestStepByName("UserAddress") | |
| def testRequest = testStep.getTestRequest() | |
| def headers = testRequest.requestHeaders | |
| headers.put('Cookie',jsessionId + '; Path=/; Secure') | |
| testRequest.requestHeaders = headers | |
| testStep = testRunner.runTestStepByName("UserAddress") | |
| log.info("response : " +testStep.response.getContentAsString()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment