Run Same Script in Multiple Devices using Appium

Learn how to run same script in multiple using Appium. Enhance your Appium tests with BrowserStack.

Get Started free
Home Guide How to Run Same Script in Multiple Devices using Appium

How to Run Same Script in Multiple Devices using Appium

By Manish Saini, Community Contributor -

Running your test script on different devices is non-negotiable when it comes to mobile app testing. This practice validates your app’s functionality and consistency across diverse platforms, screen sizes, and configurations.

Appium supports cross-platform testing for iOS and Android, allowing you to run the same test script on multiple devices efficiently. By utilizing Appium capabilities like cross-browser and parallel testing, you can run a single test script on different devices, thus saving time.

Read further to learn in detail how to run the same script on multiple devices using Appium.

Why Running the Same Script on Multiple Devices is Important?

Testing an application on multiple devices is an important step in the QA process. You should be sure that your application works with different devices, OS versions, and screen sizes.

Running the Same Script on Multiple Devices

There are many reasons why it is important to test applications on multiple devices. One of the most important reasons is that users may use different types of devices to access the same app. It is not possible to predict which device a user will use to access the app, so you need to make sure that it works. To ensure that you can easily run our Automation Script on multiple devices.

How to Run Same Script in Multiple Devices using Appium?

When you are running the Appium script, you need to pass Appium desired capabilities, which include platformName, platformVersion, and your deviceName.

{
"platformName": "iOS",
"platformVersion": "11.0",
"deviceName": "iPhone 9",
"automationName": "XCUITest",
"app": "/path/to/my.app"
}

To run your test script on another device, change the desired capabilities of your test script, and it will run our test script on that specific device. You do not need to change your test script to run it on different devices. However, it may be different from executing test scripts on Android and iOS devices because element locators may differ on Android and iOS devices. But a script written for any android or iOS device can be run on all devices with the same OS by changing desired capabilities.

Challenges In Managing Multiple Devices

Running your script on multiple devices is the easy-to-do thing in your Automation Testing process but managing those devices and having multiple devices is the hardest part and a costly affair for your Automation process. If iPhones are considered, iPhone6 to iPhone13 are used by the users with a mix of iOS11 to iOS16. And, When it comes to Android, these numbers increased massively. No team can manage or own all the popular devices presented in the market with different OS versions.

Why Emulators and Simulators are Not Reliable Alternatives

First, which comes to our mind to solve this is using emulators and simulators for different devices. But testing on an emulator/simulator is not the same as testing on Real Devices. While simulators and emulators will come close to imitation, it’s impossible to perform the same as a real device. This is because emulators can’t account for every single environmental factor, feature, or user action performed on a real device. The advantage of real devices is in the name. Testing on real, physical devices means that you’re testing the same way your users operate their devices.

Testing on Real Devices: Advantage

Here BrowserStack comes as a savior to free up the device mess. BrowserStack App Automate provides all popular devices with different OS versions to test your application automatically using Appium. You can easily integrate BrowserStack into your framework to test your scripts over multiple devices.

BrowserStack App Automate Banner

Best Practices to Run Same Script on Multiple Devices using Appium

Covering enough devices to test your application and making it top-notch for users cannot be compromised. Here are some best practices to follow while running the same script on multiple devices with Appium:

  • Leverage Parallel Testing: Configure Appium with TestNG or JUnit to concurrently execute tests on diverse devices.
  • Abstract Test Logic: In order to facilitate reusability, you should separate test logic from device-specific configurations.
  • Dynamic Locators: Utilize universal locators like accessibilityId or dynamic strategies to manage device differences.
  • Managing Sessions: Make sure each device has an independent session for easy management and minimizing conflicts.
  • Managing Flaky Tests: Execute retries or wait mechanisms to handle flakiness or delays specific to a device.
  • Logging and Reporting: Maintain device-specific reports and detailed logs to analyze and debug efficiently.
  • Device Cloud: Use cloud testing platforms like BrowserStack to access a vast real-device cloud of 3500+ device-OS combinations and test your app without having to maintain a physical device lab.

Running Appium Scripts on Multiple Devices using BrowserStack

Running Appium Scripts on Multiple Devices

Running your test script on BrowserStack with multiple devices is quite hassle-free by using App Automate. You just need to follow a few steps to change your configurations and it will integrate your existing test automation with BrowserStack.

Step 1: Sign Up on BrowserStack and get a username and access key for your account. You will find the button to get your username and access key just after login

get your username and access key

Talk to an Expert

Step 2: Upload your .apk or .ipa file on BrowserStack. You can do this by using Upload your App on your Dashboard or you can also use BrowserStack APIs to upload it automatically. You will get an App URL after uploading your application.

{
"app_url":"bs://f7c874f21852ba57957a3fdc33f47514288c4ba4"
}

Upload your App

Step 3: Specify the application under test using the app capability. Use the app_url value returned at app upload (Step 2) to set this capability.

  • Specify the real Android or iOS device you want to test using the device capability.
  • In order to initialize an Appium driver, use a remote BrowserStack URL along with your BrowserStack access credentials (mentioned in  step 1)  as shown below :

https://YOUR_USERNAME:YOUR_ACCESS_KEY@hub-cloud.browserstack.com/wd/hub

It will look like this:

userName = "YOUR_USERNAME"
accessKey = "YOUR_ACCESS_KEY"
desired_caps = { "build": "Android",
"device": "Samsung Galaxy S8 Plus",
“platformVersion": "11.0",
"app": "<app_url>"
}
driver = webdriver.Remote("https://" + userName + ":" + accessKey +
"@hub-cloud.browserstack.com/wd/hub", desired_caps)

By doing this your Appium script starts running on BrowserStack Real Devices on the cloud.

Appium script starts running

 You can easily change the device by changing its name and platform version in desired caps. On BrowserStack, you can also run your test in parallel to finish your automation faster. BrowserStack provides Video, Device Logs, Network Logs, and Appium Logs for debugging, and you can check your test runs on your Dashboard. BrowserStack can help you run your Test Scripts with multiple devices, and you do not have to manage these devices by yourself.

BrowserStack Automate

Conclusion

BrowserStack’s App Automate makes testing on multiple real devices easy. By simply changing the Desired Capabilities, the user can easily run tests on thousands of devices and systematically determine whether your application is ready to release or not. QA Teams will find it easy to use the results dashboard to find and debug issues instantly.

Run Appium Tests For Free

Tutorials

Best Practices, Tips, and Tricks

Getting Started with

Differences and Comparisons

Tags
App Automate Appium Automation Testing Real Device Cloud

Featured Articles

Desired Capabilities in Appium

How to Run Your First Appium Test Script

Automation Tests on Real Android & iOS Devices

Seamlessly Run Mobile App Automation Tests on real Android & iOS Devices