appium / appium-flutter-driver

Appium Flutter Driver is a test automation tool for Flutter apps on multiple platforms/OSes. Appium Flutter Driver is part of the Appium mobile test automation tool maintained by community
MIT License
454 stars 182 forks source link

driver.execute('flutter:enterText', {'text':'111111'}) run except #713

Closed LVHAI closed 2 months ago

LVHAI commented 3 months ago

Appium : 2.11.1 Appium-Flutter-Finder ~= 0.7.0 Appium-Python-Client ~= 4.0.0 selenium : 4.22.0

When i run driver,i meet some wrong.

options.automation_name = 'flutter'

options.automation_name = 'UiAutomator2'

options.platform_name = 'Android' options.set_capability('deviceName', 'ALP AL00') options.set_capability('noReset', True) # 是否清空缓存 options.set_capability('fullReset', False) # 是否全部清楚 options.set_capability('resetKeyboard',True) # 隐藏键盘 options.set_capability('unicodeKeyboard',True) # driver = Remote('http://localhost:4723', options=options) driver.switch_to.context('NATIVE_APP')

elements = driver.find_elements(by=AppiumBy.CLASSNAME,value='android.widget.EditText') print(elements) for ele in elements: ele.clear() ele.click() driver.implicitly_wait(1) driver.execute('flutter:enterText', {'text':'111111'})

--------------Traceback---------------------- Traceback (most recent call last): File "/Users/xxx/work/yfph_loan/./test_driver/app_test.py", line 227, in driver.execute('flutter:enterText', {'text':'111111'}) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 352, in execute response = self.command_executor.execute(driver_command, params) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/remote_connection.py", line 290, in execute command_info = self._commands[command] KeyError: 'flutter:enterText' driver

LVHAI commented 3 months ago

I try to use send_keys ,also went wrong.

elements = driver.find_elements(by=AppiumBy.CLASSNAME,value='android.widget.EditText') print(elements) for ele in elements: ele.click() print(ele.text) driver.implicitlywait(1) ele.clear() ele_.send_keys('111111')

Traceback (most recent call last): File "/Users/xxx/work/yfph_loan/./test_driver/apptest.py", line 227, in ele.send_keys('111111') File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/appium/webdriver/webelement.py", line 186, in send_keys self._execute(RemoteCommand.SEND_KEYS_TO_ELEMENT, {'text': ''.join(keys), 'value': keys}) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webelement.py", line 395, in _execute return self._parent.execute(command, params) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute self.error_handler.check_response(response) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/appium/webdriver/errorhandler.py", line 125, in check_response raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace)) selenium.common.exceptions.InvalidElementStateException: Message: Cannot set the element to '111111'. Did you interact with the correct element? Stacktrace: io.appium.uiautomator2.common.exceptions.InvalidElementStateException: Cannot set the element to '111111'. Did you interact with the correct element? at io.appium.uiautomator2.handler.SendKeysToElement.setText(SendKeysToElement.java:87) at io.appium.uiautomator2.handler.SendKeysToElement.safeHandle(SendKeysToElement.java:115) at io.appium.uiautomator2.handler.request.SafeRequestHandler.handle(SafeRequestHandler.java:59) at io.appium.uiautomator2.server.AppiumServlet.handleRequest(AppiumServlet.java:259) at io.appium.uiautomator2.server.AppiumServlet.handleHttpRequest(AppiumServlet.java:253) at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:77) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435) at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267) at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438) at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) at java.lang.Thread.run(Thread.java:929)

KazuCocoa commented 2 months ago

The below WebDriver example is by webdriverio. flutter: prefix commands are mobile: command in appium for Android and iOS. Please replace them properly with your client.

https://github.com/appium/appium-flutter-driver?tab=readme-ov-file#commands

It looks like your client is Python, then the command should be driver.execute_script instead of driver.execute with webdriverio.

LVHAI commented 2 months ago

@KazuCocoa TKS your replay。 I use "mobile:enterText", but i get another wrong.

Traceback (most recent call last): File "/Users/xxx/work/yfph_loan/./test_driver/app_test.py", line 264, in driver.execute_script('mobile:enterText', {'text':'1111'}) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 414, in execute_script return self.execute(command, {"script": script, "args": converted_args})["value"] File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 354, in execute self.error_handler.check_response(response) File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/appium/webdriver/errorhandler.py", line 125, in check_response raise exception_class(msg=message, stacktrace=format_stacktrace(stacktrace)) selenium.common.exceptions.UnknownMethodException: Message: Unknown mobile command "enterText". Only shell,execEmuConsoleCommand,startLogsBroadcast,stopLogsBroadcast,changePermissions,getPermissions,performEditorAction,getDeviceTime,startScreenStreaming,stopScreenStreaming,getNotifications,listSms,pushFile,pullFile,pullFolder,deleteFile,isAppInstalled,queryAppState,activateApp,removeApp,terminateApp,installApp,clearApp,startService,stopService,startActivity,broadcast,getContexts,lock,unlock,isLocked,refreshGpsCache,startMediaProjectionRecording,isMediaProjectionRecordingRunning,stopMediaProjectionRecording,getConnectivity,setConnectivity,hideKeyboard,isKeyboardShown,deviceidle,bluetooth,nfc,setUiMode,getUiMode,injectEmulatorCameraImage,sendTrimMemory,getPerformanceData,getPerformanceDataTypes,toggleGps,isGpsEnabled,getDisplayDensity,getSystemBars,statusBar,fingerprint,sendSms,gsmCall,gsmSignal,gsmVoice,powerAc,powerCapacity,networkSpeed,sensorSet,getCurrentActivity,getCurrentPackage,dragGesture,flingGesture,doubleClickGesture,clickGesture,longClickGesture,pinchCloseGesture,pinchOpenGesture,swipeGesture,scrollGesture,scrollBackTo,scroll,viewportScreenshot,viewportRect,deepLink,acceptAlert,dismissAlert,batteryInfo,deviceInfo,openNotifications,type,replaceElementValue,getAppStrings,installMultipleApks,backgroundApp,pressKey,screenshots,scheduleAction,getActionHistory,unscheduleAction,setClipboard,getClipboard commands are supported.

KazuCocoa commented 2 months ago

It should be flutter: prefix as the command description.

LVHAI commented 2 months ago

@KazuCocoa tks,it works。

phone_finder = finder.by_value_key('phone_input') phone_ele = FlutterElement(driver,phone_finder) phone_ele.click() driver.execute_script('flutter:enterText','111111')

phone_finder = finder.by_value_key('phone_input1') phone_ele = FlutterElement(driver,phone_finder) phone_ele.click() driver.execute_script('flutter:enterText','222222')