【问题标题】:I need to tap on the mobile keyboard from a generated number我需要从生成的号码中点击移动键盘
【发布时间】:2021-11-03 15:36:42
【问题描述】:

在 Katalon 上我做了这个自定义方法:

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;
        }
    }}

但我收到此错误: 引起:org.codehaus.groovy.runtime.InvokerInvocationException:groovy.lang.MissingMethodException:没有方法签名:java.lang.Integer.length() 适用于参数类型:() 值:[]

原因: com.kms.katalon.core.exception.StepErrorException:org.codehaus.groovy.runtime.InvokerInvocationException:groovy.lang.MissingMethodException:没有方法签名:java.lang.Integer.length()适用于参数类型:()值:[] 可能的解决方案:next()、each(groovy.lang.Closure)、getAt(java.lang.String)、with(groovy.lang.Closure)、signum(int)、wait()

请指教!

【问题讨论】:

  • 如果要电话号码的长度,建议你获取字符串a的长度。此外,如果有的话,将它转换为整数会去掉前导零。
  • 您能否编辑您的问题以包含“a”可能解析的内容/此方法获得的输入类型?

标签: java groovy katalon-studio katalon


【解决方案1】:

您收到此错误:

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

正如它所说的那样 - 整数没有 .length() 方法。

我将猜测您正在尝试做什么,这似乎是读取电话号码并按数字调用“Mobile.tap”方法。在这种情况下,我建议将数字视为字符串,以便您可以遍历每个字符:

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);
    }
}

【讨论】:

    【解决方案2】:

    已解决:

    @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;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 1970-01-01
      • 1970-01-01
      • 2018-09-29
      相关资源
      最近更新 更多