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

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

Introduction

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

Prototype

public CommandLine(String executable, String... args) 

Source Link

Usage

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.AppiumDriverLocalService.java

License:Apache License

/**
 * ?appium?/*from  w  w  w .ja  v a  2s.  c  om*/
 *
 *
 * @throws AppiumServerHasNotBeenStartedLocallyException
 * ??,
 *
 * @see #stop()
 */
public void start() throws AppiumServerHasNotBeenStartedLocallyException {
    lock.lock();
    try {
        if (isRunning()) {
            return;
        }

        try {
            process = new CommandLine(this.nodeJSExec.getCanonicalPath(), nodeJSArgs.toArray(new String[] {}));
            process.setEnvironmentVariables(nodeJSEnvironment);
            process.copyOutputTo(stream);
            process.executeAsync();
            ping(startupTimeout, timeUnit);
        } catch (Throwable e) {
            destroyProcess();
            String msgTxt = "appium??. " + "Node.js: "
                    + this.nodeJSExec.getAbsolutePath() + " ?: " + nodeJSArgs.toString() + " " + "\n";
            if (process != null) {
                String processStream = process.getStdOut();
                if (!StringUtils.isBlank(processStream)) {
                    msgTxt = msgTxt + "Process output: " + processStream + "\n";
                }
            }

            throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt, e);
        }
    } finally {
        lock.unlock();
    }
}

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  w w w  .j  av a2 s  .  co  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());//from   w ww.  j a  va2 s.co 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  w  ww.j  a v a  2 s .  com
}

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 ww  w.ja v a2  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();
}

From source file:com.opera.core.systems.runner.inprocess.OperaInProcessRunner.java

License:Apache License

public void startOpera() throws OperaRunnerException {
    lock.lock();/*w w  w .j a  va2s. c om*/

    try {
        if (isOperaRunning()) {
            return;
        }

        process = new CommandLine(settings.getBinary().getCanonicalPath(),
                Iterables.toArray(settings.arguments().getArgumentsAsStringList(), String.class));
        logger.config(String.format("runner arguments: %s", process));

        // TODO(andreastt): Do we need to forward the environment to CommandLine?
        //process.setEnvironmentVariables(environment);
        process.copyOutputTo(System.out);
        process.executeAsync();

        boolean startedProperly = new ImplicitWait(OperaIntervals.PROCESS_START_TIMEOUT.getValue())
                .until(new Callable<Boolean>() {
                    public Boolean call() {
                        try {
                            process.getExitCode();

                            // Process exited within process execute timeout, meaning it exited immediately
                            return false;
                        } catch (IllegalStateException e) {
                            // getExitCode() throws when process has not yet been executed... patience!
                        }

                        return true;
                    }
                });

        if (!startedProperly) {
            throw new IOException(
                    "Opera exited immediately; possibly incorrect arguments?  Command: " + process);
        }
    } catch (IOException e) {
        throw new OperaRunnerException("Could not start Opera: " + e.getMessage());
    } finally {
        lock.unlock();
    }
}

From source file:com.thoughtworks.selenium.testing.SeleniumTestEnvironment.java

License:Apache License

public SeleniumTestEnvironment(int port, String... extraArgs) {
    try {// w  w w. j a v a 2s.co m
        Path serverJar = new BuckBuild().of("//java/server/test/org/openqa/selenium:server-with-tests").go();

        ArrayList<Object> args = Lists.newArrayList();
        if (Boolean.getBoolean("webdriver.debug")) {
            args.add("-Xdebug");
            args.add("-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005");
        }

        args.add("-jar");
        args.add(serverJar.toAbsolutePath().toString());
        args.add("-port");
        args.add(String.valueOf(port));

        if (Boolean.getBoolean("singlewindow")) {
            args.add("singlewindow");
        }
        if (Boolean.getBoolean("webdriver.debug")) {
            args.add("-browserSideLog");
        }

        args.addAll(Arrays.asList(extraArgs));

        command = new CommandLine("java", args.toArray(new String[args.size()]));
        command.copyOutputTo(System.out);
        command.executeAsync();

        PortProber.pollPort(port);
        seleniumServerUrl = "http://localhost:" + port;

        URL status = new URL(seleniumServerUrl + "/tests");
        new UrlChecker().waitUntilAvailable(60, TimeUnit.SECONDS, status);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }

    //    appServer = new SeleniumAppServer();
    //    appServer.start();
    appServer = new AppServer() {
        @Override
        public String getHostName() {
            return "localhost";
        }

        @Override
        public String getAlternateHostName() {
            throw new UnsupportedOperationException("getAlternateHostName");
        }

        @Override
        public String whereIs(String relativeUrl) {
            try {
                return new URL(seleniumServerUrl + "/" + relativeUrl).toString();
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String whereElseIs(String relativeUrl) {
            throw new UnsupportedOperationException("whereElseIs");
        }

        @Override
        public String whereIsSecure(String relativeUrl) {
            throw new UnsupportedOperationException("whereIsSecure");
        }

        @Override
        public String whereIsWithCredentials(String relativeUrl, String user, String password) {
            throw new UnsupportedOperationException("whereIsWithCredentials");
        }

        @Override
        public void start() {
            // no-op
        }

        @Override
        public void stop() {
            command.destroy();
        }

        @Override
        public void listenOn(int port) {
            throw new UnsupportedOperationException("listenOn");
        }

        @Override
        public void listenSecurelyOn(int port) {
            throw new UnsupportedOperationException("listenSecurelyOn");
        }
    };
}

From source file:io.appium.java_client.service.local.AppiumDriverLocalService.java

License:Apache License

/**
 * Starts the defined appium server/*w w w .  j  a va  2s. c o  m*/
 * @throws AppiumServerHasNotBeenStartedLocallyException If an error occurs while spawning the child process.
 * @see #stop()
 */
public void start() throws AppiumServerHasNotBeenStartedLocallyException {
    lock.lock();
    if (isRunning())
        return;

    try {
        process = new CommandLine(this.nodeJSExec.getCanonicalPath(), nodeJSArgs.toArray(new String[] {}));
        process.setEnvironmentVariables(nodeJSEnvironment);
        process.copyOutputTo(System.err);
        process.executeAsync();
        ping(startupTimeout, timeUnit);
    } catch (Throwable e) {
        destroyProcess();
        String msgTxt = "The local appium server has not been started. " + "The given Node.js executable: "
                + this.nodeJSExec.getAbsolutePath() + " Arguments: " + nodeJSArgs.toString() + " " + "\n";
        String processStream = process.getStdOut();
        if (!StringUtils.isBlank(processStream))
            msgTxt = msgTxt + "Process output: " + processStream + "\n";

        throw new AppiumServerHasNotBeenStartedLocallyException(msgTxt, e);
    } finally {
        lock.unlock();
    }
}