How to query which device is connected before test run

Hi All,

I’ve built a framework for my automation which uses the same classes to run both Android & iOS.
In order to start the proper driver and pass the proper elements I need to query which device is currently running, or even better which device is currently connected before the initialization of the test.

Do you have any idea how can I do it?

Cheers,
Liran

Typically a user will know what device(s) should available to test with. I suppose you could cycle thru these devices programmatically, trying to connect, to see whats actually there. You can use getCapabilities to get a better idea of the capabilities of each phone. you were able to connect to.

Things are likely more flexible if using Experitest’s upcoming appium cloud solution.

1 Like

I agree with Walter’s comment

namely with the approach that allows you to get the current capabilities of a driver post initialization
We also have a capability which allows you to query for a device based on XPath expressions :

dc.setCapability("deviceQuery", "(@versionnumber >= 10 and contains(@model,'Nexus'))");
AppiumDriver driver = new AndroidDriver(url,dc);
// returns a map of existing driver capabilities
Map capsMap = driver.getCapabilities().asMap();

To learn more about the parameters which can be filtered by device queries -

https://docs.experitest.com/display/public/TD/SeeTestAutomation-+WaitForDevice

Other option:

String devicesXml = driver.executeScript(“client:client.getDevicesInformation();”);

It should return a string in xml format containing the devices information.