How to Run Same Script in Multiple Devices using Appium
By Manish Saini, Community Contributor - May 23, 2022
Automation testing of mobile applications has been around for a while now. It was considered a luxury to have an automated test suite for your app in the early days. But now, it’s become an essential part of DevOps.
There are many benefits of automation testing, but the following three are the most important:
- Increased test coverage: Automation testing allows you to test more features in less time. This means you can increase your test coverage without increasing your testing budget.
- Reduced risk of human error: Automation tests are less likely to miss edge cases or have other errors when manually testing an app.
- Faster feedback: Automated tests can be run much faster than manual tests. This means you can get feedback on your app much sooner, which can help you fix issues before they become major problems.
Mobile application automation testing is a valuable process that can help you release better quality apps in less time.
Read More: How to Accelerate Product Release Velocity
But the question arises here are you covering enough devices to test your application and making it of top-notch quality. Testing your application on a single device or many devices can result in device-specific issues, UI issues in different resolutions, and functional issues across different OS versions.
Why Running the Same Script on Multiple Devices is Important?
Testing an application on multiple devices is an important step in the QA process. We should be sure that our application works with different devices, OS versions, and screen sizes.
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. We can’t predict which device a user will use to access the app, so we need to make sure that it works. To ensure that we can easily run our Automation Script on multiple devices.
How to Run Same Script in Multiple Devices using Appium?
When we are running our Appium script, we need to pass Appium desired capabilities, which include platformName, platformVersion, and our deviceName.
{ "platformName": "iOS", "platformVersion": "11.0", "deviceName": "iPhone 9", "automationName": "XCUITest", "app": "/path/to/my.app" }
To run your test script on another device, we need to change the desired capabilities of our test script, and it will run our test script on that specific device. We do not need to change our 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 we only talk about iPhones, it has from iPhone6 to iPhone13, which 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
Emulator/Simulator as an Alternative
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.
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.
To conclude,
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.