Best Testsigma code snippet using com.testsigma.agent.exception.DeviceContainerException
Source:DeviceContainer.java
...9package com.testsigma.agent.mobile;10import com.testsigma.agent.browsers.AgentBrowser;11import com.testsigma.agent.config.AgentConfig;12import com.testsigma.agent.dto.AgentDeviceDTO;13import com.testsigma.agent.exception.DeviceContainerException;14import com.testsigma.agent.exception.TestsigmaException;15import com.testsigma.agent.http.ServerURLBuilder;16import com.testsigma.agent.http.WebAppHttpClient;17import com.testsigma.agent.mappers.MobileDeviceMapper;18import com.fasterxml.jackson.core.type.TypeReference;19import com.testsigma.automator.AutomatorConfig;20import com.testsigma.automator.drivers.DriversUpdateService;21import com.testsigma.automator.entity.Browsers;22import com.testsigma.automator.entity.OsBrowserType;23import com.testsigma.automator.exceptions.AutomatorException;24import com.testsigma.automator.http.HttpResponse;25import lombok.Getter;26import lombok.RequiredArgsConstructor;27import lombok.extern.log4j.Log4j2;28import org.springframework.beans.factory.annotation.Autowired;29import org.springframework.http.HttpStatus;30import org.springframework.stereotype.Component;31import java.util.List;32import java.util.Map;33import java.util.Map.Entry;34import java.util.concurrent.ConcurrentHashMap;35@Log4j236@Component37@RequiredArgsConstructor(onConstructor = @__(@Autowired))38public class DeviceContainer {39 // device map table (key: device uniqueId, value: MobileDevice class)40 @Getter41 private final Map<String, MobileDevice> deviceMap = new ConcurrentHashMap<>();42 @Getter43 private final Map<String, MobileDevice> muxDeviceMap = new ConcurrentHashMap<>();44 private final WebAppHttpClient httpClient;45 private final MobileDeviceMapper mobileDeviceMapper;46 private final AgentConfig agentConfig;47 private final MobileAutomationServerService mobileAutomationServerService;48 public void addDevice(MobileDevice mobileDevice) throws DeviceContainerException {49 try {50 if (mobileDevice == null) {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);167 throw new DeviceContainerException(e.getMessage(), e);168 }169 }170 private AgentDeviceDTO createAgentDevice(AgentDeviceDTO agentDeviceRequest) throws DeviceContainerException {171 try {172 AgentDeviceDTO agentDeviceDTO = null;173 String agentUuid = agentConfig.getUUID();174 String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();175 HttpResponse<AgentDeviceDTO> response =176 httpClient.post(ServerURLBuilder.agentConnectedDevicesURL(agentUuid), agentDeviceRequest,177 new TypeReference<>() {178 }, authHeader);179 if (response.getStatusCode() == HttpStatus.CREATED.value()) {180 agentDeviceDTO = response.getResponseEntity();181 }182 return agentDeviceDTO;183 } catch (Exception e) {184 log.error(e.getMessage(), e);185 throw new DeviceContainerException(e.getMessage(), e);186 }187 }188 private AgentDeviceDTO updateAgentDevice(AgentDeviceDTO agentDeviceRequest) throws DeviceContainerException {189 try {190 AgentDeviceDTO agentDeviceDTO = null;191 String agentUuid = agentConfig.getUUID();192 String authHeader = WebAppHttpClient.BEARER + " " + this.agentConfig.getJwtApiKey();193 HttpResponse<AgentDeviceDTO> response =194 httpClient.put(ServerURLBuilder.agentConnectedDeviceURL(agentUuid, agentDeviceRequest.getUniqueId()),195 agentDeviceRequest,196 new TypeReference<>() {197 }, authHeader);198 if (response.getStatusCode() == HttpStatus.OK.value()) {199 agentDeviceDTO = response.getResponseEntity();200 }201 return agentDeviceDTO;202 } catch (Exception e) {203 log.error(e.getMessage(), e);204 throw new DeviceContainerException(e.getMessage(), e);205 }206 }207}...
Source:DeviceListener.java
...7 *8 */9package com.testsigma.agent.mobile;10import com.testsigma.agent.config.AgentConfig;11import com.testsigma.agent.exception.DeviceContainerException;12import com.testsigma.agent.exception.NativeBridgeException;13import com.testsigma.agent.exception.TestsigmaException;14import com.testsigma.agent.http.ServerURLBuilder;15import com.testsigma.agent.http.WebAppHttpClient;16import com.testsigma.agent.mappers.MobileDeviceMapper;17import com.testsigma.agent.mobile.android.AdbBridge;18import com.testsigma.agent.mobile.android.CommandExecutor;19import com.testsigma.agent.mobile.ios.DeveloperImageService;20import com.testsigma.agent.mobile.ios.IosDeviceService;21import com.testsigma.agent.services.DriverSessionsService;22import lombok.RequiredArgsConstructor;23import lombok.extern.log4j.Log4j2;24import org.springframework.beans.factory.annotation.Autowired;25import org.springframework.stereotype.Component;26@Log4j227@Component28@RequiredArgsConstructor(onConstructor = @__(@Autowired))29public abstract class DeviceListener implements Runnable {30 protected final MobileDeviceMapper mobileDeviceMapper;31 protected final WebAppHttpClient httpClient;32 protected final DeviceContainer deviceContainer;33 protected final AgentConfig agentConfig;34 protected final AdbBridge adbBridge;35 protected final CommandExecutor commandExecutor;36 protected final SessionContainer sessionContainer;37 protected final DriverSessionsService driverSessionsService;38 protected final IosDeviceService iosDeviceService;39 protected final DeveloperImageService developerImageService;40 protected Boolean bridgeInitialized = false;41 protected String listenerType;42 public void run() {43 log.debug("Device listener triggered for " + listenerType + " devices");44 if (!shouldListen()) {45 return;46 }47 try {48 initializeNativeBridge();49 getInitialDeviceList();50 addDeviceListenerCallback();51 } catch (Exception e) {52 log.error(e.getMessage(), e);53 }54 }55 public void addDevice(MobileDevice device) throws DeviceContainerException {56 if (!bridgeInitialized) {57 log.info("Native bridge is not yet initialized");58 return;59 }60 if (!device.getIsOnline()) {61 log.info("Device is offline. Skipping the device from container.");62 return;63 }64 deviceContainer.addDevice(device);65 }66 public void removeDevice(MobileDevice device) throws DeviceContainerException {67 try {68 driverSessionsService.disconnectDeviceSession(device.getUniqueId());69 } catch (Exception e) {70 log.error(e.getMessage(), e);71 }72 deviceContainer.deleteDevice(device.getUniqueId());73 }74 public void updateDevice(MobileDevice device) throws DeviceContainerException {75 this.addDevice(device);76 }77 public abstract void getInitialDeviceList() throws TestsigmaException, DeviceContainerException;78 public abstract void initializeNativeBridge() throws TestsigmaException, NativeBridgeException;79 public abstract void addDeviceListenerCallback() throws TestsigmaException;80 public boolean shouldListen() {81 boolean listen = true;82 if (agentConfig.getRegistered().equals(Boolean.FALSE)) {83 log.debug("Agent is not yet registered...skipping device listener...");84 listen = false;85 }86 return listen;87 }88 public void syncInitialDeviceStatus() {89 try {90 if (shouldListen()) {91 String agentUuid = agentConfig.getUUID();...
Source:DeviceEventCallback.java
...6 * ****************************************************************************7 *8 */9package com.testsigma.agent.mobile.ios;10import com.testsigma.agent.exception.DeviceContainerException;11import com.testsigma.agent.exception.TestsigmaException;12import com.testsigma.agent.mobile.MobileDevice;13import com.testsigma.agent.mobile.ios.libs.LibIMobileDevice;14import com.sun.jna.Pointer;15import lombok.extern.log4j.Log4j2;16@Log4j217public class DeviceEventCallback implements LibIMobileDevice.idevice_event_cb_t {18 private final IosDeviceListener iosDeviceListener;19 DeviceEventCallback(IosDeviceListener iosDeviceListener) {20 this.iosDeviceListener = iosDeviceListener;21 }22 @Override23 public void apply(LibIMobileDevice.IdeviceEvent iDeviceEvent, Pointer user_data) {24 try {25 int event = iDeviceEvent.event;26 String uuid = iDeviceEvent.uuid.getString(0);27 switch (event) {28 case 1:29 onDeviceAdded(uuid);30 break;31 case 2:32 onDeviceRemoved(uuid);33 break;34 case 3:35 onDevicePaired(uuid);36 break;37 default:38 throw new TestsigmaException("event type " + event + "not recognized.");39 }40 } catch (Exception e) {41 log.error(e.getMessage(), e);42 }43 }44 public void onDeviceAdded(String uuid) throws TestsigmaException, DeviceContainerException {45 MobileDevice mobileDevice = iosDeviceListener.getMobileDevice(uuid);46 mobileDevice.setIsOnline(true);47 mobileDevice.setIsEmulator(false);48 iosDeviceListener.addDevice(mobileDevice);49 }50 public void onDeviceRemoved(String uuid) throws TestsigmaException, DeviceContainerException {51 MobileDevice mobileDevice = iosDeviceListener.getMobileDevice(uuid);52 mobileDevice.setIsOnline(false);53 mobileDevice.setIsEmulator(false);54 iosDeviceListener.removeDevice(mobileDevice);55 System.out.println("Removed: " + uuid);56 }57 public void onDevicePaired(String uuid) throws TestsigmaException, DeviceContainerException {58 MobileDevice mobileDevice = iosDeviceListener.getMobileDevice(uuid);59 mobileDevice.setIsOnline(true);60 mobileDevice.setIsEmulator(false);61 iosDeviceListener.updateDevice(mobileDevice);62 System.out.println("Paired: " + uuid);63 }64}...
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2import com.testsigma.agent.devicecontainer.DeviceContainer;3import com.testsigma.agent.devicecontainer.Device;4import com.testsigma.agent.devicecontainer.DeviceContainerManager;5import com.testsigma.agent.exception.DeviceContainerManagerException;6public class 2 {7DeviceContainerManager deviceContainerManager = new DeviceContainerManager();8DeviceContainer deviceContainer = new DeviceContainer();9Device device = new Device();10DeviceContainerException deviceContainerException = new DeviceContainerException();11DeviceContainerManagerException deviceContainerManagerException = new DeviceContainerManagerException();12deviceContainer.setName("deviceContainerName");13deviceContainer.setDescription("deviceContainerDescription");14deviceContainer.setContainerId("deviceContainerId");15deviceContainer.setContainerType("deviceContainerType");16deviceContainer.setStatus("deviceContainerStatus");17deviceContainer.setCapacity("deviceContainerCapacity");18deviceContainer.setOwner("deviceContainerOwner");19deviceContainer.setGroup("deviceContainerGroup");20deviceContainer.setHost("deviceContainerHost");21deviceContainer.setPort("deviceContainerPort");22deviceContainer.setPlatform("deviceContainerPlatform");23deviceContainer.setProtocol("deviceContainerProtocol");24deviceContainer.setUsername("deviceContainerUsername");25deviceContainer.setPassword("deviceContainerPassword");26deviceContainer.setDeviceId("deviceContainerDeviceId");
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2public class 2 {3 public static void main(String[] args) {4 try {5 throw new DeviceContainerException("DeviceContainerException");6 } catch (DeviceContainerException e) {7 System.out.println("Caught DeviceContainerException");8 System.out.println("Message: " + e.getMessage());9 }10 }11}12import com.testsigma.agent.exception.DeviceException;13public class 3 {14 public static void main(String[] args) {15 try {16 throw new DeviceException("DeviceException");17 } catch (DeviceException e) {18 System.out.println("Caught DeviceException");19 System.out.println("Message: " + e.getMessage());20 }21 }22}23import com.testsigma.agent.exception.DeviceNotFoundException;24public class 4 {25 public static void main(String[] args) {26 try {27 throw new DeviceNotFoundException("DeviceNotFoundException");28 } catch (DeviceNotFoundException e) {29 System.out.println("Caught DeviceNotFoundException");30 System.out.println("Message: " + e.getMessage());31 }32 }33}34import com.testsigma.agent.exception.DeviceNotReachableException;35public class 5 {36 public static void main(String[] args) {37 try {38 throw new DeviceNotReachableException("DeviceNotReachableException");39 } catch (DeviceNotReachableException e) {40 System.out.println("Caught DeviceNotReachableException");41 System.out.println("Message: " + e.getMessage());42 }43 }44}45import com.testsigma.agent.exception.DeviceNotUsableException;46public class 6 {47 public static void main(String[] args) {48 try {49 throw new DeviceNotUsableException("DeviceNotUsableException");50 } catch (DeviceNotUsableException e) {51 System.out.println("Caught DeviceNotUsableException");52 System.out.println("Message: " + e.getMessage());53 }54 }55}
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2public class TestDeviceContainerException {3 public static void main(String[] args) {4 try {5 throw new DeviceContainerException("DeviceContainerException");6 } catch (DeviceContainerException e) {7 System.out.println(e.getMessage());8 }9 }10}
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2public class DeviceContainerExceptionExample {3public static void main(String[] args) {4try {5throw new DeviceContainerException("DeviceContainerException message");6} catch (DeviceContainerException e) {7System.out.println(e.getMessage());8}9}10}
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2public class 2 {3public static void main(String args[]) {4try {5throw new DeviceContainerException("DeviceContainerException");6} catch (DeviceContainerException e) {7System.out.println("DeviceContainerException is caught");8}9}10}11public DeviceContainerException()12public DeviceContainerException(String message)13public DeviceContainerException(Throwable cause)14public DeviceContainerException(String message, Throwable cause)15public DeviceContainerException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2import java.io.IOException;3public class 2 {4public static void main(String args[]) throws DeviceContainerException, IOException {5DeviceContainerException e = new DeviceContainerException();6System.out.println(e);7}8}
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2import com.testsigma.agent.exception.DeviceContainerExceptionCode;3public class 2 {4 public static void main(String[] args) {5 try {6 String s = null;7 s.length();8 } catch (Exception e) {9 throw new DeviceContainerException(DeviceContainerExceptionCode.DC_1001, e);10 }11 }12}13DeviceContainerException(DeviceContainerExceptionCode code, String message, Throwable cause)
DeviceContainerException
Using AI Code Generation
1import com.testsigma.agent.exception.DeviceContainerException;2import java.io.IOException;3import java.io.PrintWriter;4import java.io.StringWriter;5import java.util.Map;6import java.util.Set;7import java.util.HashMap;8import com.testsigma.agent.exception.DeviceContainerException;9import com.testsigma.agent.exception.DeviceContainerException;10import com.testsigma.agent.ex
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!!