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.
To test app upgrades, ensure that the upgraded app version has the same signatures and bundle ID as the application under test.
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 the 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>"]
|
Example:
midSessionInstallApps :
- 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:
- Upload the app version say
v1.0
and set the app_url value (returned on uploading the app) inapp
capability. This will be the application under test(AUT) for your Appium test. - Now, upload the upgrade version of app (say
v1.1
). You need to set the app_url value (returned on uploading the app) inbrowserstack.midSessionInstallApps
capability in your test script prior to running the test as mentioned above. - Start your Appium test execution.
- 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://<hashed app-id>"));
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://<hashed app-id>"});
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://<hashed app-id>');
$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://<hashed app-id>"});
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://<hashed app-id>"})
execute_script("mobile: startActivity", {"intent" => "com.browserstack.sample.MainActivity", "package" => "com.browserstack.sample"})
Sample Android code snippet
The following code samples explain an app-upgrade test using Appium. A test begins with the app version v1.0
but later gets updated to v1.1
by installing the latest version through the app_url.
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://<hashed app-id>");
// Set app_url obtained after uploading the upgrade version v1.1 of app
browserstackOptions.put("midSessionInstallApps", new String[]{"bs://<hashed app-id>"});
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://<hashed app-id>"));
// 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();
}
}
}
const { remote } = require('webdriverio');
async function testAppUpgrade() {
const capabilities = {
platformName: 'android',
platformVersion: '9.0',
deviceName: 'Google Pixel 3',
app: 'bs://<hashed app-id>',
'bstack:options': {
midSessionInstallApps: ['bs://<hashed app-id>']
}
};
const driver = await remote({
capabilities,
hostname: 'hub.browserstack.com',
port: 443,
path: '/wd/hub',
user: 'YOUR_BROWSERSTACK_USERNAME',
key: 'YOUR_BROWSERSTACK_ACCESS_KEY'
});
try {
// Your test with v1.0 goes here
// Close the app under test
await driver.terminateApp('com.browserstack.sample');
await driver.executeScript('mobile:terminateApp', { appId: 'com.browserstack.sample' });
// Install the upgrade version of the app
await driver.executeScript('mobile:installApp', { appPath: 'bs://<hashed app-id>' });
// Launch the app using the package and launcher activity of the app
await driver.executeScript('mobile:startActivity', { intent: 'com.browserstack.sample.MainActivity', package: 'com.browserstack.sample' });
// Your test with upgrade version v1.1 goes here
} finally {
await driver.deleteSession();
}
}
testAppUpgrade();
using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Enums;
using OpenQA.Selenium.Appium.Service;
using OpenQA.Selenium.Remote;
class Program
{
static void Main(string[] args)
{
TestAppUpgrade();
}
static void TestAppUpgrade()
{
var capabilities = new AppiumOptions();
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformName, "Android");
capabilities.AddAdditionalCapability(MobileCapabilityType.PlatformVersion, "9.0");
capabilities.AddAdditionalCapability(MobileCapabilityType.DeviceName, "Google Pixel 3");
capabilities.AddAdditionalCapability(MobileCapabilityType.App, "bs://<hashed app-id>");
capabilities.AddAdditionalCapability("bstack:options", new Dictionary<string, object>
{
{ "midSessionInstallApps", new string[] { "bs://<hashed app-id>" } }
});
var serviceUri = new Uri("https://hub.browserstack.com/wd/hub");
var driver = new AndroidDriver<AppiumWebElement>(serviceUri, capabilities);
try
{
// Your test with v1.0 goes here
// Close the app under test
driver.CloseApp();
// Install the upgrade version of the app
driver.InstallApp("<hashed app-id>");
// Launch the app using the package and launcher activity of the app
driver.ExecuteScript("mobile:startActivity", new Dictionary<string, object>
{
{ "intent", "com.browserstack.sample.MainActivity" },
{ "package", "com.browserstack.sample" }
});
// Your test with upgrade version v1.1 goes here
}
finally
{
driver.Quit();
}
}
}
<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
function testAppUpgrade() {
$capabilities = DesiredCapabilities::android();
$capabilities->setCapability('platformVersion', '9.0');
$capabilities->setCapability('deviceName', 'Google Pixel 3');
$capabilities->setCapability('app', 'bs://<hashed app-id>');
$capabilities->setCapability('bstack:options', ['midSessionInstallApps' => ['bs://<hashed app-id>']]);
$driver = RemoteWebDriver::create(
'https://hub.browserstack.com/wd/hub',
$capabilities,
'YOUR_BROWSERSTACK_USERNAME',
'YOUR_BROWSERSTACK_ACCESS_KEY'
);
try {
// Your test with v1.0 goes here
// Close the app under test
$driver->terminateApp('com.browserstack.sample');
$driver->executeScript('mobile:terminateApp', ['appId' => 'com.browserstack.sample']);
// Install the upgrade version of the app
$driver->executeScript('mobile:installApp', ['appPath' => 'bs://<hashed app-id>']);
// Launch the app using the package and launcher activity of the app
$driver->executeScript('mobile:startActivity', ['intent' => 'com.browserstack.sample.MainActivity', 'package' => 'com.browserstack.sample']);
// Your test with upgrade version v1.1 goes here
} finally {
$driver->quit();
}
}
testAppUpgrade();
?>
from appium import webdriver
def test_app_upgrade():
desired_caps = {
'platformName': 'Android',
'platformVersion': '9.0',
'deviceName': 'Google Pixel 3',
'app': 'bs://<hashed app-id>',
'bstack:options': {'midSessionInstallApps': ['bs://<hashed app-id>']}
}
driver = webdriver.Remote(
command_executor='https://hub.browserstack.com/wd/hub',
desired_capabilities=desired_caps,
username='YOUR_BROWSERSTACK_USERNAME',
access_key='YOUR_BROWSERSTACK_ACCESS_KEY'
)
try:
# Your test with v1.0 goes here
# Close the app under test
driver.terminate_app('com.browserstack.sample')
driver.execute_script('mobile:terminateApp', {'appId': 'com.browserstack.sample'})
# Install the upgrade version of the app
driver.execute_script('mobile:installApp', {'appPath': 'bs://<hashed app-id>'})
# Launch the app using the package and launcher activity of the app
driver.execute_script('mobile:startActivity', {'intent': 'com.browserstack.sample.MainActivity', 'package': 'com.browserstack.sample'})
# Your test with upgrade version v1.1 goes here
finally:
driver.quit()
test_app_upgrade()
require 'appium_lib'
def test_app_upgrade
caps = {
platformName: 'Android',
platformVersion: '9.0',
deviceName: 'Google Pixel 3',
app: 'bs://<hashed app-id>',
'bstack:options': { midSessionInstallApps: ['bs://<hashed app-id>'] }
}
opts = {
caps: caps,
appium_lib: {
server_url: 'https://hub.browserstack.com/wd/hub',
wait_timeout: 30
}
}
driver = Appium::Driver.new(opts, true).start_driver
begin
# Your test with v1.0 goes here
# Close the app under test
driver.terminate_app('com.browserstack.sample')
driver.execute_script('mobile:terminateApp', { appId: 'com.browserstack.sample' })
# Install the upgrade version of the app
driver.execute_script('mobile:installApp', { appPath: 'bs://<hashed app-id>' })
# Launch the app using the package and launcher activity of the app
driver.execute_script('mobile:startActivity', { intent: 'com.browserstack.sample.MainActivity', package: 'com.browserstack.sample' })
# Your test with upgrade version v1.1 goes here
ensure
driver.quit
end
end
test_app_upgrade
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://<hashed app-id>");
// Set app_url obtained after uploading the upgrade version v1.1 of app
capabilities.setCapability("browserstack.midSessionInstallApps", new String[]{"bs://<hashed app-id>"});
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://<hashed app-id>");
// 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();
}
}
}
const { remote } = require('webdriverio');
async function testAppUpgrade() {
const capabilities = {
browserstack: {
user: 'YOUR_USERNAME',
key: 'YOUR_ACCESS_KEY',
device: 'Samsung Galaxy S8',
os_version: '7.0',
name: 'Test_app_upgrade',
'browserstack.appium_version': '1.20.2'
},
app: 'bs://<hashed app-id>',
'browserstack.midSessionInstallApps': ['bs://<hashed app-id>']
};
const browserstackOptions = {
hostname: 'hub.browserstack.com',
port: 443,
path: '/wd/hub',
protocol: 'https'
};
const driver = await remote({
capabilities,
...browserstackOptions
});
try {
// Your test with v1.0 goes here
// Close the app under test
await driver.terminateApp('com.browserstack.sample');
// Install the upgrade version of the app
await driver.installApp('bs://<hashed app-id>');
// Launch the app using the package and launcher activity of the app
await driver.activateApp('com.browserstack.sample');
// Your test with upgrade version v1.1 goes here
} finally {
await driver.deleteSession();
}
}
testAppUpgrade();
using System;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Android;
class Program
{
static void Main(string[] args)
{
TestAppUpgrade();
}
static void TestAppUpgrade()
{
var options = new AppiumOptions();
options.AddAdditionalCapability("browserstack.user", "YOUR_USERNAME");
options.AddAdditionalCapability("browserstack.key", "YOUR_ACCESS_KEY");
options.AddAdditionalCapability("device", "Samsung Galaxy S8");
options.AddAdditionalCapability("os_version", "7.0");
options.AddAdditionalCapability("name", "Test_app_upgrade");
options.AddAdditionalCapability("app", "bs://<hashed app-id>");
options.AddAdditionalCapability("browserstack.appium_version", "1.20.2");
options.AddAdditionalCapability("browserstack.midSessionInstallApps", new string[] { "bs://<hashed app-id>" });
var driver = new AndroidDriver<AndroidElement>(new Uri("https://hub.browserstack.com/wd/hub"), options);
try
{
// Your test with v1.0 goes here
// Close the app under test
driver.CloseApp();
// Install the upgrade version of the app
driver.InstallApp("bs://<hashed app-id>");
// Launch the app using the package and launcher activity of the app
driver.ActivateApp("com.browserstack.sample");
// Your test with upgrade version v1.1 goes here
}
finally
{
driver.Quit();
}
}
}
<?php
require_once('vendor/autoload.php'); // Assuming you have webdriverio installed via Composer
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
async function testAppUpgrade() {
$capabilities = [
'browserstack' => [
'user' => 'YOUR_USERNAME',
'key' => 'YOUR_ACCESS_KEY',
'device' => 'Samsung Galaxy S8',
'os_version' => '7.0',
'name' => 'Test_app_upgrade',
'browserstack.appium_version' => '1.20.2'
],
'app' => 'bs://<hashed app-id>',
'browserstack.midSessionInstallApps' => ['bs://<hashed app-id>']
];
$browserstackOptions = [
'hostname' => 'hub.browserstack.com',
'port' => 443,
'path' => '/wd/hub',
'protocol' => 'https'
];
$webDriver = RemoteWebDriver::create(
'https://hub.browserstack.com/wd/hub',
$capabilities,
'YOUR_USERNAME',
'YOUR_ACCESS_KEY'
);
try {
// Your test with v1.0 goes here
// Close the app under test
$webDriver->terminateApp('com.browserstack.sample');
// Install the upgrade version of the app
$webDriver->installApp('bs://<hashed app-id>');
// Launch the app using the package and launcher activity of the app
$webDriver->activateApp('com.browserstack.sample');
// Your test with upgrade version v1.1 goes here
} finally {
$webDriver->quit();
}
}
testAppUpgrade();
?>
from appium import webdriver
def test_app_upgrade():
desired_caps = {
'browserstack.user': 'YOUR_USERNAME',
'browserstack.key': 'YOUR_ACCESS_KEY',
'device': 'Samsung Galaxy S8',
'os_version': '7.0',
'name': 'Test_app_upgrade',
'app': 'bs://<hashed app-id>',
'browserstack.appium_version': '1.20.2',
'browserstack.midSessionInstallApps': ['bs://<hashed app-id>']
}
driver = webdriver.Remote(
command_executor='https://hub.browserstack.com/wd/hub',
desired_capabilities=desired_caps
)
try:
# Your test with v1.0 goes here
# Close the app under test
driver.terminate_app('com.browserstack.sample')
# Install the upgrade version of the app
driver.install_app('bs://<hashed app-id>')
# Launch the app using the package and launcher activity of the app
driver.activate_app('com.browserstack.sample')
# Your test with upgrade version v1.1 goes here
finally:
driver.quit()
test_app_upgrade()
require 'appium_lib'
def test_app_upgrade
caps = {
'browserstack.user': 'YOUR_USERNAME',
'browserstack.key': 'YOUR_ACCESS_KEY',
'device': 'Samsung Galaxy S8',
'os_version': '7.0',
'name': 'Test_app_upgrade',
'app': 'bs://<hashed app-id>',
'browserstack.appium_version': '1.20.2',
'browserstack.midSessionInstallApps': ['bs://<hashed app-id>']
}
opts = {
caps: caps,
appium_lib: {
server_url: 'https://hub.browserstack.com/wd/hub'
}
}
driver = Appium::Driver.new(opts, true).start_driver
begin
# Your test with v1.0 goes here
# Close the app under test
driver.terminate_app('com.browserstack.sample')
# Install the upgrade version of the app
driver.install_app('bs://<hashed app-id>')
# Launch the app using the package and launcher activity of the app
driver.activate_app('com.browserstack.sample')
# Your test with upgrade version v1.1 goes here
ensure
driver.quit
end
end
test_app_upgrade
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.
For JSONwire browserstack.midSessionInstallApps
and W3C midSessionInstallApps
capabilities can also be used to install any other app in between the test session.
Sample iOS code snippet
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
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!