id | title | sidebar_label | description |
---|---|---|---|
test-app-upgrades |
Test App Upgrades/Mid-Session App Installations |
Test App Upgrades |
Learn how to test app upgrades or mid-session app installations. |
import useBaseUrl from '@docusaurus/useBaseUrl'; import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem';
As app developers, we often release newer versions of our applications to customers on a regular basis. In these instances, users are typically upgrading from an older version rather than installing the app from scratch. This transition may involve the migration of existing user data for the application to function correctly, which makes the testing of app upgrades a crucial step in the development process. By testing app upgrades, we can ensure that our application continues to operate as expected even following an upgrade.
But app upgrades aren't the only scenario where you might need to install apps during a running session. Sometimes, your app's functionality might rely on other dependent applications. In such cases, testing your app's interplay with these dependencies becomes essential. For instance, if your application pulls data from or interacts with another app, you'd want to ensure that this interaction remains smooth even after an upgrade. This makes the ability to install dependent apps during a run an invaluable feature for comprehensive testing.
There are scenarios where you might want to delete an app and reinstall it again during a running session. For example, if you want to test the app's behavior when a user deletes and reinstalls it, you can use the mid-session install feature to accomplish this task. (Deleting apps can be done for Android and iOS command.)
:::caution Important Installing apps mid-session from the Sauce Storage is only supported in our Real Device Cloud. :::
Before running your test execution, the first step involves uploading the app that is intended for upgrade (the newer version) or any dependent app. You can accomplish this task using our REST API. This process is similar to how you would handle your app under test.
After uploading, you can use the following command to install apps mid-session using Appium:
<Tabs groupId="install-app" defaultValue="java" values={[ {label: 'Java', value: 'java'}, {label: 'Node.js', value: 'js'}, {label: 'Python', value: 'python'}, {label: 'Ruby', value: 'ruby'}, {label: 'C#', value: 'csharp'}, ]}>
// When using the file name
driver.executeScript("mobile:installApp", ImmutableMap.of("appPath", "storage:filename=<file-name>.apk|ipa"));
// When using the file id
driver.executeScript("mobile:installApp", ImmutableMap.of("appPath", "storage:<file-id>"));
// When using the file name
driver.execute('mobile:installApp', {"appPath": "storage:filename=<file-name>.apk|ipa"})
// When using the file id
driver.execute('mobile:installApp', {"appPath": "storage:<file-id>"})
# When using the file name
driver.execute_script('mobile: installApp', {"appPath": "storage:filename=<file-name>.apk|ipa"})
# When using the file id
driver.execute_script('mobile: installApp', {"appPath": "storage:<file-id>"})
# When using the file name
@driver.execute_script('mobile: installApp', {"appPath" => "storage:filename=<file-name>.apk|ipa"})
# When using the file id
@driver.execute_script('mobile: installApp', {"appPath" => "storage:<file-id>"})
// When using the file name
driver.ExecuteScript("mobile: installApp", new Dictionary<string, string> { { "appPath", "storage:filename=<file-name>.apk|ipa" } });
// When using the file id
driver.ExecuteScript("mobile: installApp", new Dictionary<string, string> { { "appPath", "storage:<file-id>" } });
A successful installation will return the following response which can be used to validate if the right version of the app was installed:
<Tabs groupId="install-app-response" defaultValue="android" values={[ {label: 'Android', value: 'android'}, {label: 'iOS', value: 'ios'}, ]}>
{
"packageName": "com.saucelabs.mydemoapp.android",
"version": "1.5.0",
"buildNumber": "274"
}
{
"bundleId": "com.saucelabs.mydemoapp.ios",
"version": "1.5.0",
"buildNumber": "191"
}
By default, Appium will not automatically launch the app after a mid-session install. You will need to launch the app manually using the followings commands after installation:
- iOS:
mobile: launchApp
- Android:
mobile: startActivity
We added two extra text lines in the Appium Commands list in the Sauce Labs UI to indicate that the app has been installed and needs to be launched manually. Additionally, you will notice the execution of the command GET /timeouts
. This command acts as a "heartbeat" to keep the session active when installation takes longer than the default timeout of 60 seconds. By setting a maximum timeout of 5 minutes, the Appium session will remain active until the app is successfully installed, ensuring that it doesn't expire prematurely.
<img src={useBaseUrl('img/mobile-apps/appium-mid-session-logs.jpg')} alt="Mid session install logs" width="800" />
The following commands will launch the newly installed app. Remember to replace the bundleId
or intent
with your specific application's identifier or main activity, respectively.
<Tabs groupId="start-app" defaultValue="java" values={[ {label: 'Java', value: 'java'}, {label: 'Node.js', value: 'js'}, {label: 'Python', value: 'python'}, {label: 'Ruby', value: 'ruby'}, {label: 'C#', value: 'csharp'}, ]}>
// Android
driver.executeScript("mobile: startActivity", ImmutableMap.of("intent", "com.saucelabs.mydemoapp.rn/.MainActivity"));
// iOS
driver.executeScript("mobile: launchApp", ImmutableMap.of("bundleId", "com.saucelabs.mydemoapp.rn"));
// Android
driver.execute('mobile: startActivity', {intent: 'com.saucelabs.mydemoapp.rn/.MainActivity'});
//
driver.execute('mobile: launchApp', { bundleId: 'com.saucelabs.mydemoapp.rn'});
# Android
driver.execute_script("mobile: startActivity", {"intent": "com.saucelabs.mydemoapp.rn/.MainActivity"})
# iOS
driver.execute_script("mobile: launchApp", {"bundleId": "com.saucelabs.mydemoapp.rn"})
# Android
@driver.execute_script("mobile: startActivity", {"intent" => "com.saucelabs.mydemoapp.rn/.MainActivity"})
# iOS
@driver.execute_script("mobile: launchApp", {"bundleId" => "com.saucelabs.mydemoapp.rn"})
// Android
driver.ExecuteScript("mobile: startActivity", new Dictionary<string, string> { { "intent", "com.saucelabs.mydemoapp.rn/.MainActivity" } });
// iOS
driver.ExecuteScript("mobile: launchApp", new Dictionary<string, string> { { "bundleId", "com.saucelabs.mydemoapp.rn" } });
This is an example test execution that installs an app mid-session, launches it, and:
- Validates that the version has been upgraded.
- Validates that the user data from the previous version has been retained.
<video controls style={{"max-width": "800px"}}>