4

while using driver.launchApp(); my app is re-installed every time. So how can I prevent this ?

    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability(CapabilityType.BROWSER_NAME, "Android");
    capabilities.setCapability(CapabilityType.VERSION, Android_Version);
    capabilities.setCapability(CapabilityType.PLATFORM, "Android");
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("deviceName", DeviceName);
    capabilities.setCapability("app", app.getAbsolutePath());
    capabilities.setCapability("app-package", app_package);
    capabilities.setCapability("app-activity", app_activity);

    try{
        driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        APP_LOGS.info("Appium driver is initialized!!");
        driver.closeApp();
       }

IN My Test Cases

@Test
public void Test2()
{
   driver.launchApp();
    System.out.println("this is second test in appium suite");
    driver.closeApp();
}

1 Answer 1

5

There are one or more things you can do to stop installing the App again and again.


a. Setting appium --no-reset Flag to true :This Flag is used when we don't want to reset app state between sessions (IOS: don’t delete app plist files; Android: don’t uninstall app before new session). Its default Value is False,

You can start your appium server with "appium --no-reset" command or include server capability like:

capabilities.setCapability("noReset","true");

b. Make Sure --full-reset Flag is False: : (iOS) Delete the entire simulator folder. (Android) Reset app state by uninstalling app instead of clearing app data. On Android, this will also remove the app after the session is complete. Default false.

capabilities.setCapability("fullReset","false");

c. I think you need to remove launceApp() and closeApp() method from your test case instead of that you just write the test case code instde @Test Case method

d. Just make sure that your app is already installed on the device also the execution sequence by default of Unit test is like @Before @Test and @After So your SetUp method will run first than your test case and finally Teardown method. So Setup() will contain the server capabilities and Test Env. Specification and TearDown() will be used to close/quit the app,

You can Find Below My Code for the same:

@Before
public void setup(){
    DesiredCapabilities capabilities = new DesiredCapabilities();
            capabilities.setCapability("noReset","true");
            capabilities.setCapability("fullReset","false");
            capabilities.setCapability("automationName","Appium");
            capabilities.setCapability("platformName", "Android");
            capabilities.setCapability("VERSION", "5.1.1");
            capabilities.setCapability("deviceName", "LG Nexus 5");
            capabilities.setCapability("appPackage", "com.packageName");
            capabilities.setCapability("appActivity", "ui.activity.SplashScreenActivity");
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}

@Test
public void sampleTest(){
//Testing Code Only
}

//To Exit/Quit close the driver
    @After
    public void teardown() {
        if (driver != null)
            driver.quit();
    }

Hope you find this useful, Regards

7
  • Thanks for your suggestion and the reason behind using driver.launch() and driver.close() in every test case is "to get sure that driver object will be present in my each test case". After removing these if any of my test case become failed due to app crash then all further test cases of my suite become automatically fails. Is there any other approach to get ensure that all test cases of my suite become run then plz let me know. Sep 4, 2015 at 8:36
  • After using your code I got another exception A new session could not be created. (Original error: Permission to start activity denied.) (WARNING: The server did not provide any stacktrace information) Sep 4, 2015 at 8:45
  • In the android manifest, in the activity you wish to open, add android:exported="true" and it should work out just fine. Otherwise you need to start the default "ui.splash.SplashActivity" which always works. Also, be sure that in settings->DeveloperOptions the device is in debug mode and there is only one App with recent version is installed. Give me a feedback if this doesn't work please. Sep 4, 2015 at 8:54
  • Darshan I couldn't find manifest file in my project but SplashActivity worked. Another thing that I want to open app in its previous state >e.g: In my First Test case I logged in and reached to home screen. >In second test Case I want to perform some activity on home screen but as I use driver.launchApp() in second test case my app open in it's initial state(Login Screen). How can I maintain the state of app throughout my Appium Suite. Sep 4, 2015 at 10:13
  • If I'm not wrong, You might need to preserve the state of App, But I rather suggest not to do that, because by doing so your test cases might be depend on one another, which is not a good practice, If you want to use data generated by one test case in another than better be store it in variables and regenerate the state. Sep 4, 2015 at 10:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.