A sample showing how to test a flow that spans two Android apps in one session on BrowserStack App Automate real devices, using Appium (Java), TestNG and no BrowserStack SDK. A typical use case is a banking app that needs an OTP from a separate soft-token / authenticator app.
The test shows how to:
- The primary app (SecureBank Demo,
com.example.securebank) is installed withappium:app. - The secondary app (SecureToken Demo,
com.example.securetoken) is pre-installed alongside it withappium:otherApps. - Mid-test, the script opens the secondary app through its deep link
(
securetoken://auth?requestId=req_98765), reads the OTP, and switches back to the primary app withdriver.activateApp()without resetting the session.
MultiAppTestProject/
apps/
SecureBank-debug.apk primary app (com.example.securebank)
SecureToken-debug.apk secondary app (com.example.securetoken)
src/test/java/com/demo/automation/MultiAppOtpTest.java
pom.xml
The two APKs are ready to use. You do not need to build anything.
- JDK 11 or later and Maven 3.8+
- A BrowserStack account with App Automate
export BROWSERSTACK_USERNAME=<your-username>
export BROWSERSTACK_ACCESS_KEY=<your-access-key>Run these from the MultiAppTestProject folder. Each response contains an app_url of the form
bs://<hash>; note both values.
# Primary app
curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@apps/SecureBank-debug.apk" \
-F "custom_id=SecureBankDemo"
# Secondary app
curl -u "$BROWSERSTACK_USERNAME:$BROWSERSTACK_ACCESS_KEY" \
-X POST "https://api-cloud.browserstack.com/app-automate/upload" \
-F "file=@apps/SecureToken-debug.apk" \
-F "custom_id=SecureTokenDemo"mvn clean test \
-DPRIMARY_APP=bs://<PRIMARY_APP_ID> \
-DSECONDARY_APP=bs://<SECONDARY_APP_ID>Results appear in the BrowserStack App Automate dashboard under the project
Multi App OTP Demo. The test sets the session status (passed / failed) itself.
- Logs in to the SecureBank app (
txtUsername,txtPassword,btnLogin). - Taps Open Token App (
btnOpenTokenApp) on the verification screen. - Opens the SecureToken app through its deep link and waits until it is in the foreground.
- Reads the OTP from
lblGeneratedToken. - Switches back to SecureBank with
driver.activateApp("com.example.securebank"). - Enters the OTP in
txtOtpInputand tapsbtnVerifyOtp. - Asserts
lblStatuscontainsSuccess: Transaction Approved!. - Marks the BrowserStack session as passed or failed.
- Device and OS are set in
MultiAppOtpTest.setUp()(currently Samsung Galaxy S23, Android 13.0). BrowserStack rejects a device and OS combination it does not offer; see the capability builder for valid pairs. otherAppsis a top-level capability (appium:otherApps), not part ofbstack:options.- Credentials are read from environment variables and are never stored in the project.
- The demo OTP is the fixed value
849201, which the SecureBank app accepts.