Best Testsigma code snippet using com.testsigma.agent.exception.TestsigmaException.TestsigmaException
Source:DeveloperImageService.java
1package com.testsigma.agent.mobile.ios;2import com.testsigma.agent.config.AgentConfig;3import com.testsigma.agent.dto.IosDeveloperImageDTO;4import com.testsigma.agent.exception.TestsigmaException;5import com.testsigma.agent.http.ServerURLBuilder;6import com.testsigma.agent.http.WebAppHttpClient;7import com.testsigma.agent.mobile.MobileDevice;8import com.testsigma.agent.utils.PathUtil;9import com.fasterxml.jackson.core.type.TypeReference;10import com.testsigma.automator.exceptions.AutomatorException;11import com.testsigma.automator.http.HttpResponse;12import com.testsigma.automator.mobile.ios.IosDeviceCommandExecutor;13import lombok.RequiredArgsConstructor;14import lombok.extern.log4j.Log4j2;15import org.apache.commons.io.FileUtils;16import org.springframework.beans.factory.annotation.Autowired;17import org.springframework.http.HttpStatus;18import org.springframework.stereotype.Component;19import java.io.File;20import java.net.URL;21import java.nio.file.Paths;22@Log4j223@Component24@RequiredArgsConstructor(onConstructor = @__(@Autowired))25public class DeveloperImageService {26 private final AgentConfig agentConfig;27 private final WebAppHttpClient httpClient;28 public Boolean isDeveloperImageAvailable(String deviceOsVersion) {29 log.info("Checking if developer image directory is available for osVersion - " + deviceOsVersion);30 Boolean isAvailable = Boolean.FALSE;31 File developerImagePath = developerImageDirectory(deviceOsVersion);32 if (developerImagePath.exists()) {33 File imagePath = Paths.get(developerImagePath.getAbsolutePath(), "DeveloperDiskImage.dmg").toFile();34 File imageSigPath = Paths.get(developerImagePath.getAbsolutePath(), "DeveloperDiskImage.dmg.signature").toFile();35 if (imagePath.exists() && imageSigPath.exists())36 isAvailable = Boolean.TRUE;37 }38 log.info("Developer image availability - " + isAvailable + " , osVersion - " + deviceOsVersion);39 return isAvailable;40 }41 public File developerImageDirectory(String deviceOsVersion) {42 return Paths.get(developerImageBaseDirectory(), deviceOsVersion).toFile();43 }44 public String developerImageBaseDirectory() {45 return Paths.get(PathUtil.getInstance().getIosPath(), "DeviceSupport").toString();46 }47 public void mountDeveloperImage(MobileDevice device) throws TestsigmaException, AutomatorException {48 log.info("Trying to mount developer image onto the device");49 if (!isDeveloperImageAvailable(device.getOsVersion())) {50 IosDeveloperImageDTO iosDeveloperImageDTO = fetchDeveloperImageLinks(device.getOsVersion());51 downloadDeveloperImage(device.getOsVersion(), iosDeveloperImageDTO);52 }53 String developerImageDirectory = developerImageDirectory(device.getOsVersion()).getAbsolutePath();54 if (new File(developerImageDirectory).exists()) {55 log.info("Developer image exists at - " + developerImageDirectory);56 } else {57 log.info("Developer image could not be fetched for osVersion - " + device.getOsVersion());58 }59 IosDeviceCommandExecutor iosDeviceCommandExecutor = new IosDeviceCommandExecutor();60 Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[]{"-u", device.getUniqueId(), "developer",61 developerImageDirectory});62 String mountCommandOutput = iosDeviceCommandExecutor.getProcessStreamResponse(p);63 log.info("Response from mount developer image on device - " + mountCommandOutput);64 if (mountCommandOutput.contains("PairingDialogResponsePending")) {65 throw new TestsigmaException("Device is not yet paired. Triggered the trust dialogue. Please accept and try again",66 "Device is not yet paired. Triggered the trust dialogue. Please accept and try again");67 } else if (mountCommandOutput.contains("DeveloperImage already mounted")) {68 log.info("Developer image is already mounted in the device");69 } else if (mountCommandOutput.contains("DeveloperImage mounted successfully")) {70 log.info("Developer image is mounted successfully on the device");71 } else if (mountCommandOutput.contains("DeviceLocked")) {72 throw new TestsigmaException("Device is locked with a passcode. Please unlock and try again",73 "Device is locked with a passcode. Please unlock and try again");74 } else {75 throw new TestsigmaException("Unknown error while mounting developer image to the device",76 "Unknown error while mounting developer image to the device");77 }78 }79 public IosDeveloperImageDTO fetchDeveloperImageLinks(String osVersion) throws TestsigmaException {80 IosDeveloperImageDTO iosDeveloperImageDTO;81 log.info("Fetching developer image URL's from testsigma servers...");82 try {83 String authHeader = WebAppHttpClient.BEARER + " " + agentConfig.getJwtApiKey();84 HttpResponse<IosDeveloperImageDTO> response =85 httpClient86 .get(ServerURLBuilder.deviceDeveloperImageURL(this.agentConfig.getUUID(), osVersion), new TypeReference<>() {87 }, authHeader);88 log.info("Response of developer image fetch request - " + response.getStatusCode());89 if (response.getStatusCode() == HttpStatus.OK.value()) {90 iosDeveloperImageDTO = response.getResponseEntity();91 } else {92 String errorMsg = String.format("Error while fetching developer image - [%s] - [%s] ", response.getStatusCode(),93 response.getStatusMessage());94 throw new TestsigmaException(errorMsg, errorMsg);95 }96 log.info("Response from device developer image urls for os version - " + osVersion + " is - " + iosDeveloperImageDTO);97 } catch (Exception e) {98 throw new TestsigmaException(e.getMessage(), e);99 }100 return iosDeveloperImageDTO;101 }102 public void downloadDeveloperImage(String deviceOsVersion, IosDeveloperImageDTO iosDeveloperImageDTO)103 throws TestsigmaException {104 try {105 log.info("Downloading developer image files for os version - " + deviceOsVersion);106 File deviceDeveloperImageFilePath = Paths.get(developerImageBaseDirectory(), deviceOsVersion,107 "DeveloperDiskImage.dmg").toFile();108 log.info("Copying from " + iosDeveloperImageDTO.getDeveloperImageUrl() + " to " + deviceDeveloperImageFilePath);109 FileUtils.copyURLToFile(new URL(iosDeveloperImageDTO.getDeveloperImageUrl()), deviceDeveloperImageFilePath,110 (60 * 1000), (60 * 1000));111 File deviceDeveloperImageSigFilePath = Paths.get(developerImageBaseDirectory(), deviceOsVersion,112 "DeveloperDiskImage.dmg.signature").toFile();113 log.info("Copying from " + iosDeveloperImageDTO.getDeveloperImageSignatureUrl() + " to " + deviceDeveloperImageSigFilePath);114 FileUtils.copyURLToFile(new URL(iosDeveloperImageDTO.getDeveloperImageSignatureUrl()),115 deviceDeveloperImageSigFilePath, (60 * 1000), (60 * 1000));116 } catch (Exception e) {117 throw new TestsigmaException(e.getMessage(), e);118 }119 }120}...
Source:AgentConfig.java
1package com.testsigma.agent.config;2import com.testsigma.agent.exception.TestsigmaException;3import com.testsigma.agent.utils.PathUtil;4import lombok.Data;5import lombok.ToString;6import lombok.extern.log4j.Log4j2;7import org.apache.commons.io.FileUtils;8import org.apache.commons.lang3.BooleanUtils;9import org.springframework.beans.factory.annotation.Value;10import org.springframework.context.annotation.Configuration;11import org.springframework.context.annotation.PropertySource;12import org.springframework.stereotype.Component;13import java.io.*;14import java.util.Properties;15@Log4j216@Data17@Component18@PropertySource(value = "classpath:agent.properties")19@Configuration20public class AgentConfig {21 @Value("${cloud.url}")22 private String serverUrl;23 @Value("${local.server.url}")24 private String localServerUrl;25 @Value("${local.agent.register}")26 private Boolean localAgentRegister;27 @Value("${agent.version}")28 private String agentVersion;29 private String registered;30 private String UUID;31 @ToString.Exclude32 private String jwtApiKey;33 public AgentConfig() {34 try {35 touchConfigFile();36 String propertiesPath = PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties";37 Properties properties = AgentConfig.loadProperties(new FileInputStream(propertiesPath));38 this.registered = properties.getProperty("agent.registered");39 this.UUID = properties.getProperty("agent.UUID");40 this.jwtApiKey = properties.getProperty("agent.jwtApiKey");41 log.info("Loaded agent config properties - " + this);42 } catch (FileNotFoundException | TestsigmaException e) {43 log.error(e.getMessage(), e);44 }45 }46 public static Properties loadProperties(InputStream is) throws TestsigmaException {47 Properties prop = new Properties();48 try {49 prop.load(is);50 } catch (final IOException e) {51 throw new TestsigmaException("Bad InputStream, failed to load properties from file", e);52 }53 return prop;54 }55 public Boolean getRegistered() {56 return BooleanUtils.toBoolean(this.registered);57 }58 private void touchConfigFile() {59 File configFile = new File(PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties");60 try {61 FileUtils.touch(configFile);62 } catch (IOException e) {63 log.error("Error while creating agent configuration properties file: " + configFile.getAbsolutePath());64 log.error(e.getMessage(), e);65 }66 }67 /**68 * @throws TestsigmaException69 */70 public void saveConfig() throws TestsigmaException {71 FileOutputStream fileOut = null;72 touchConfigFile();73 try {74 String propertiesPath = PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties";75 Properties properties = AgentConfig.loadProperties(new FileInputStream(propertiesPath));76 if (this.registered != null) {77 properties.setProperty("agent.registered", this.registered);78 }79 if (this.UUID != null) {80 properties.setProperty("agent.UUID", this.UUID);81 }82 if (this.jwtApiKey != null) {83 properties.setProperty("agent.jwtApiKey", this.jwtApiKey);84 }85 fileOut = new FileOutputStream(propertiesPath);86 properties.store(fileOut, "Agent configuration");87 } catch (IOException e) {88 throw new TestsigmaException(e);89 } finally {90 if (fileOut != null) {91 try {92 fileOut.flush();93 fileOut.close();94 } catch (IOException e) {95 throw new TestsigmaException("Failed to flush/close file out stream", e);96 }97 }98 }99 }100 /**101 * @throws TestsigmaException102 */103 public void removeConfig() throws TestsigmaException {104 FileOutputStream fileOut = null;105 touchConfigFile();106 try {107 String propertiesPath = PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties";108 Properties properties = AgentConfig.loadProperties(new FileInputStream(propertiesPath));109 properties.remove("agent.UUID");110 properties.setProperty("agent.registered", "false");111 properties.remove("agent.jwtApiKey");112 fileOut = new FileOutputStream(propertiesPath);113 properties.store(fileOut, "Agent configuration");114 } catch (IOException e) {115 throw new TestsigmaException(e);116 } finally {117 if (fileOut != null) {118 try {119 fileOut.flush();120 fileOut.close();121 } catch (IOException e) {122 throw new TestsigmaException("Failed to flush/close file out stream", e);123 }124 }125 }126 }127}...
Source:DeviceEventCallback.java
...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}...
TestsigmaException
Using AI Code Generation
1import com.testsigma.agent.exception.TestsigmaException;2public class TestsigmaExceptionExample {3 public static void main(String[] args) {4 try {5 throw new TestsigmaException("Testsigma Exception");6 } catch (TestsigmaException e) {7 System.out.println(e);8 }9 }10}11 at TestsigmaExceptionExample.main(TestsigmaExceptionExample.java:7)
TestsigmaException
Using AI Code Generation
1import com.testsigma.agent.exception.TestsigmaException;2public class TestsigmaExceptionExample {3 public static void main(String[] args) {4 try {5 throw new TestsigmaException("TestsigmaException");6 } catch (TestsigmaException e) {7 e.printStackTrace();8 }9 }10}11 at TestsigmaExceptionExample.main(2.java:6)12 at com.testsigma.agent.runtime.TestsigmaRuntime.main(TestsigmaRuntime.java:12)
TestsigmaException
Using AI Code Generation
1package com.testsigma.agent.exception;2import java.io.IOException;3public class TestsigmaException {4 public static void main(String[] args) {5 try {6 throw new IOException("Testsigma IOException");7 } catch (IOException e) {8 e.printStackTrace();9 }10 }11}12package com.testsigma.agent.exception;13import java.io.IOException;14public class TestsigmaException {15 public static void main(String[] args) {16 try {17 throw new IOException("Testsigma IOException");18 } catch (IOException e) {19 e.printStackTrace();20 }21 }22}23package com.testsigma.agent.exception;24import java.io.IOException;25public class TestsigmaException {26 public static void main(String[] args) {27 try {28 throw new IOException("Testsigma IOException");29 } catch (IOException e) {30 e.printStackTrace();31 }32 }33}34package com.testsigma.agent.exception;35import java.io.IOException;36public class TestsigmaException {37 public static void main(String[] args) {38 try {39 throw new IOException("Testsigma IOException");40 } catch (IOException e) {41 e.printStackTrace();42 }43 }44}45package com.testsigma.agent.exception;46import java.io.IOException;47public class TestsigmaException {48 public static void main(String[] args) {49 try {50 throw new IOException("Testsigma IOException");51 } catch (IOException e) {52 e.printStackTrace();53 }54 }55}56package com.testsigma.agent.exception;57import java.io.IOException;58public class TestsigmaException {59 public static void main(String[] args) {60 try {61 throw new IOException("Testsigma IOException");62 } catch (IOException e) {63 e.printStackTrace();64 }65 }66}
TestsigmaException
Using AI Code Generation
1import com.testsigma.agent.exception.TestsigmaException;2import org.testng.annotations.Test;3public class TestsigmaExceptionTest {4public void testTestsigmaException() throws TestsigmaException {5TestsigmaException test = new TestsigmaException();6}7}
TestsigmaException
Using AI Code Generation
1import com.testsigma.agent.exception.TestsigmaException;2{3 public static void main(String[] args)4 {5 {6 throw new TestsigmaException("TestsigmaException");7 }8 catch(TestsigmaException e)9 {10 System.out.println(e.getMessage());11 }12 }13}
TestsigmaException
Using AI Code Generation
1package com.testsigma.agent.exception;2public class TestsigmaException extends Exception {3 private static final long serialVersionUID = 1L;4 private String errorMessage;5 private String errorType;6 private String error;7 private String errorDescription;8 private String errorCause;9 private String errorAction;10 private String errorDetails;11 private String errorScreenShot;12 public TestsigmaException(String errorMessage, String errorType, String error, String errorDescription, String errorCause, String errorAction, String errorDetails, String errorScreenShot) {13 super(errorMessage);14 this.errorMessage = errorMessage;15 this.errorType = errorType;16 this.error = error;17 this.errorDescription = errorDescription;18 this.errorCause = errorCause;19 this.errorAction = errorAction;20 this.errorDetails = errorDetails;21 this.errorScreenShot = errorScreenShot;22 }23 public String getErrorMessage() {24 return errorMessage;25 }26 public void setErrorMessage(String errorMessage) {27 this.errorMessage = errorMessage;28 }29 public String getErrorType() {30 return errorType;31 }32 public void setErrorType(String errorType) {33 this.errorType = errorType;34 }35 public String getError() {36 return error;37 }38 public void setError(String error) {39 this.error = error;40 }41 public String getErrorDescription() {42 return errorDescription;43 }44 public void setErrorDescription(String errorDescription) {45 this.errorDescription = errorDescription;46 }47 public String getErrorCause() {48 return errorCause;49 }50 public void setErrorCause(String errorCause) {51 this.errorCause = errorCause;52 }53 public String getErrorAction() {54 return errorAction;55 }56 public void setErrorAction(String errorAction) {57 this.errorAction = errorAction;58 }59 public String getErrorDetails() {60 return errorDetails;61 }62 public void setErrorDetails(String errorDetails) {63 this.errorDetails = errorDetails;64 }65 public String getErrorScreenShot() {66 return errorScreenShot;67 }68 public void setErrorScreenShot(String errorScreenShot) {69 this.errorScreenShot = errorScreenShot;70 }71}72package com.testsigma.agent.exception;73public class TestsigmaException extends Exception {
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!!