简体   繁体   中英

Testing of Android Application without resetting its state using Appium and Selenium WebDriver

I wish to test my android application without resetting its state. I noticed that different popups appear everytime I run the application so I wish to log all the various popups.

My definition of "run" here is tapping the back button on my phone and tapping my application icon again.

However, I am unable to simulate this physical tapping of the phone on my Appium test. I can exit my first test but I am unable to reopen my application again. (Simulation of tapping on the application icon with my finger)

Things I have tried:

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)

Is there anyway I can simulate the physical tapping of the icon in the form of code? I know we can set the coordinates but I don't want to hard code my test to run only on a specific instance of the phone. It will not run if other applications are uninstalled and my application icon shifts to another position.

This worked for me:

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

This won't reinstall the .apk, appium server and it won't delete the appdata. You can just start the app like you've left it before starting the test.

I found this browsing the same issues on GitHub:

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

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

If I am not getting you wrong here, you can try using a combination of following using AndroidDriver :

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM