Skip to main content
Transform your testing process with: Real Device Features, Company-wide Licences, & App Percy

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
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>"]
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.executeScript("mobile:installApp",ImmutableMap.of("appPath", "bs://9fg0rt302be241e6524ebc67253ecdee266343"));

HashMap<String, String> startActivityArgs = new HashMap<>();
startActivityArgs.put("intent", "com.browserstack.sample.MainActivity");
startActivityArgs.put("package", "com.browserstack.sample");

driver.executeScript("mobile:startActivity", startActivityArgs);
// Use app_url value passed in the "browserstack.midSessionInstallApps" capability
driver.execute("mobile: installApp", {appPath: "bs://9fg0rt302be241e6524ebc67253ecdee266343"});

driver.execute("mobile: startActivity", {intent: "com.browserstack.sample.MainActivity", package:"com.browserstack.sample"});
// Use app_url value passed in the "browserstack.midSessionInstallApps" capability
Dictionary<string, string> installAppArgs = new Dictionary<string, string>();
installAppArgs.Add("appPath", "bs://9fg0rt302be241e6524ebc67253ecdee266343");
((IJavaScriptExecutor)driver).ExecuteScript("mobile:installApp", installAppArgs);

Dictionary<string, string> startActivityArgs = new Dictionary<string, string>();
startActivityArgs.Add("intent", "com.browserstack.sample.MainActivity");
startActivityArgs.Add("package", "com.browserstack.sample");
((IJavaScriptExecutor)driver).ExecuteScript("mobile: startActivity", startActivityArgs);
// 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.execute_script("mobile: installApp", {"appPath": "bs://9fg0rt302be241e6524ebc67253ecdee266343"});

driver.execute_script("mobile: startActivity", {"intent": "com.browserstack.sample.MainActivity", "package":"com.browserstack.sample"});
# Use app_url value passed in the 'browserstack.midSessionInstallApps' capability
execute_script("mobile: installApp", { "appPath" => "bs://9fg0rt302be241e6524ebc67253ecdee266343"})

execute_script("mobile: startActivity", {"intent" => "com.browserstack.sample.MainActivity", "package" => "com.browserstack.sample"})

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();
        HashMap<String, Object> browserstackOptions = new HashMap<String, Object>();
        // Set your access credentials
        capabilities.setCapability("bstack:options", browserstackOptions);
        capabilities.setCapability("platformName", "android");
        capabilities.setCapability("platformVersion", "9.0");
        capabilities.setCapability("deviceName", "Google Pixel 3");

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

        AndroidDriver driver = new AndroidDriver(new URL("https://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.terminateApp(APP_PKG);
            driver.executeScript("mobile:terminateApp",ImmutableMap.of("appId", APP_PKG));

            // 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.executeScript("mobile:installApp",ImmutableMap.of("appPath", "bs://9fg0rt302be241e6524ebc67253ecdee266343"));

            // Launch the app using the package and launcher activity of the app
            HashMap<String, String> startActivityArgs = new HashMap<>();
            startActivityArgs.put("intent", APP_ACT);
            startActivityArgs.put("package", APP_PKG);

            driver.executeScript("mobile:startActivity", startActivityArgs);
            //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.

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://9fg0rt302be241e6524ebc67253ecdee266343");
        // 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("https://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.terminateApp(APP_PKG);

            // 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
           
            driver.activateApp(APP_PKG);

            //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. For JSONwire browserstack.midSessionInstallApps and W3C midSessionInstallApps capabilities can also be used to install any other app 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
Download Copy