Appium - 在第一次测试和最后一次测试时清除应用程序状态,但在测试之间不清除

Appium - Clean app state at the first test and last test, but not between tests

背景:
我想使用 appium 在 android 和 ios 模拟器中测试我的应用程序。我在 Python 中进行了 运行 测试,我希望拥有它,以便测试的工作流程始终如下:

if first test to be ran:
  reset any previous data
  launch simulator and application
  do test
  close application and save state
else:
  launch application
  do test
  close application and save state

if last test:
  reset any saved data

我认为正确的方法是包含 --no-reset 服务器标志,然后在测试之间使用 driver.launch_app()driver.close_app(),但我不确定如何重置上次测试时保存的所有数据。

感谢您的帮助。

假设您有一个创建 Appium Driver 实例的方法 start_driver

然后,传递下一个功能:fullResetfalse 值以及 noResettrue 值。这样 start_driver 方法将简单地重启应用程序而不重置任何东西。

重置应用程序:
1.卸载应用程序
- iOS: ideviceinstaller --udid #{udid} --uninstall #{package}
- Android:您可以清除应用数据 adb -s #{udid} shell pm clear #{package_name} 或卸载应用 adb -s #{udid} uninstall #{package}
2. 调用 start_driver

更新: 以上说明适用于真实设备。我没注意到你说的是模拟器。

这是我最终使用的有效方法:

要清理 iOS 模拟器:

xcrun simctl erase <udid here>

请注意,对于iOS模拟器,当模拟器未打开时,这必须是运行。

要清理 android 模拟器:

adb shell pm clear <app package here>

请注意,对于 android 模拟器,这必须是 运行,同时打开模拟器并关闭应用程序。