How to Run Same Script in Multiple Devices using Appium
By Manish Saini, Community Contributor - December 27, 2024
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?
- How to Run Same Script in Multiple Devices using Appium?
- Challenges In Managing Multiple Devices
- Why Emulators and Simulators are Not Reliable Alternatives
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.
Read More: How to set up QA processes from scratch
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.
Read More: Running Appium Tests on an iOS Device
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.
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.
Read More: How to Perform Mobile Browser Debugging
- 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 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
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" }
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.
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.
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.
Tutorials
- How to perform Parallel Test Execution in Appium?
- Appium Visual Testing: The Essential Guide
- How to run Appium iOS Tests on Real Devices?
- How to perform Debugging in Appium
- How to Run Your First Appium Test Script
- How to report bugs in Appium UI Testing?
- How to run Appium Tests on macOS?
- XPath in Appium: Tutorial
- How to Analyze Appium Logs
- How to perform Drag and Drop using Appium
- How to test mobile app in Landscape or Portrait mode using Appium
- How to Run Same Script in Multiple Devices using Appium
- How to change Time Zones for Mobile App Testing using Appium
- How to Perform Localization of Mobile Apps using Appium
- What is Appium Inspector? (Benefits & How to Use it?)
- How to run Appium tests on Android devices
- How to scroll down to an element in Appium
- How to Download and Install Appium
- How to set up your Appium Grid
- How to test Biometric authentication using Appium?
- How to use touch actions in Appium?
- How to Automate a Real E2E User Flow involving App and Browser with Appium
- How to Inspect Element using UIAutomatorViewer in Appium
- How to Test Flutter Apps Using Appium Automation
- Understanding Appium Desktop: Tutorial
- Appium Tutorial for Mobile Application Testing
- React Native and Appium Tutorial
- Understanding FindElements in Appium
Best Practices, Tips, and Tricks
- Appium Best Practices Every Developer Must Know
- Effective Locator Strategies in Appium
- Top Appium Commands every Developer must know
- Desired Capabilities in Appium
- Overcoming Top Challenges faced in Appium Automation
Getting Started with
- Getting Started with Appium and NUnit framework
- WebdriverIO Tutorial: Getting started with Test Automation using Selenium and Appium
- Appium with Python: Getting Started with App Automation Testing
- Appium with Java: Getting Started to Run Automated Tests
- Test Windows Desktop App using Appium-Compatible WinAppDriver
Differences and Comparisons