How to use number variable in test case


#1

Hello,
I need to use integer variable in test case. How should I call?

I declared local variable ‘acc_num’ with default value type ‘Number’ and default value as ‘10000’.

I used this for calling variable->
Mobile.setText(findTestObject(‘account_number’), acc_num, 0)

But this is displaying error->
Test Cases/JoinHaggle FAILED because (of) groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.setText() is applicable for argument types: (java.lang.String, java.lang.Integer, java.lang.Integer) values: [account_number, 10000, 1]
Possible solutions: setText(com.kms.katalon.core.testobject.TestObject, java.lang.String, int), setText(com.kms.katalon.core.testobject.TestObject, java.lang.String, int, com.kms.katalon.core.model.FailureHandling), getText(com.kms.katalon.core.testobject.TestObject, int), getText(com.kms.katalon.core.testobject.TestObject, int, com.kms.katalon.core.model.FailureHandling)

Test Cases/JoinHaggle.run:39


#2

setText takes expects a string as third parameter.
Try this:
Mobile.setText(findTestObject(‘account_number’), toString(acc_num), 0)


#3

I want integer. Then what do I need to use?


#4

Did you try it?

Mobile.setText(), as the name suggests, sets some text to your element (presumably some input field). Groovy’s toString() will convert your integer to string, but I think it will send ‘10000’ to your input field anyway. Try and see what happens.


#5

It is giving error.
Can you tell any other method to set numbers in text field (other than setText)?


#6

Try

[Mobile] Send Keys


#7

I will elaborate again what I need to do exactly.
I want to increment account number with each iteration of for loop.

Something like this->

int acc_no = 1000 // This is local variable
for (def i = 1; i < 10; i++) {
// set acc_no in text field account_number
// increment acc_no by 100 with each iteration of loop
}

How can I do this?


#8

Please use String.valueOf(<your_variable>)


#9

Thank you… It worked…


#10

duyluong said:

Please use String.valueOf(<your_variable>)

It works for me…