报错信息
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: UiAutomator2 Server cannot start because the local port #8200 is busy. Make sure the port you provide via ‘systemPort’ capability is not occupied. This situation might often be a result of an inaccurate sessions management, e.g. old automation sessions on the same device must always be closed before starting new ones.
Stacktrace:
UnknownError: An unknown server-side error occurred while processing the command. Original error: UiAutomator2 Server cannot start because the local port #8200 is busy. Make sure the port you provide via ‘systemPort’ capability is not occupied. This situation might often be a result of an inaccurate sessions management, e.g. old automation sessions on the same device must always be closed before starting new ones.
at getResponseForW3CError (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:804:9)
at asyncHandler (C:\Users\Administrator\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:380:37)
翻译
引发exception_类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions。WebDriverException:消息:处理命令时发生未知服务器端错误。原始错误:UiAutomator2服务器无法启动,因为本地端口#8200正忙。确保通过“systemPort”功能提供的端口未被占用。这种情况通常可能是由于会话管理不准确造成的,例如,在启动新的自动化会话之前,必须始终关闭同一设备上的旧自动化会话。
堆栈跟踪:
未知错误:处理命令时发生未知服务器端错误。原始错误:UiAutomator2服务器无法启动,因为本地端口#8200正忙。确保通过“systemPort”功能提供的端口未被占用。这种情况通常可能是由于会话管理不准确造成的,例如,在启动新的自动化会话之前,必须始终关闭同一设备上的旧自动化会话。
在getResponseForW3CError(C:\Users\Administrator\AppData\Roaming\npm\node\u modules\appium\node\u modules\appium base driver\lib\protocol\errors.js:804:9)
在asyncHandler(C:\Users\Administrator\AppData\Roaming\npm\node\u modules\appium\node\u modules\appium base driver\lib\protocol\protocol.js:380:37)
白话:
1.上次执行时出现了某个异常,报错,未正常关闭移动端8200端口的服务
解决方法:
driver初始化出现异常,重新初始化,初始化成功后跳出
while True:
try:
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
print("driver初始化成功……")
break
except Exception as e:
#Logger.info('driver初始化失败,重新初始化!!!(%s)' % e)
print('driver初始化失败,重新初始化!!!' )
#print('driver初始化失败,重新初始化!!!(%s)' % e)
2.是没有出现报错,正常执行完成后,未执行 driver.quit(),服务未结束,第二次运行时出现,上述报错 (port #8200 is busy)
解决方法:
执行完成后最后一行添加代码driver.quit()