Last updated: Dec 11, 2018 16:17
When implementing a Smart Retry mechanism, one possibility is by simply trying to create a driver to establish a connection with the device.
The disadvantage of this approach is, that it causes an Error- which is also represented in the DigitalZoom reporting, adding unnecessary noise which makes analyzing results harder.
Another disadvantage is, that trying to connect to the device through Selenium/Appium is not immediate. A plain REST API call has much less overhead being much faster.
This is what we will discuss below, for an example Java implementation.
An option is to use a REST API call to verify whether a device is available, before actually attempting to create an Appium/Selenium driver.
In this example project, a helper class has been added, which exposes a CheckIfDevicesAvailable method. This will translate the DesiredCapabilities related to Device Selection (deviceName, model, ...) into a parameters which it will then use in a Get Devices List REST call.
Returning true or false, depending on whether one or more devices are available- or not.
- Add the Class "DeviceSelectHelper" to your project. You find it here.
- If you don't already have it, add the capability "user" to the Desired Capabilities to the existing capabilities.
This will be used to determine whether a device is available for the executing user.
Before creating the driver, call the DeviceSelectHelper.CheckIfDevicesAvailable.
This will return true if there is at least 1 device available to be opened, that complies with the given capabilities.
Depending on the returned value being true or false, your framework can either stop the test, or keep retrying for a number of times (pausing in between retries) before giving up.
The example is kept extremely simple and will simply stop the execution if no compliant device is available:
The helper class used is just an example to show what is possible. It does not necessarily have all all selection parameters that you are looking for but can be easily adjusted to your requirements.