Skip to content

Instantly share code, notes, and snippets.

@imadi
Created January 22, 2017 03:04
Show Gist options
  • Select an option

  • Save imadi/3540184759c99175c7c36d532bff7b0a to your computer and use it in GitHub Desktop.

Select an option

Save imadi/3540184759c99175c7c36d532bff7b0a to your computer and use it in GitHub Desktop.
Using session id in between requests in SoapUI using groovy script
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