Hello,
I have a problem with storing in GlobalVariable my authorization
token, which I want to use in other test cases.
I’ve tried to do this in Postman and it’s works perfectly,
but not in Katalon…
What I want to do:
[tc-1] POST auth_token
and store access_token and refresh_token in GlobalVariable
[tc-2] GET user list
using access_token
How code looks [tc-1]:
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.google.common.util.concurrent.CycleDetectingLockFactory.ExampleStackTrace
import
com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import
com.kms.katalon.core.checkpoint.CheckpointFactory as CheckpointFactory
import
com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as MobileBuiltInKeywords
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.testcase.TestCaseFactory as
TestCaseFactory
import
com.kms.katalon.core.testdata.TestData as
TestData
import
com.kms.katalon.core.testdata.TestDataFactory as
TestDataFactory
import
com.kms.katalon.core.testobject.ObjectRepository as ObjectRepository
import
com.kms.katalon.core.testobject.TestObject as
TestObject
import
com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WSBuiltInKeywords
import
com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import
com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUiBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords
as WebUI
import internal.GlobalVariable as GlobalVariable
import groovy.json.JsonSlurper as JsonSlurper
import
com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.testobject.TestObjectProperty
import
com.kms.katalon.core.testobject.ConditionType
‘Send a REST request and return its response’
def response = WS.sendRequest(findTestObject(‘Object
Repository/QA_POST_AUTH_TOKEN’))
‘Store access_token’
def jsonSlurper = new JsonSlurper()
def res = jsonSlurper.parseText(response.getResponseText())
AutToken = res.access_token
println AutToken
GlobalVariable.AutToken = AutToken
As I can see in console, access token is printable. But when
I try to run [tc-2] there is no
AutToken (the string is empty)
In case of Postman, I’ve used this:
var jsonData =
JSON.parse(responseBody);
postman.setGlobalVariable(“access_token”,
jsonData.access_token);
And access_token is stored in GlobalVariable, which I can
use in next test case…
I’ve tried everything what I could find in Katalon forum and
in the internet