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.

Revisions

  1. imadi created this gist Jan 22, 2017.
    17 changes: 17 additions & 0 deletions SoapUISessions.groovy
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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())