Test App Upgrades

Testing app upgrades is an important scenario since new versions of your apps are shipped to customers on a frequent basis. Users upgrade to the latest version of your app and not install it from scratch. In such cases, there might be existing user data that needs to be migrated for the app to work correctly. As a result, testing of app-upgrade is very important to ensure that the app works as expected even after the upgrade.

Before starting test execution, you first need to upload the app to be upgraded (newer version) using REST API similar to your app under test. The REST API response will return an app_url for each successful app upload. Use this app_url value (returned on uploading the app) to set the browserstack.midSessionInstallApps capability in your Appium test script.

Capability Description Values
browserstack.midSessionInstallApps Set this capability if you want to install app(s) in between a test session. Upload your apps to BrowserStack servers using REST API. Use the app_url value returned as a result of the upload request to set this capability. The app_url returned on successful upload.
Example: ["bs://<hashed app-id>", "bs://<hashed app-id>"]


You can now make use of Appium’s install app command. It will allow you to install and launch the upgraded version of your app in between your Appium test session and continue with your test flow with this newer version of the app.

The detailed steps to achieve this are:

  1. Upload the app version say v1.0 and set the app_url value (returned on uploading the app) in app capability. This will be the application under test(AUT) for your Appium test.
  2. Now, upload the upgrade version of app (say v1.1). You need to set the app_url value (returned on uploading the app) in browserstack.midSessionInstallApps capability in your test script prior to running the test as mentioned above.
  3. Start your Appium test execution.
  4. In the middle of the test you can install and upgrade the app version using Appium’s install app command. You can launch the installed app using the Start Activity command.
// Use app_url value passed in the "browserstack.midSessionInstallApps" capability
driver.installApp("bs://9fg0rt302be241e6524ebc67253ecdee266343");

driver.startActivity(new Activity("com.browserstack.sample", "com.browserstack.sample.MainActivity"));
// Use app_url value passed in the "browserstack.midSessionInstallApps" capability
driver.installApp('bs://9fg0rt302be241e6524ebc67253ecdee266343');

driver.startActivity('com.browserstack.sample', 'com.browserstack.sample.MainActivity'));
// Use app_url value passed in the "browserstack.midSessionInstallApps" capability
driver.InstallApp("bs://9fg0rt302be241e6524ebc67253ecdee266343");

driver.StartActivity(new Activity("com.browserstack.sample", "com.browserstack.sample.MainActivity"));
// Use app_url value passed in the 'browserstack.midSessionInstallApps' capability
$driver->installApp('bs://9fg0rt302be241e6524ebc67253ecdee266343');

$driver->startActivity(array('appPackage' => 'com.browserstack.sample',
                             'appActivity' => 'com.browserstack.sample.MainActivity'));
# Use app_url value passed in the 'browserstack.midSessionInstallApps' capability
driver.install_app('bs://9fg0rt302be241e6524ebc67253ecdee266343')

driver.start_activity('com.browserstack.sample', 'com.browserstack.sample.MainActivity')
# Use app_url value passed in the 'browserstack.midSessionInstallApps' capability
driver.install_app('bs://9fg0rt302be241e6524ebc67253ecdee266343')

driver.start_activity app_package: "com.browserstack.sample", app_activity: "com.browserstack.sample.MainActivity"

Sample code snippet

Here is a complete sample Java code which shows that an Appium test was started with app version v1.0. In the middle of the test an upgrade version of the app v1.1 was installed with app_url value as bs://9fg0rt302be241e6524ebc67253ecdee266343.

package android;

import io.appium.java_client.MobileBy;
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import java.io.IOException;
import java.net.URL;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;


public class AppUpgradeBS {
    
    private String APP_PKG = "com.browserstack.sample";
    private String APP_ACT = "com.browserstack.sample.MainActivity";
    
    @Test
    public void testAppUpgrade () throws IOException {

        DesiredCapabilities capabilities = new DesiredCapabilities();
        // Set your access credentials
        capabilities.setCapability("browserstack.user", "YOUR_USERNAME");
        capabilities.setCapability("browserstack.key", "YOUR_ACCESS_KEY");
        capabilities.setCapability("device", "Samsung Galaxy S8");
        capabilities.setCapability("os_version", "7.0");
        capabilities.setCapability("name", "Test_app_upgrade");

        // Set app_url of the application under test(AUT) which is version v1.0 of app
        capabilities.setCapability("app", "bs://86c51rt30e34d1652cdee2663524ebc69t5s41");
        // Set app_url obtained after uploading the upgrade version v1.1 of app
        capabilities.setCapability("browserstack.midSessionInstallApps", new String[]{"bs://9fg0rt302be241e6524ebc67253ecdee266343"});

        AndroidDriver driver = new AndroidDriver(new URL("http://hub.browserstack.com/wd/hub"), capabilities);
        WebDriverWait wait = new WebDriverWait(driver, 10);

        try {

            //Your test goes with v1.0 goes here

            // Close the app under test
            driver.closeApp();

            // Install the upgrade version of the app 
            // Specify the app_url of the upgrade version(v1.1) of the app that was passed in "browserstack.midSessionInstallApps" capability
            driver.installApp("bs://9fg0rt302be241e6524ebc67253ecdee266343");
            
            // Launch the app using the package and launcher activity of the app
            Activity activity = new Activity(APP_PKG, APP_ACT);
            driver.startActivity(activity);

            //Your test with upgrade version v1.1 goes


        } finally {
            driver.quit();
        }
    }
}

In case of Android, you can also pass publicly accessible URL as a value in the driver.installApp command. The public URL should have a downloadable Android app (.apk/.aab) file.

Note:
  1. To test app upgrades, you need to ensure that upgrade version app should have same signatures and bundle id as the application under test.
  2. browserstack.midSessionInstallApps capability can also be used to install any other apps in between the test session.

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback

Is this page helping you?

Yes
No

We're sorry to hear that. Please share your feedback so we can do better







Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked






Thank you for your valuable feedback!

Talk to an Expert
Talk to an Expert