Example usage for org.openqa.selenium.os CommandLine getStdOut

List of usage examples for org.openqa.selenium.os CommandLine getStdOut

Introduction

In this page you can find the example usage for org.openqa.selenium.os CommandLine getStdOut.

Prototype

public String getStdOut() 

Source Link

Usage

From source file:com.mengge.service.local.AppiumServiceBuilder.java

License:Apache License

private File findNodeInCurrentFileSystem() {
    setUpNPMScript();/* w  w  w  .  j  a v a  2 s  .c  o  m*/

    String instancePath;
    CommandLine commandLine;
    try {
        if (Platform.getCurrent().is(Platform.WINDOWS)) {
            commandLine = new CommandLine(CMD_EXE, "/C", "npm root -g");
        } else {
            commandLine = new CommandLine(BASH, "-l", npmScript.getAbsolutePath());
        }
        commandLine.execute();
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }

    instancePath = (commandLine.getStdOut()).trim();
    try {
        File defaultAppiumNode;
        if (StringUtils.isBlank(instancePath)
                || !(defaultAppiumNode = new File(instancePath + File.separator + APPIUM_FOLDER)).exists()) {
            String errorOutput = commandLine.getStdOut();
            throw new InvalidServerInstanceException(ERROR_NODE_NOT_FOUND, new IOException(errorOutput));
        }
        //appium?v1.5
        File result;
        if ((result = new File(defaultAppiumNode, APPIUM_NODE_MASK)).exists()) {
            return result;
        }

        throw new InvalidServerInstanceException(ERROR_NODE_NOT_FOUND, new IOException(
                "?" + APPIUM_NODE_MASK + "," + defaultAppiumNode + ""));
    } finally {
        commandLine.destroy();
    }
}

From source file:com.mengge.service.local.AppiumServiceBuilder.java

License:Apache License

@Override
protected File findDefaultExecutable() {

    String nodeJSExec = System.getProperty(NODE_PATH);
    if (StringUtils.isBlank(nodeJSExec)) {
        nodeJSExec = System.getenv(NODE_PATH);
    }/*  ww  w .j a  v  a 2s  . c o  m*/
    if (!StringUtils.isBlank(nodeJSExec)) {
        File result = new File(nodeJSExec);
        if (result.exists()) {
            return result;
        }
    }

    CommandLine commandLine;
    setUpGetNodeJSExecutableScript();
    try {
        if (Platform.getCurrent().is(Platform.WINDOWS)) {
            commandLine = new CommandLine(NODE + ".exe", getNodeJSExecutable.getAbsolutePath());
        } else {
            commandLine = new CommandLine(NODE, getNodeJSExecutable.getAbsolutePath());
        }
        commandLine.execute();
    } catch (Throwable t) {
        throw new InvalidNodeJSInstance("Node.js!", t);
    }

    String filePath = (commandLine.getStdOut()).trim();

    try {
        if (StringUtils.isBlank(filePath) || !new File(filePath).exists()) {
            String errorOutput = commandLine.getStdOut();
            String errorMessage = "Can't get a path to the default Node.js instance";
            throw new InvalidNodeJSInstance(errorMessage, new IOException(errorOutput));
        }
        return new File(filePath);
    } finally {
        commandLine.destroy();
    }
}

From source file:com.opera.core.systems.common.io.ProcessManager.java

License:Apache License

private static String executeCommand(String commandName, String... args) {
    CommandLine cmd = new CommandLine(commandName, args);
    logger.fine(cmd.toString());// www.ja v a2s .  c o  m

    cmd.execute();
    String output = cmd.getStdOut();

    if (!cmd.isSuccessful()) {
        throw new WebDriverException(String.format("exec return code %d: %s", cmd.getExitCode(), output));
    }

    return output;
}

From source file:com.opera.core.systems.OperaPaths.java

License:Apache License

/**
 * Locates a specified program using the `which` program on UNIX or LINUX platforms. If no program
 * is found, it will return null.//from w  w w. j  ava2  s.  c o  m
 * 
 * @param program the program binary to find
 * @return the absolute path to the binary, or null if program is not found
 */
private static String which(String program) {
    if (!currentPlatform.is(UNIX) && !currentPlatform.is(LINUX)) {
        throw new WebDriverException("Executing program `which` not possible on this platform");
    }

    CommandLine which = new CommandLine("which", program);
    which.execute();
    return which.getStdOut().trim();
}