前言:
最近在搞 appium 自动化项目,遇到超过 60s 的应用场景时,总是报错报错。如何解决呢?见下文。
报错信息:
2018-05-21 14:03:42:253 - [HTTP] <-- POST /wd/hub/session/6b55742d-aa16-413c-aedd-ba69a89ced41/element/14/click 200 135 ms - 76
2018-05-21 14:03:42:253 - [HTTP]
2018-05-21 14:04:42:252 - [BaseDriver] Shutting down because we waited 60 seconds for a command
2018-05-21 14:04:42:253 - [debug] [AndroidDriver] Shutting down Android driver
2018-05-21 14:04:42:253 - [Appium] Closing session, cause was 'New Command Timeout of 60 seconds expired. Try customizing the timeout using the 'newCommandTimeout' desired capability'
2018-05-21 14:04:42:254 - [Appium] Removing session 6b55742d-aa16-413c-aedd-ba69a89ced41 from our master session list
2018-05-21 14:04:42:254 - [debug] [AndroidDriver] Resetting IME to io.appium.android.ime/.UnicodeIME
解决方案:
Appium 在没有收到下一个命令时,默认超时时间是 60s,超时后应用将会自动关闭 session,所以你接下来的所有操作都将失败。(Android 和 iOS 通用)
capabilities = {
'automationName': 'UIAutomator2',
#可以通过newcommandtimeout将超时时间改长,这样就解决了该问题!!
#超时时间可按照实际情况自定义!
'newCommandTimeout': "2000",
'unicodeKeyboard': True,
'resetKeyboard': True,
'noSign': True
}
host = "http://localhost:4723/wd/hub"
driver = webdriver.Remote(host, capabilities)
以上。