How to Switch Between Apps at Runtime Using Appium

How to Switch Between Apps at Runtime Using Appium

5 April 2024 Stephan Petzl Leave a comment Tech-Help

When it comes to automated testing of mobile applications, Appium is a go-to framework for many professionals. A common scenario encountered during testing is the need to switch between two applications at runtime. This guide provides a step-by-step approach to accomplish this task using Appium.

Setting Up Your Test Environment

Before you begin, it’s important to set up your test environment correctly. You’ll need to specify the capabilities for the applications you intend to switch between. Here’s how to set up for two example applications: a calculator app and a settings app on an Android device.

Specifying App Capabilities

DesiredCapabilities capabilities =;
capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "Android");
capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "");
capabilities.setCapability(MobileCapabilityType.APP_PACKAGE, "");
capabilities.setCapability(MobileCapabilityType.APP_ACTIVITY, "");

AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

Executing Tests Across Multiple Apps

Once your initial application is launched and your tests are underway, you may want to switch to another application. Here’s an example of how to perform a simple calculation in the calculator app and then switch to the settings app to turn off Wi-Fi:

Performing Actions in the First App

// Perform calculation in calculator

Switching to the Second App

// Launch settings App
driver.startActivity("", "");

// Switch OFF WIFI

Returning to the First App

// Re-launch calculator App
driver.startActivity("", "");

// Validate results
String result = driver.findElement(By.className("android.widget.EditText")).getText();
System.out.println("Result : " + result);
Assert.assertEquals("Incorrect Result", "12", result);


Switching between applications during runtime using Appium is a straightforward process once you have properly configured the desired capabilities for each app. By following the steps outlined above, you can automate tests that involve multiple applications, enhancing your testing efficiency and coverage.

Note: Always ensure that your test environment is set up correctly and that you understand the specific capabilities required for the applications you are testing. This will help avoid common pitfalls and ensure a smooth testing experience.

Like this article? there’s more where that came from!