RunScript returning multiple values not always work


#1

Hi,

I want to return multiple values from JS in runScript. It’s impossible to return many values at once so i use a little trick and try something like this:

runScript | var i = 1; var j = 2; var k = 3; |
runScript | return i; | i
runScript | return j; | j
runScript | return k; | k

In first run, command with return “i” throw an error that “i” is not declared. So i change first runScript to addScript and then it’s works fine. Furthermore when i change it back to runScript it work fine from now on. It’s just happening from time to time. It’s not a big deal because after change command ot works fine but what if it will happen in real live situation not just checking how to return many values? It could be frustrating then.


Katalon Automation Recorder - Tips and tricks
#2

I found a way around this problem i think. I found this topic: Array in Katalon Recorder and i modify it a little bit to work in actual version of Katalon. And then i modifed it even more so i have two way to workaround this problem.

1 version:

runScript | var i = 1; var j = 2; var k = 3; |
storeEval | 0 | loop
while | ${loop}<=2 |
storeEval | array[${loop}] | element${loop}
storeEval | ${loop} + 1 | loop
endWhile

This version is good if you have a lot of values to store in Katalon from just one JS code.

2 version:

runScript | var i = 1; var j = 2; var k = 3; |
storeEval | array[0] | element0
storeEval | array[1] | el1
storeEval | array[2] | something

This is bettter if you want to give your vars diffrent names like shown in the example. It 's also easier to understand to people how are new in Katalon.