How to use getAgentDevice method of com.testsigma.agent.mobile.DeviceContainer class

Best Testsigma code snippet using com.testsigma.agent.mobile.DeviceContainer.getAgentDevice

Source:DeviceContainer.java Github

copy

Full Screen

...51 return;52 }53 String deviceUniqueId = mobileDevice.getUniqueId();54 if (deviceUniqueId != null && !deviceMap.containsKey(deviceUniqueId)) {55 AgentDeviceDTO agentDeviceDTO = getAgentDevice(deviceUniqueId);56 if (agentDeviceDTO == null) {57 log.info("Found a new device. Adding an entry for the device: " + mobileDevice);58 createAgentDevice(mobileDeviceMapper.map(mobileDevice));59 } else {60 log.info("Found an existing device. Updating the entry for the device: " + mobileDevice);61 mobileDeviceMapper.merge(mobileDevice, agentDeviceDTO);62 updateAgentDevice(agentDeviceDTO);63 }64 deviceMap.put(mobileDevice.getUniqueId(), mobileDevice);65 if (mobileDevice.getMuxDeviceId() != null) {66 muxDeviceMap.put(mobileDevice.getMuxDeviceId(), mobileDevice);67 }68 mobileAutomationServerService.installDrivers(mobileDevice.getOsName(), mobileDevice.getUniqueId());69 syncBrowserDrivers(mobileDevice);70 } else {71 log.info("Device " + deviceUniqueId + " already in container...");72 }73 } catch (Exception e) {74 log.error(e.getMessage(), e);75 throw new DeviceContainerException(e.getMessage(), e);76 }77 }78 public void syncBrowserDrivers(MobileDevice mobileDevice) {79 log.info("Syncing Browser Drivers For Mobile Devices - " + mobileDevice);80 List<AgentBrowser> browserList = mobileDevice.getBrowserList();81 if (browserList == null) {82 return;83 }84 for (AgentBrowser browserObj : browserList) {85 try {86 log.info("Trying to sync driver for mobile browser - " + browserObj);87 OsBrowserType browserType = browserObj.getName();88 String browserVersion = browserObj.getMajorVersion() + "";89 Browsers browser = OsBrowserType.getBrowserType(browserType);90 String driverPath = AutomatorConfig.getInstance().getAppBridge().getDriverExecutablePath(browser.getKey(),91 browserVersion);92 new DriversUpdateService().syncBrowserDriver(browserType, browserVersion, driverPath);93 } catch (AutomatorException e) {94 log.error(e.getMessage(), e);95 }96 }97 }98 public void deleteDevice(String uniqueId) throws DeviceContainerException {99 try {100 for (Entry<String, MobileDevice> entry : deviceMap.entrySet()) {101 String key = entry.getKey();102 MobileDevice device = entry.getValue();103 if (key.equals(uniqueId)) {104 log.info("Removing the device " + key + " from device container");105 AgentDeviceDTO agentDeviceDTO = getAgentDevice(key);106 if (agentDeviceDTO != null) {107 agentDeviceDTO.setIsOnline(false);108 updateAgentDevice(agentDeviceDTO);109 }110 deviceMap.remove(key);111 muxDeviceMap.remove(device.getMuxDeviceId());112 break;113 }114 }115 } catch (Exception e) {116 log.error(e.getMessage(), e);117 throw new DeviceContainerException(e.getMessage(), e);118 }119 }120 public void disconnectDevices() throws DeviceContainerException {121 try {122 for (Entry<String, MobileDevice> entry : deviceMap.entrySet()) {123 String key = entry.getKey();124 MobileDevice device = entry.getValue();125 log.info("Removing the device " + key + " from device container");126 AgentDeviceDTO agentDeviceDTO = getAgentDevice(key);127 if (agentDeviceDTO != null) {128 agentDeviceDTO.setIsOnline(false);129 updateAgentDevice(agentDeviceDTO);130 }131 deviceMap.remove(key);132 muxDeviceMap.remove(device.getMuxDeviceId());133 }134 log.info("Removed all the devices - " + deviceMap.size());135 } catch (Exception e) {136 log.error(e.getMessage(), e);137 throw new DeviceContainerException(e.getMessage(), e);138 }139 }140 public MobileDevice getDevice(String uniqueId) throws TestsigmaException {141 if ((uniqueId == null) || !this.deviceMap.containsKey(uniqueId)) {142 throw new TestsigmaException(String.format("There is no device with unique Id %s in device container", uniqueId));143 }144 return this.deviceMap.get(uniqueId);145 }146 public MobileDevice getDeviceByMuxId(String muxId) throws TestsigmaException {147 if ((muxId == null) || !this.muxDeviceMap.containsKey(muxId)) {148 throw new TestsigmaException(String.format("There is no device with mux Id %s in device container", muxId));149 }150 return this.muxDeviceMap.get(muxId);151 }152 private AgentDeviceDTO getAgentDevice(String uniqueId) throws DeviceContainerException {153 try {154 AgentDeviceDTO agentDeviceDTO = null;155 String agentUuid = agentConfig.getUUID();156 String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();157 HttpResponse<AgentDeviceDTO> response =158 httpClient159 .get(ServerURLBuilder.agentConnectedDeviceURL(agentUuid, uniqueId), new TypeReference<>() {160 }, authHeader);161 if (response.getStatusCode() == HttpStatus.OK.value()) {162 agentDeviceDTO = response.getResponseEntity();163 }164 return agentDeviceDTO;165 } catch (Exception e) {166 log.error(e.getMessage(), e);...

Full Screen

Full Screen

getAgentDevice

Using AI Code Generation

copy

Full Screen

1def device = getAgentDevice()2def deviceName = device.getName()3def deviceId = device.getId()4def deviceType = device.getType()5def deviceOS = device.getOS()6def deviceOSVersion = device.getOSVersion()7def deviceManufacturer = device.getManufacturer()8def deviceModel = device.getModel()9def deviceResolution = device.getResolution()10def deviceIPAddress = device.getIPAddress()11def devicePort = device.getPort()12def deviceSerialNumber = device.getSerialNumber()13def deviceManufacturer = device.getManufacturer()

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testsigma automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful