I am wondering how to pass the test data from a Global Variable which increases it’s value by it’s own whenever I run the test case. E.g. I want to enter the username to be entered as
Test 1
Test 2
Test 3
.
.
.
Test n, each time I run the test case. How do I define that under Global variable?
I use only Global Variable to pass my test data and do not use excel or csv. Please help.
import internal.GlobalVariable as GlobalVariable
// we assume GlobalVariable.SEQ is defined with initial value 0
println GlobalVariable.SEQ
GlobalVariable.SEQ += 1
println GlobalVariable.SEQ
GlobalVariable.SEQ += 1
println GlobalVariable.SEQ
Thank you for the reply. The above example works if the Value Type is number but I want to concatenate with String. When I set the Value Type to string, I am geting the following output.
<
2021-02-18 16:01:32.552 INFO c.k.katalon.core.main.TestCaseExecutor - START Test Cases/New Test Case
2021-02-18 16:01:33.594 DEBUG testcase.New Test Case - 1: println(username)
test
2021-02-18 16:01:33.817 DEBUG testcase.New Test Case - 2: username += 1
2021-02-18 16:01:33.827 DEBUG testcase.New Test Case - 3: println(username)
test1
2021-02-18 16:01:33.842 DEBUG testcase.New Test Case - 4: username += 1
2021-02-18 16:01:33.847 DEBUG testcase.New Test Case - 5: println(username)
test11
2021-02-18 16:01:33.852 INFO c.k.katalon.core.main.TestCaseExecutor - END Test Cases/New Test Case
Do you have some way of getting the last reference that you used? I can’t see any means of incrementing some reference unless you know what the last one was–was it 6 or 56. If you can get the last reference, then Split and Substring will allow you to add.
import internal.GlobalVariable as GlobalVariable
// we assume GlobalVariable.SEQ is like: Test 0056@Test.com
def temp = GlobalVariable.SEQ.toString().split("@")[0];
WebUI.comment("old reference is: " + temp)
"old GV value; get the last FOUR characters/numbers in the GV"
def ref = temp[-4..-1].toInteger();
ref++;
WebUI.comment("new test data is: " + ref.toString())
def newRef = "000" + ref.toString();
"make new GV value"
GlobalVariable.SEQ = "Test "+ newRef[-4..-1] + "@Test.com";
WebUI.comment("new reference is: " + GlobalVariable.SEQ)
Another way
import internal.GlobalVariable as GlobalVariable
// we assume GlobalVariable.SEQ is like: Test 56@Test.com
def temp = GlobalVariable.SEQ.toString().split("@")[0];
WebUI.comment("old reference is: " + temp)
"old GV value; get the numbers in the GV starting in the 5th position"
def ref = temp[5].toInteger();
ref++;
WebUI.comment("new test data is: " + ref.toString())
"make new GV value"
GlobalVariable.SEQ = "Test "+ ref.toString() + "@Test.com";
WebUI.comment("new reference is: " + GlobalVariable.SEQ)
Thank you. This one is working fine, but I want to update this GlobalVariable.SEQ in the execution profile during runtime. I have the GV set to “test0@test.com” and when I execute it I get “test1@test.com”. I want to update the GV with the value “test1@test.com”.
My suggestion would be to read the reference from a text file in the data folder rather than from the GV. Create a text file with “text0@test.com” at the top. Read the reference from the text file, manipulate the reference, write the new reference back out to the text file. Once you have read in the reference of the text file, equate it to your GV.
The alternative is to read and write the reference to Excel. That has been discussed many times on this forum. You need to persist the reference between runs and it does not look like GV are a means to do that.