Best Testsigma code snippet using com.testsigma.agent.mobile.ios.IosDeviceService.getSimulatorDevice
Source:IosDeviceService.java
...99 for(String deviceJson : devices) {100 JSONObject deviceJsonObject = getSimulatorProperties(deviceJson);101 if(deviceJsonObject.getString("state").equals(DeviceStatus.BOOTED.getStatus()) && deviceJsonObject.getString("type").equals("simulator")) {102 try {103 MobileDevice device = getSimulatorDevice(deviceJsonObject.getString("udid"));104 deviceList.add(device);105 } catch(Exception e) {106 log.error(e.getMessage());107 }108 }109 }110 return deviceList;111 }112 public JSONObject getDeviceProperties(String uniqueId) throws TestsigmaException {113 try {114 log.info("Fetching device properties for device uniqueID - " + uniqueId);115 IosDeviceCommandExecutor iosDeviceCommandExecutor = new IosDeviceCommandExecutor();116 Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[]{"-u", uniqueId, "info", "--json"}, true);117 String devicePropertiesJsonString = iosDeviceCommandExecutor.getProcessStreamResponse(p);118 log.info("Fetched device properties for device - " + uniqueId + ", properties - " + devicePropertiesJsonString);119 JSONObject devicePropertiesJson = new JSONObject(devicePropertiesJsonString);120 log.info("Fetched device properties for device - " + uniqueId + ", json format - " + devicePropertiesJson);121 return devicePropertiesJson;122 } catch(Exception e) {123 throw new TestsigmaException(e.getMessage());124 }125 }126 public JSONObject getSimulatorProperties(String deviceJson) throws TestsigmaException {127 try {128 return new JSONObject(deviceJson);129 } catch (Exception e) {130 throw new TestsigmaException(e.getMessage());131 }132 }133 public void setupWda(MobileDevice device) throws TestsigmaException, AutomatorException {134 log.info("Setting up WDA on device - " + device.getName());135 try {136 wdaService.installWdaToDevice(device);137 if(device.getIsEmulator()) {138 wdaService.installXCTestToDevice(device);139 }140 wdaService.startWdaOnDevice(device);141 } catch (Exception e) {142 log.error("Error while setting up wda and starting it. Error - ");143 log.error(e.getMessage(), e);144 cleanupWda(device);145 throw new TestsigmaException(e.getMessage(), e);146 }147 }148 public void cleanupWda(MobileDevice device) {149 log.info("Cleaning up WDA on device - " + device.getName());150 try {151 wdaService.stopWdaOnDevice(device);152 } catch (TestsigmaException e) {153 log.error(e.getMessage(), e);154 }155 }156 public String installApp(MobileDevice device, String appUrl, Boolean isEmulator) throws AutomatorException {157 return new AppInstaller(httpClient).installApp(device.getName(), device.getUniqueId(), appUrl, isEmulator);158 }159 public MobileDevice getSimulatorDevice(String udid) throws AutomatorException, TestsigmaException {160 IosDeviceCommandExecutor iosDeviceCommandExecutor = new IosDeviceCommandExecutor();161 Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[]{"describe", "--udid", udid, "--json"}, false);162 String deviceDescriptionJson = iosDeviceCommandExecutor.getProcessStreamResponse(p);163 JSONObject device = getSimulatorProperties(deviceDescriptionJson);164 MobileDevice mobileDevice = new MobileDevice();165 mobileDevice.setOsName(MobileOs.IOS);166 mobileDevice.setUniqueId(device.getString("udid"));167 mobileDevice.setName(device.getString("name"));168 mobileDevice.setOsVersion(device.getString("os_version").split(" ")[1]);169 mobileDevice.setApiLevel(mobileDevice.getOsVersion());170 mobileDevice.setAbi(device.getString("architecture"));171 mobileDevice.setIsOnline(device.getString("state").equals(DeviceStatus.BOOTED.getStatus()));172 mobileDevice.setProductModel(device.isNull("model") ? "-" : device.get("model").toString());173 mobileDevice.setIsEmulator(device.getString("target_type").equals("simulator"));...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!