com.appium.device.DevicesByHost Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of AppiumTestDistribution Show documentation
Show all versions of AppiumTestDistribution Show documentation
A tool run Android and iOS test in parallel across devices
package com.appium.device;
import com.appium.ios.IOSDeviceConfiguration;
import com.appium.manager.AppiumDevice;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
public class DevicesByHost {
private ConcurrentHashMap> devicesByHost;
DevicesByHost(Map> devicesByHost) {
this.devicesByHost = new ConcurrentHashMap<>(devicesByHost);
}
public List getAllDevices() {
return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
stringListEntry.getValue().parallelStream())
.collect(Collectors.toList());
}
public List getAllSimulators() {
return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
stringListEntry.getValue().parallelStream().filter(device ->
device.getDevice().getUdid().length()
== IOSDeviceConfiguration.SIM_UDID_LENGTH))
.collect(Collectors.toList());
}
public List getAllIOSDevices() {
return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
stringListEntry.getValue().parallelStream().filter(device ->
device.getDevice().getUdid().length()
== IOSDeviceConfiguration.IOS_UDID_LENGTH))
.collect(Collectors.toList());
}
public List getAllAndroidDevices() {
return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
stringListEntry.getValue().parallelStream().filter(device ->
(device.getDevice().getUdid().length()
!= IOSDeviceConfiguration.IOS_UDID_LENGTH
&& device.getDevice().getUdid().length()
!= IOSDeviceConfiguration.SIM_UDID_LENGTH)))
.collect(Collectors.toList());
}
public AppiumDevice getDeviceProperty(String uuid) {
return devicesByHost.entrySet().parallelStream().flatMap(stringListEntry ->
stringListEntry.getValue().parallelStream().filter(device ->
device.getDevice().getUdid().equalsIgnoreCase(uuid)))
.collect(Collectors.toList()).get(0);
}
public Set getAllHosts() {
return devicesByHost.keySet();
}
public Map> getAllHostDevices() {
return devicesByHost;
}
public AppiumDevice getAppiumDevice(String deviceUdid, String hostName) {
List devicesInHost = devicesByHost.get(hostName);
return devicesInHost.stream().filter(appiumDevice ->
appiumDevice.getDevice().getUdid().equals(deviceUdid)).findFirst().get();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy