use of com.testsigma.agent.exception.TestsigmaException in project testsigma by testsigmahq.
the class WdaService method startWdaOnDevice.
public void startWdaOnDevice(MobileDevice device) throws TestsigmaException, AutomatorException {
try {
log.info("Starting WDA on device - " + device.getName());
log.info("Checking for any previously started WDA processes on device - " + device.getName());
IosDeviceCommandExecutor iosDeviceCommandExecutor = new IosDeviceCommandExecutor();
stopWdaOnDevice(device);
device.setWdaExecutorService(Executors.newSingleThreadExecutor());
device.setWdaRelayExecutorService(Executors.newSingleThreadExecutor());
device.getWdaExecutorService().execute(() -> {
try {
Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[] { "-u", device.getUniqueId(), "xctest", "-B", WDA_BUNDLE_ID });
device.setWdaProcess(p);
} catch (Exception e) {
log.info(e.getMessage(), e);
}
});
log.info("Putting the thread to sleep for 10 seconds so as wait for WDA process to start on device - " + device.getName());
Thread.sleep(10000);
checkWDAProcessStatus(device);
device.getWdaRelayExecutorService().execute(() -> {
try {
Process p = iosDeviceCommandExecutor.runDeviceCommand(new String[] { "-u", device.getUniqueId(), "relay", WDA_PORT.toString(), WDA_PORT.toString() });
device.setWdaRelayProcess(p);
} catch (Exception e) {
log.info(e.getMessage(), e);
}
});
log.info("Putting the thread to sleep for 2 seconds so as wait for WDA relay process to start on device - " + device.getName());
Thread.sleep(2000);
checkWDARelayProcessStatus(device);
} catch (Exception e) {
throw new TestsigmaException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.TestsigmaException in project testsigma by testsigmahq.
the class WdaService method checkWDARelayProcessStatus.
private void checkWDARelayProcessStatus(MobileDevice device) throws TestsigmaException, AutomatorException {
IosDeviceCommandExecutor iosDeviceCommandExecutor = new IosDeviceCommandExecutor();
if ((device.getWdaRelayProcess() != null) && device.getWdaRelayProcess().isAlive()) {
log.info("Checked if the WDA relay process is still alive and it seems to be still running on device - " + device.getName());
return;
}
log.info(iosDeviceCommandExecutor.getProcessStreamResponse(device.getWdaRelayProcess()));
throw new TestsigmaException("Unable to start WDA relay process on device - " + device.getName(), "Unable to start WDA relay process on device - " + device.getName());
}
use of com.testsigma.agent.exception.TestsigmaException in project testsigma by testsigmahq.
the class WdaService method stopWdaOnDevice.
public void stopWdaOnDevice(MobileDevice device) throws TestsigmaException {
log.info("Check and stop any running WDA and WDA relay process on device - " + device.getName());
try {
stopWdaThreadIfRunning(device);
stopWdaRelayThreadIfRunning(device);
} catch (Exception e) {
throw new TestsigmaException(e.getMessage(), e);
}
}
use of com.testsigma.agent.exception.TestsigmaException in project testsigma by testsigmahq.
the class AgentConfig method saveConfig.
/**
* @throws TestsigmaException
*/
public void saveConfig() throws TestsigmaException {
FileOutputStream fileOut = null;
touchConfigFile();
try {
String propertiesPath = PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties";
Properties properties = AgentConfig.loadProperties(new FileInputStream(propertiesPath));
if (this.registered != null) {
properties.setProperty("agent.registered", this.registered);
}
if (this.UUID != null) {
properties.setProperty("agent.UUID", this.UUID);
}
if (this.jwtApiKey != null) {
properties.setProperty("agent.jwtApiKey", this.jwtApiKey);
}
fileOut = new FileOutputStream(propertiesPath);
properties.store(fileOut, "Agent configuration");
} catch (IOException e) {
throw new TestsigmaException(e);
} finally {
if (fileOut != null) {
try {
fileOut.flush();
fileOut.close();
} catch (IOException e) {
throw new TestsigmaException("Failed to flush/close file out stream", e);
}
}
}
}
use of com.testsigma.agent.exception.TestsigmaException in project testsigma by testsigmahq.
the class AgentConfig method removeConfig.
/**
* @throws TestsigmaException
*/
public void removeConfig() throws TestsigmaException {
FileOutputStream fileOut = null;
touchConfigFile();
try {
String propertiesPath = PathUtil.getInstance().getConfigPath() + File.separator + "agent.properties";
Properties properties = AgentConfig.loadProperties(new FileInputStream(propertiesPath));
properties.remove("agent.UUID");
properties.setProperty("agent.registered", "false");
properties.remove("agent.jwtApiKey");
fileOut = new FileOutputStream(propertiesPath);
properties.store(fileOut, "Agent configuration");
} catch (IOException e) {
throw new TestsigmaException(e);
} finally {
if (fileOut != null) {
try {
fileOut.flush();
fileOut.close();
} catch (IOException e) {
throw new TestsigmaException("Failed to flush/close file out stream", e);
}
}
}
}
Aggregations