在 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()
请指教 !