0

on Katalon I made this custom method :

def void enterPhoneNumber(a){
    a = Integer.valueOf(a)
    def ref = ""
    int max = a.length()
    for(int i=0; i< max; i++){
        ref = a.substring(i, i + 1)
        switch (ref) {
            case "0":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 0' , GlobalVariable.avgWait);
                break;
            case "1":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 1' , GlobalVariable.avgWait);
                break;
            case "2":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 2' , GlobalVariable.avgWait);
                break;
            case "3":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 4' , GlobalVariable.avgWait);
                break;
            case "4":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 3' , GlobalVariable.avgWait);
                break;
            case "5":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 5' , GlobalVariable.avgWait);
                break;
            case "6":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 6' , GlobalVariable.avgWait);
                break;
            case "7":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 7' , GlobalVariable.avgWait);
                break;
            case "8":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 8' , GlobalVariable.avgWait);
                break;
            case "9":
                Mobile.tap('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 9' , GlobalVariable.avgWait);
                break;
            default:
                break;
        }
    }}

but am getting this error : Caused by: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.length() is applicable for argument types: () values: []

Reason: com.kms.katalon.core.exception.StepErrorException: org.codehaus.groovy.runtime.InvokerInvocationException: groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.length() is applicable for argument types: () values: [] Possible solutions: next(), each(groovy.lang.Closure), getAt(java.lang.String), with(groovy.lang.Closure), signum(int), wait()

please advise !

  • 2
    If you want the length of the telephone number, I suggest you get the length of the string a. Also, converting it to integer like that will drop leading zero's if there are any. – ou_ryperd Nov 03 '21 at 16:15
  • Can you edit your question to include what "a" might resolve to/what sort of input this method is getting? – aspok Nov 03 '21 at 16:19

2 Answers2

0

You are getting this error:

groovy.lang.MissingMethodException: No signature of method: java.lang.Integer.length() is applicable

for exactly the reason it says - there is no .length() method for an Integer.

I'm going to take a guess at what you're attempting to do, which appears to be to read in a phone number and call the "Mobile.tap" method per digit. In that case, I would suggest treating the number as a String so that you can iterate over each character:

void enterPhoneNumber(number) {
    String numberAsStr = number as String
    numberAsStr.each { digit ->
        Mobile.tap("Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - $digit" , GlobalVariable.avgWait);
    }
}
aspok
  • 285
  • 3
  • 10
-1

solved by :

@Keyword
//tap on related button on numeric keyboard based on phone number passed
def void enterPhoneNumber(a){
    def ref = ""
    String max = a.length()-1
    int maxInt = Integer.valueOf(max)
    for(int i=0; i<= maxInt; i++){
        ref = a.substring(i, i+1 )
        switch (ref) {
            case "0":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 0') , 5);
                break;
            case "1":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 1') , 5);
                break;
            case "2":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 2') , 5);
                break;
            case "3":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 3') , 5);
                break;
            case "4":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 4') , 5);
                break;
            case "5":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 5') , 5);
                break;
            case "6":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 6') , 5);
                break;
            case "7":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 7') , 5);
                break;
            case "8":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 8') , 5);
                break;
            case "9":
                Mobile.tap(findTestObject('Object Repository/Onboarding/001-Startup page/001-Phone number fields/002-Numeric Keyboard/Button - 9') , 5);
                break;
            default:
                break;
        }
    }
}