使用Appium和Selenium WebDriver测试Android应用程序而不重置其状态

问题描述 投票:1回答:3

我想测试我的Android应用程序而不重置其状态。我注意到每次运行应用程序时都会出现不同的弹出窗口,所以我希望记录所有各种弹出窗口。

我在这里对“运行”的定义是点击手机上的后退按钮并再次点击我的应用程序图标。

但是,我无法在Appium测试中模拟手机的这种物理攻击。我可以退出我的第一个测试,但我无法重新打开我的应用程序。 (用我的手指模拟应用程序图标)

我尝试过的事情:

1. Setting noReset to true in capabilities setting

2. Using uiautomator to find my application.  However, uiautomator doesn't seem to be able to detect any icons in the app menu page. It just shows many layers of frame layouts.

3. closeApp() and launchApp() resets the application and this defeats the purpose of my test.  My application somehow behaves differently with each run so I hope to run my test in a single session (i.e. closing and opening the application while it is still in the same state)

无论如何我可以用代码的形式模拟图标的物理点击吗?我知道我们可以设置坐标,但我不想硬编码我的测试只能在手机的特定实例上运行。如果卸载了其他应用程序并且我的应用程序图标转移到另一个位置,它将无法运行。

java android selenium-webdriver appium
3个回答
2
投票

这对我有用:

"appPackage": "com.company.app",
"appActivity": "com.company.app.activities.HomeActivity",
"skipDeviceInitialization": true,
"skipServerInstallation": true,
"noReset": true

这将不会重新安装.apk,appium服务器,它不会删除appdata。您可以像开始测试之前离开它一样启动应用程序。

我发现这在GitHub上浏览相同的问题:

https://github.com/appium/appium/issues/4955

https://github.com/appium/appium/issues/3783


0
投票

如果我在这里没有弄错你,你可以尝试使用以下组合使用AndroidDriver

driver.navigate().back(); // from app home screen to mobile home screen
driver.startActivity(String appPackage, String appActivity); // or possibly cast ((AndroidDriver)driver)

0
投票

您可以通过提供包名称和启动活动名称而不是所需大写的apk文件来启动应用程序,这样每次启动应用程序时都不会重置您的应用程序Den使用presskey4来点击后退按钮,你可以调用启动app功能无需重置即可启动应用

© www.soinside.com 2019 - 2024. All rights reserved.