How to install .apk for the first test run only and then re-launch the same app again for rest of the tests?

Hi everyone,
I want to install apk every time I run my test suites even when it is already installed. The newer build should overwrite the already installed build. And for the rest of the tests, the app should not re-install and should keep the app data.
For example, If I am running the test suites, then for the first test, app should install freshly and handle the splash screen and do login stuff. And for the rest of the tests, the same app should re-launch and it should open the home screen only (login data should be saved).
I tried with the following capabilities:
capabilities.setCapability(MobileCapabilityType.NO_RESET, “true”);
capabilities.setCapability(MobileCapabilityType.FULL_RESET, “false”);

It’s meeting all my requirements. But its not installing fresh app everytime I run the test suites. If the app is already installed in the device, then it will simply re-launch it and then proceed from the home screen.
Kindly let me know what changes I need to make in the desired capabilities in order to meet this requirement.


Try the below code snippet.

				cap.setCapability(MobileCapabilityType.FULL_RESET, true);
			cap.setCapability(MobileCapabilityType.NO_RESET, false);

Hi @mehedihasan619 , thanks for responding. I just tried with this approach but the app is re-installing for each and every test executed. I want to have installation during first test run and then same build should not re-install again for further test cases during the suite run. Any idea, how we can achieve this?

I believe you are creating new driver instance for every test execution.

For your case, to achieve the goal, the idea would be to use same driver instance for the entire test suite.

I am using the same driver instance for all tests as I am not closing or quit the driver after each test.

Sorry for the delay.
I see your point.

  1. Add the following capabilities

     		cap.setCapability(MobileCapabilityType.FULL_RESET, false);
     		cap.setCapability(MobileCapabilityType.NO_RESET, false);
  2. In your @BeforeSuite add driver.installApp("appPath");

  3. Finally add driver.resetApp(); after each test to clear the app cache so that it launches with home screen. if you do not need to clear cache you can skip this.