appium 2.0 + 版本使用了noReset 参数之后无法启动app或者不能关闭app的解决方案

appium 2.0 + noReset 参数于1.0+版本的表现差异

在启动参数设置这些时,可能会出现不会调起app,然后在teardown的时候加上了 driver.quit()也无法关闭app

        caps = {}
        # 设置 app 安装平台
        caps["appium:platformName"] = "Android"
        # 设置 app 安装平台的版本
        caps["appium:platformVersion"] = "6"
        # 设备的名字
        caps["appium:deviceName"] = "MuMu"
        # 设置driver
        caps["appium:automationName"] = "UiAutomator2"
        # 设置 app 的包名
        caps["appium:appPackage"] = "com.tencent.wework"
        # 设置 app 启动页
        caps["appium:appActivity"] = ".launch.LaunchSplashActivity"
        # 不清空缓存
        caps["appium:noReset"] = True

解决方案,在参数上再追加以下两个参数。

# 设置以下两个参数来控制启动app和关闭掉app
caps["appium:forceAppLaunch"] = True
caps["appium:shouldTerminateApp"] = True

参考

app does not launch if noResent is true · Issue #19460 · appium/appium · GitHub

常见问题

如果Appium Server 日志端如果出现以下报错:

[W3C] Matched W3C error code 'invalid session id' to NoSuchDriverError
[AndroidUiautomator2Driver@dcdc (141c8d0c)] Encountered internal error running command: io.appium.uiautomator2.common.exceptions.NoSuchDriverException: The session identified by 6ebcf3d6-a7a6-4ef2-81bc-91ee886f25a3 is not known

或者以下报错

Original error: Could not proxy command to the remote server

原因是因为io.appium.uiautomator2.server以及io.appium.uiautomator2.server.test这两个apk出现了问题。将apk手动卸载之后,重装即可

adb devices
adb uninstall io.appium.uiautomator2.server
adb uninstall io.appium.uiautomator2.server.test