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

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

Introduction

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

Prototype

public void execute() 

Source Link

Usage

From source file:com.atlassian.selenium.browsers.firefox.DisplayAwareFirefoxChromeLauncher.java

License:Apache License

private void populateCustomProfileDirectory(String profilePath) {
    /*/*  ww  w .j a  v  a 2s .c  om*/
     * The first time we launch Firefox with an empty profile directory, Firefox will launch itself,
     * populate the profile directory, then kill/relaunch itself, so our process handle goes out of
     * date. So, the first time we launch Firefox, we'll start it up at an URL that will immediately
     * shut itself down.
     */
    CommandLine command = prepareCommand(browserInstallation.launcherFilePath(), "-profile", profilePath,
            "-silent");
    command.setDynamicLibraryPath(browserInstallation.libraryPath());
    log.info("Preparing Firefox profile...");
    command.execute();
    try {
        waitForFullProfileToBeCreated(20 * 1000);
    } catch (RuntimeException e) {
        command.destroy();
        throw e;
    }
}

From source file:com.ggasoftware.jdiuitest.web.selenium.driver.WebDriverUtils.java

License:Open Source License

private static void executeCommand(String commandName, String... args) {
    CommandLine cmd = new CommandLine(commandName, args);
    cmd.execute();
}

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

License:Apache License

private File findNodeInCurrentFileSystem() {
    setUpNPMScript();/* w  w w  . jav  a 2  s.  co  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);
    }//from ww  w. jav  a 2  s . c  om
    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());//from  w w  w . ja v a 2 s .  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.CrashTest.java

License:Apache License

@After
public void tearDown() throws Exception {
    super.tearDownAfterClass();

    // Make sure Opera is gone
    CommandLine line = new CommandLine("kill", "`pgrep opera`");
    line.execute();
}

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./* w  w w  .  java 2s  .com*/
 * 
 * @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();
}

From source file:com.opera.core.systems.runner.launcher.OperaLauncherRunnerSettings.java

License:Apache License

/**
 * Makes the launcher executable by chmod'ing the file at given path (GNU/Linux and Mac only).
 *
 * @param launcher the file to make executable
 *//*  w  ww . j a v a 2  s .  c  om*/
private static void makeLauncherExecutable(File launcher) {
    Platform current = Platform.getCurrent();

    if (current.is(Platform.UNIX) || current.is(Platform.MAC)) {
        CommandLine line = new CommandLine("chmod", "u+x", launcher.getAbsolutePath());
        line.execute();
    }
}