我将 appium 版本升级到 1.6.3 后遇到此问题。每当我使用
driver.launchApp();
命令时,它会清除应用程序数据,因此我无法执行下一个测试用例。
我也尝试设置以下所需功能,但每次我尝试启动应用程序时它仍然会清除应用程序数据。
capabilities.setCapability("noReset", "true");
所以情况是,我登录到应用程序,然后重新启动应用程序,appium 清除应用程序数据,然后再次出现不应出现的登录屏幕。
下面是日志,我们可以清楚地看到appium正在清除应用数据。
[debug] [ADB] Running 'C:\Users\Vinod\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","079a1ea4d037eeb7","shell","am","force-stop","PACKAGENAME"]
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Vinod\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","079a1ea4d037eeb7","shell","pm","clear","PACKAGENAME"]
[debug] [ADB] Device API level: 23
[debug] [ADB] Getting connected devices...
[debug] [ADB] 1 device(s) connected
[debug] [ADB] Running 'C:\Users\Vinod\AndroidSDK\platform-tools\adb.exe' with args: ["-P",5037,"-s","079a1ea4d037eeb7","shell","am","start","-W","-n","PACKAGENAME/.ui.SplashActivity","-S","-a","android.intent.action.MAIN","-c","android.intent.category.LAUNCHER","-f","0x10200000"]
您需要在功能中添加以下代码
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("noReset", "true");
cap.setCapability("fullReset", "false");
它对我有用。
确保设置了此功能: 尽管此功能的默认值是 false,但仍然值得一试。
capabilities.setCapability("fullReset", "false");
如果它不起作用,请提供您项目中的代码示例。
如果删除 driver.launchApp();声明那么它应该可以完美工作。
您不需要调用此方法,因为 appium 在启动具有功能的服务器时会为您执行此操作。
希望您能找到解决方案。如果没有你可以尝试这个。 Appium 版本 1.14.2
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.FULL_RESET, "False");
cap.setCapability(MobileCapabilityType.NO_RESET, "True");
由于所需的功能已被弃用,我认为这会有所帮助。
使用 .noReset() 和 .doesNoReset() 对我的情况有帮助,请在下面找到完整的代码片段。
var ltOptions = new HashMap<String, Object> ();
ltOptions.put("deviceName", "Redmi K20 Pro");
ltOptions.put("platformName", "Android");
ltOptions.put("platformVersion", "11");
ltOptions.put("udid", "aaa88c0");
var options1 = new UiAutomator2Options();
options1.setUdid("aaa88c0");
options1.noReset();
options1.doesNoReset();
options1.setClearSystemFiles(false);
URL url = new URL("http://localhost:4723/wd/hub");
AndroidDriver driver1 = new AndroidDriver(url, options1);