Forum Discussion

jpriyan4's avatar
jpriyan4
Frequent Visitor
9 years ago

Soapui - How to maintain session from login post request to get request

Im using soapui(5.2.1) for webservice testing , not able to hit the rest api-Get request followed by post request (authentication).

Below are the scritps that i have

 

1 Login(Post request) - Login

2 SetCookie - Groovyscript

3.GetBasic(Get request) - To get json output data

4.RunAll(Run all the teststep (Post request,SetCookie,Get request) )- Groovyscript

 

First request is working fine , tried to hit get request but throws "this requires http authentication". I searched few blogs and written setcookie groovy script and below are the code.

 

def header = testRunner.testCase.getTestStepByName("Login").httpRequest.response.responseHeaders["Set-Cookie"]

header=header.toString()

start=header.indexOf("JSESSIONID=")

end=header.indexOf("; Path=")

testCaseProperty= header.substring(start,end)

testRunner.testCase.testSuite.setPropertyValue( "JSESSIONID", testCaseProperty )

testRunner.testCase.testSuite.project.setPropertyValue( "JSESSIONID", testCaseProperty )

log.info "jsession id - "+testCaseProperty

 

After that at GetBasic test step i set the header ${#TestSuite#JSESSIONID}.Then in RunAll script i have mentioned the step1,2,3 to run.

1.Login executed succesfully (username,password specified)

2.Set cookie executed succesfully

3.GetBasic(Get request) fails (throws "This requires http authentication")

 

But manually when i select the test case(check maintain session) and execute(Step1,2,3) it works fine

Please find the attached snap for the reference , can any one helpme on this please.

Note(Setcookie script set the cookie but it is not used by GetBasic get request)

No RepliesBe the first to reply