Search in sources :

Example 6 with TestsigmaException

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);
    }
}
Also used : IosDeviceCommandExecutor(com.testsigma.automator.mobile.ios.IosDeviceCommandExecutor) TestsigmaException(com.testsigma.agent.exception.TestsigmaException) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) TestsigmaException(com.testsigma.agent.exception.TestsigmaException)

Example 7 with TestsigmaException

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());
}
Also used : IosDeviceCommandExecutor(com.testsigma.automator.mobile.ios.IosDeviceCommandExecutor) TestsigmaException(com.testsigma.agent.exception.TestsigmaException)

Example 8 with TestsigmaException

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);
    }
}
Also used : TestsigmaException(com.testsigma.agent.exception.TestsigmaException) AutomatorException(com.testsigma.automator.exceptions.AutomatorException) TestsigmaException(com.testsigma.agent.exception.TestsigmaException)

Example 9 with TestsigmaException

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);
            }
        }
    }
}
Also used : TestsigmaException(com.testsigma.agent.exception.TestsigmaException) ToString(lombok.ToString) Properties(java.util.Properties)

Example 10 with TestsigmaException

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);
            }
        }
    }
}
Also used : TestsigmaException(com.testsigma.agent.exception.TestsigmaException) ToString(lombok.ToString) Properties(java.util.Properties)

Aggregations

TestsigmaException (com.testsigma.agent.exception.TestsigmaException)18 AutomatorException (com.testsigma.automator.exceptions.AutomatorException)10 IosDeviceCommandExecutor (com.testsigma.automator.mobile.ios.IosDeviceCommandExecutor)6 File (java.io.File)4 IosDeveloperImageDTO (com.testsigma.agent.dto.IosDeveloperImageDTO)2 AdbCommandExecutionException (com.testsigma.agent.exception.AdbCommandExecutionException)2 NativeBridgeException (com.testsigma.agent.exception.NativeBridgeException)2 URL (java.net.URL)2 Properties (java.util.Properties)2 ToString (lombok.ToString)2 DriverSessionDTO (com.testsigma.agent.dto.DriverSessionDTO)1 DeviceContainerException (com.testsigma.agent.exception.DeviceContainerException)1 DeviceNotConnectedException (com.testsigma.agent.exception.DeviceNotConnectedException)1 MobileLibraryInstallException (com.testsigma.agent.exception.MobileLibraryInstallException)1 TestDeviceSettings (com.testsigma.automator.entity.TestDeviceSettings)1 IOException (java.io.IOException)1 JSONObject (org.json.JSONObject)1