Closing and launching app in a single session

Hi Guys,

I’ve a scenario where user close app and re-launch it

is it possible in single IOS session to do this

@jagadeeshkotha

You can first close the app using closeApp() and then launchApp().

These methods use the cabaility provided at the time instantiation

@raghuappium, did it work for you?
I tried these commands on iOS and I have the following problems:

  1. closeApp uninstalls the app from iOS real device
  2. closeApp logs me out of my application on simulator…

I am using appium 1.3.4
Have any idea?
Thanks!

@ShiranDadon

On ios7+ if you close the app I dont think you will be able to access it again with the same appium session (you can in android)

I tried it before with restart, close_app, launch and reset and playing with the capabilities of server such as --no-reset, etc.

If anyone can do it, let me know :slight_smile:

CloseApp works on iOS 8, the app launches back in it’s initial state (no memory of the last page opened in the previous test)

Hi @Ag

unfortunately I made the mistake of upgrading to ios8 :slight_smile: And yes, the problem in this ticket does not occurs with ios8.1.3

  1. Click to IOS icon on Appium
  2. Tick to No Reset
    –> Try again

Dear Team ,

Can someone explain me the difference between close and CloseApp() in appium ?

Reason I’m eager to know because - in my attempt to use below line of code

driver.close()
driver.launchApp()

encountered an error message stating "WebDriverException: Not implemented in this context, try switching into or out of a web view”

Here I am confused, where am I trying to switch into web view ?

System Information:-

Xcode: 7.2
Appium 1.4.13
Java : 8
iOS: 9.2

Scenario:-

Crash app manually and then relaunch it in same session

Error Logs:-

I noticed error to be

Exception in thread “main” org.openqa.selenium.WebDriverException: Not implemented in this context, try switching into or out of a web view (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 8 milliseconds
Build info: version: ‘2.48.2’, revision: ‘41bccdd’, time: ‘2015-10-09 19:55:52’
System info: host: ‘VIJAYs-MacBook-Pro.local’, ip: ‘100.113.161.132’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.10.5’, java.version: ‘1.8.0_60’
Driver info: io.appium.java_client.ios.IOSDriver
Capabilities [{networkConnectionEnabled=false, noReset=true, warnings={}, databaseEnabled=false, deviceName=iPad 2, version=9.2, fullReset=true, platform=MAC, AppName=DataGrinchApp, desired={noReset=true, platformName=iOS, deviceName=iPad 2, version=9.2, fullReset=true, AppName=DataGrinchApp}, webStorageEnabled=false, locationContextEnabled=false, browserName=iOS, takesScreenshot=true, javascriptEnabled=true, platformName=iOS}]
Session ID: 392177c4-f6b8-493a-be89-cfb6c9bf0440
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:647)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:206)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:511)
at ios.resusefunctions.stop(resusefunctions.java:65)
at ios.crash.logContinousCrashOnline(crash.java:23)
at ios.mainclass.main(mainclass.java:46)

Solution that I implemented.

replaced driver.close() with driver.closeApp() method.

Is there any way to do the following process in android Automation using Appium with android driver? Put app in background, the app launches back not in initial state but with the last page opened .
driver.launchapp(); making the app to launch from the Home screen . But I want to launch it from the same screen from where I have gone into background. Please help if anybody knows

closeApp() no longer exists, and close() fails with:

org.openqa.selenium.WebDriverException: Method is not implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 165 milliseconds
Build info: version: ‘3.0.1’, revision: ‘1969d75’, time: ‘2016-10-18 09:48:19 -0700’
System info: host: ‘C02ST0PZH03Y’, ip: ‘172.31.135.190’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.2’, java.version: ‘1.8.0_111’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{app=/Users/jeffrey.blaze/Desktop/Build/Products/Debug-iphonesimulator/VungleTestApp.app, networkConnectionEnabled=false, noReset=true, databaseEnabled=false, deviceName=iPhone 7, platform=MAC, newCommandTimeout=900, platformVersion=10.2, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=iOS}]
Session ID: efb27c1b-0691-42df-901c-96e85bd2f655
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:487)
at test.TestCallbacks.testPlayAnAdSuccessfully(TestCallbacks.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

org.openqa.selenium.WebDriverException: Method is not implemented (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7 milliseconds
Build info: version: ‘3.0.1’, revision: ‘1969d75’, time: ‘2016-10-18 09:48:19 -0700’
System info: host: ‘C02ST0PZH03Y’, ip: ‘172.31.135.190’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.12.2’, java.version: ‘1.8.0_111’
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities [{app=/Users/jeffrey.blaze/Desktop/Build/Products/Debug-iphonesimulator/VungleTestApp.app, networkConnectionEnabled=false, noReset=true, databaseEnabled=false, deviceName=iPhone 7, platform=MAC, newCommandTimeout=900, platformVersion=10.2, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=iOS}]
Session ID: efb27c1b-0691-42df-901c-96e85bd2f655
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:658)
at org.openqa.selenium.remote.RemoteWebDriver.close(RemoteWebDriver.java:487)
at test.TestCallbacks.tearDown(TestCallbacks.java:42)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

both closeApp() and resetApp() method closes the simulator as well.

In case I just want to close the app but continue using the simulator, what needs to be done ?

Thanks & Regards,
Vikram

http://appium.github.io/java-client/io/appium/java_client/InteractsWithApps.html#launchApp--

[SOLVED]

capabilities.setCapability(“noReset”, true)

use above to achieve the desired effect.

1 Like

it fixed - https://github.com/appium/appium/issues/7729 - will come in next version. in the mean time you can close Simulator and re-open with “driver.launchApp()”

2 Likes

You can use this code; it has worked for me with both Android and iOS apps. However, the session is not closed because the app keeps close and launching.

Example:
driver.terminateApp(“Bundle_ID(Android or iOS)”);
driver.activateApp(“Bundle_ID(Android or iOS)”);

I’m unable to do it for my android app, believe bundle id is for iOS, could you please tell me how to do it for android device. Also the activateApp() method is not available for me. So could you please share me the jar files you had used for this operation