使用WinAppDriverd搭配appnium框架进行自动化测试,编写的脚本在使用的过程中遇到一个问题:脚本在本地使用没问题(偶尔也会报错,不稳定),但是放到服务器上就会执行报错:
[2024-03-07 20:04:39] ok 连接客户端成功
[2024-03-07 20:04:39] step 获取版本
[2024-03-07 20:04:39] ok 版本号获取成功:杭州[4.5.5.0 UAT]
[2024-03-07 20:04:39] step 登录
[2024-03-07 20:04:42] error Traceback (most recent call last):
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\MesClientTest\testProcess.py", line 23, in runTestProcess
callback()
File "D:\AutoTestAgent\script\1765708594818351105.py", line 16, in testProcess
mesClient.login('chenl', '1234')
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\MesClientTest\mesClient.py", line 122, in login
self.inputByAutomationId('txtUsername', username)
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\MesClientTest\mesClient.py", line 199, in inputByAutomationId
input.send_keys(text)
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\appium\webdriver\webelement.py", line 223, in send_keys
self._execute(RemoteCommand.SEND_KEYS_TO_ELEMENT,
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response
raise wde
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
super().check_response(response)
File "C:\Users\mesuser\AppData\Local\Programs\Python\Python311\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown error occurred in the remote end while processing the command.
appnium+winappdriver执行报错
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
关注 引自免费微信小程序:皆我百晓生
从您提供的错误信息来看,当在服务器上执行appium+winappdriver自动化测试脚本时遇到了
WebDriverException
异常。该异常通常表示在与远程WebDriver通信时出现了未知错误。针对此类问题,我们可以尝试以下几种解决方案:
-
环境一致性检查: 确保服务器上的运行环境(包括但不限于操作系统版本、Python版本、Appium版本、WinAppDriver版本以及应用程序版本)与本地开发环境保持一致。不一致的环境配置可能导致兼容性问题。
-
网络与权限问题: 检查服务器是否能够正常访问并操作目标应用程序。如果应用程序需要特定网络环境或权限才能运行,确保服务器具有相应的访问权限和环境配置。
-
日志级别与详细信息: 虽然您给出的日志中没有包含具体的错误原因,但可以尝试提高Appium和WinAppDriver的日志级别以获取更详细的错误堆栈信息,以便定位问题所在。在启动Appium Server时,可以添加
--log-level debug
参数增加调试信息。 -
服务稳定性: 由于您提到本地偶尔也会报错,可能是WinAppDriver服务不稳定或者有资源竞争导致的问题。确保WinAppDriver服务始终处于稳定运行状态,并且在每次测试前重启服务或重新建立连接。
-
同步UI状态: 在调用
send_keys
方法输入文本时,可能由于UI元素还未完全加载或可交互而导致错误。可以在执行此操作之前加入等待条件,如使用ExpectedConditions
类中的element_to_be_clickable
方法确认元素已准备好接受输入。 -
代码示例: 添加适当的等待时间以确保元素存在和可交互:
from appium.webdriver.common.mobileby import MobileBy from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC # 假设username_field是用户名输入框的定位器 username_field = (MobileBy.AutomationId, 'txtUsername') wait = WebDriverWait(self.driver, 10) input_element = wait.until(EC.element_to_be_clickable(username_field)) input_element.send_keys('chenl')
-
检查更新与修复: 查看是否有相关的Appium、WinAppDriver或Selenium库的更新,有时候bug修复可能会解决遇到的问题。
-
防火墙设置: 确认服务器的防火墙规则不会阻止Appium与WinAppDriver之间的通信。
通过以上步骤逐个排查,应该能找出问题的原因并进行解决。若仍然无法解决问题,请提供更多详细的错误日志和系统环境信息。
解决 无用评论 打赏 举报 编辑记录-
悬赏问题
- ¥15 CVRP 图论 物流运输优化
- ¥15 Tableau online 嵌入ppt失败
- ¥100 支付宝网页转账系统不识别账号
- ¥15 基于单片机的靶位控制系统
- ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
- ¥15 下图接收小电路,谁知道原理
- ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
- ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
- ¥15 手机接入宽带网线,如何释放宽带全部速度
- ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测