Hello everybody, If you are a mobile automation engineer, you would know that managing your mobile device capabilities need so much effort in case you change your device frequently. During the test, there are mandatory capabilities that you need to manage like “Platform Name”, “Device Version”, “Device Name” or “UDID” information. In this tutorial, I will explain how to manage appium capabilities dynamically.
You need to run ADB command to extract those kinds of data or you need to manually find them out.
Thanks to Bahadır Üstün, we recently developed a library to fetch information from devices connected to your computer. It fetches any information that can be captured from your IOS or Android device.
In order to use it on Android device, you need to install Android Debug Bridge (ADB) and for IOS, you should install libimobiledevice. Then you can just use a few lines to get a connected device and pass that information to your Desired Capabilities.
Here’s an example:
DeviceInfo deviceInfo = new DeviceInfoImpl(DeviceType.ALL); Device device = deviceInfo.getFirstDevice(); DesiredCapabilities capabilities = new DesiredCapabilities(); capabilities.setCapability(CapabilityType.PLATFORM, device.getDeviceProductName()); capabilities.setCapability("platformName", device.getDeviceProductName()); capabilities.setCapability(CapabilityType.VERSION, device.getProductVersion()); capabilities.setCapability("deviceName", device.getModelNumber()); capabilities.setCapability("udid", device.getUniqueDeviceID()); capabilities.setCapability("app", "#Your App File#"); driver = new RemoteWebDriver(new URL(URL), capabilities);
So whenever a new mobile device is registered into your laptop, you don’t have to change a single line of code. Here is the library GitHub Link: https://github.com/Testinium/MobileDeviceInfo
Canberk Akduygu is a Test Lead working on Test Automation and Performance Testing in Amsterdam at Qardio.