Pruebas con problems automating the Token of my api test

I am trying to automate the generation of the token so that my test can be deployed in the cloud.

I reviewed the documentation and different posts and managed to create the execution and printing of my token, with the following code:

tokenGen (). toString ()

def token

String tokenGen () {

 def response = WS.sendRequest (findTestObject ('GenerateAccessToken'))

 def token = response.getHeaderField ("Authorization")

WS.verifyResponseStatusCode (response, 200)

println (response.getHeaderField (“Authorization”))

 GlobalVariable.token = response.getHeaderField ("Authorization")

println (token)

}

But I have the problem that this is not being pasted in the global variable therefore it is not authenticating the api test

1 Like

i’m doing this (SOAP Requests) and also cannot save to a globalVariable.
So also interested in this thread

String rToken = response.getResponseText()

String Token = println((rToken.split(’<a:Token>’)[1]).substring(1, 36).trim())

GlobalVariable.Token = Token

@rtetrault It may be only a copy and paste ooops, but your String Token is equated to a println function. A println has a return type of void, so you should get nothing as the result in Token. Hover your mouse over the println keyword within the KS application and it should display information on the word, including its return type. If you want to have rToken result set in Token, you will have to remove the println statement.

String rToken = response.getResponseText()

GlobalVariable.Token = (rToken.split(’<a:Token>’)[1]).substring(1, 36).trim()

1 Like

Not an copy and paste opps. I’m still very much a junior programmer. I appreciate the reply and will look at what you explain below.

Again, really appreciate the advice. :+1:

Update. Remove println and creating globalvariable and transfer to next call now works! Thank you so much. Been working on this on and off for many days now, trying to see how SOAPUI Transfer property worked and transferring that to Katalon’s way of doing was not an easy task.

If anyone needs specifics on how to transfer dynamic response elements to next call, reply and i will do a write up.