How do i store dynamic session id in variable


#1

I am having some difficulty to get dynamic session id to store in variable

even i try below


tell me about session


#2

Create global variable in the profile level.

ex: in my scenario, I have created one global variable called ‘token’.

Then Call your post method, which you have created in the object repository. Like below code.

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import static org.assertj.core.api.Assertions.*
import com.kms.katalon.core.testobject.RequestObject as RequestObject
import com.kms.katalon.core.testobject.ResponseObject as ResponseObject
import com.kms.katalon.core.webservice.verification.WSResponseManager as WSResponseManager
import groovy.json.JsonSlurper as JsonSlurper
import groovy.json.JsonSlurper

tokenGen().toString()

def token
String tokenGen() {
def response = WS.sendRequest(findTestObject(‘GenerateAccessToken’))
def jsonSlurper = new JsonSlurper()
def slurper = new JsonSlurper()
def result = slurper.parseText(response.getResponseBodyContent())
def token = result.access_token
WS.verifyResponseStatusCode(response, 200)
println(token)
GlobalVariable.token = token

}

Using this code you can get any value from your response.

Please reach out to me, if you have any questions.


#3

Thanks… That worked out.