Appium iOS: Uninstall app and delete session - ios

Background:
I want to remove the user logging session after the tests so that whenever I kick off tests again it starts from Login Functionality. But as of now after teardown() functions i.e. after quitting the session (the appium driver) the user remains logged in.
I have tried reset options/caps mentioned on this page.
http://appium.io/docs/en/writing-running-appium/other/reset-strategies/
but no luck except fullReset but it takes a lot of time because it also shuts down the simulator completely.
Question: How can I delete/remove the login session from the iOS app without having a simulator restarted?
I am using
Appium version 1.16.0
Capabilities properties
appium.platformName=IOS
appium.platformVersion=9
appium.deviceName=iPhone 6s plus
appium.app=/Users/CR9972/Desktop/iOSDemo/demo.app

To solve this issue, you can create the app session from the scratch using the #BeforeMethod and then unistall/remove the app using the #AfterMethod. This way, you would be having a complete new session every time your test case would start executing.
To remove the app in the #AfterMethod, you can use:
driver.resetApp("bundle id of the app");
And if the above command doesn't work then you can use:
driver.removeApp("bundle id of the app");

Related

How can my iOS app know Appium is running it?

One of the benefits of Appium is that I can run tests against the app without compiling in any instrumentation. But, there's a feature I want to turn off in my app when Appium is the user.
How can Appium can send information directly to the app, to tell it that Appium is driving? This needs to happen shortly after launch, so hiding a secret switch somewhere is not a good option.
You can use the processArguments capability to pass application launch arguments through Appium to your application. Inside your application you can read the launch arguments and values using NSUserDefaults.

Removing App from background using Appium

is there any way to remove app from background using Appium in Windows.
What i want is
- Start server with -No reset
-Run the program
-Program ends
-driver quits using driver.quit() method
Now when i start my test execution again , the app on which i was earlier working is there in the memory.So i have to press "Home" key and remove it from memory and then start working on it. (e.g. if i am working on messaging app of device , after test execution i press "Home" hardkey and manually remove the app as follows)
Please help me how to do this
You have to use driver.closeApp() before driver.quit().
Please see this link with the different appium methods provide app control.

How to test Background App Launch in case of NSURLSession(Background Session) event?

How can one test the scenario of Application Launch in background for handling Background NSURLSession's event?
Flow:
Application starts a upload/download task using Background URL
session.
User hits home button. App is in suspended or in background
state.
OS decides to Exit the application. I know, one can exit the app by double-tapping home button and swipe-up the particular app. But in that case OS will never re-launch the app in background for event handling.
Upload/download task needs some event handling. OS re-lauches App in background.
So the question is how do I make OS exit the app like it may normally do after some-time. The purpose is to test the code for this scenario. I tried using UIApplicationExitsOnSuspend but it does not work since then App can not be launched in Background.
It's not a perfect solution, but I was able to manually test the launch of an app due to a Background URLSession on a physical device as follows:
Connect device for debugging via USB
Disable Internet connectivity on device (i.e. disable WiFi/Cellular)
Start the app via Xcode
Issue a request using background URLSession. The request shouldn't fail, it will just be waiting around for an Internet connection until it times out, so use a reasonably long timeout to make testing easier.
Kill the app via Xcode (press stop button)
View the device logs via Windows > Devices and Simulators
Enable Internet connectivity on the device again without starting the app
The requests from the background URLSession should then complete and in the device logs (from step 6.) you should see any NSLog statements issued as a result of the app being launched via the application(_:handleEventsForBackgroundURLSession:completionHandler:) app delegate method.
They key point is that killing the app via Xcode, as opposed to killing it using device itself, does not prevent the app from being relaunched for background event handling.
A possible alternative to killing the app manually via Xcode might be to intentionally crash the app in code - this might be more suitable for automated testing.
You could write an app that has a button that allocates and intentionally leaks chunks of memory. If you get this thing to allocate enough RAM, the OS will start killing other apps to get their RAM back.
Hopefully this would exhibit the behavior you need.

How to close an iOS app on a real device using appium

I'm using appium to automate some tests but I want the application under test to return to the same start in between tests. I think that the easiest way to do this would be to close and reopen the app. Is this possible with appium? If so, how?
(Note: driver.close() does not work)
You can do this with driver.quit(). You will need to reconnect but as long as the server is launched with the --no-reset switch it should boot up in the state where you left it.
You could also background the app as an alternative using executeScript with "mobile: background" (see https://github.com/mutualmobile/appium/commit/53f0c58857eec512f48732d40ace71b7db4ae32f) or calling the UIAutomation command directly with executeScript. (e.g. au.background(5)) for 5 seconds in the background.

Forcing BlackBerry to do a hard restart after app installation

I've been experiencing unexplained connection issues with my BB app. This only happens on a Curve 8520, and only on some of them. There is no noticeable pattern so i cant determine what causes it. The app prompts me to check my internet connection even though all other apps / browsers are working fine.
The only solution is to do a manual hard restart after installation. This solved the problem and the app runs seamlessly 100% of the time.
Is there a way to prompt the user to restart the phone after initial installation has been completed? Ex. Like some RIM products, after you've installed it prompts you to restart now or later, if you select yes it does a complete / hard restart.
AFAIK when a BlackBerry application is set "Run on startup" it runs automatically as it is installed.
And you may use requestPowerOff method of Device class to turn the device off and automatically turn it on (this is controlled by the method parameter).

Resources