Java Code Examples for org.openqa.selenium.os.CommandLine#executeAsync()

The following examples show how to use org.openqa.selenium.os.CommandLine#executeAsync() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaProfileTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void executeCommand() throws Throwable {
    JavaProfile profile = new JavaProfile(LaunchMode.JAVA_COMMAND_LINE).setMainClass("-version");
    final CommandLine commandLine = profile.getCommandLine();
    AssertJUnit.assertNotNull(commandLine);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    commandLine.copyOutputTo(baos);
    commandLine.executeAsync();
    new Wait("Waiting till the command is complete") {
        @Override
        public boolean until() {
            return !commandLine.isRunning();
        }
    };
    BufferedReader reader = new BufferedReader(new StringReader(new String(baos.toByteArray())));
    String line = reader.readLine();
    while (line != null && !line.contains("java version")) {
        line = reader.readLine();
    }
    AssertJUnit.assertTrue(line.contains("java version"));
}
 
Example 2
Source File: JavaProfileTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void executeWSCommand() throws Throwable {
    if (OS.isFamilyWindows()) {
        throw new SkipException("Test not valid for Windows");
    }
    JavaProfile profile = new JavaProfile(LaunchMode.JAVA_WEBSTART).addWSArgument("-verbose").addVMArgument("-Dx.y.z=hello");
    final CommandLine commandLine = profile.getCommandLine();
    AssertJUnit.assertNotNull(commandLine);
    AssertJUnit.assertTrue(commandLine.toString().contains("-javaagent:"));
    AssertJUnit.assertTrue(commandLine.toString().contains("-verbose"));
    AssertJUnit.assertTrue(commandLine.toString().contains("-Dx.y.z=hello"));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    commandLine.copyOutputTo(baos);
    commandLine.executeAsync();
    new Wait("Waiting till the command is complete") {
        @Override
        public boolean until() {
            return !commandLine.isRunning();
        }
    };
    BufferedReader reader = new BufferedReader(new StringReader(new String(baos.toByteArray())));
    String line = reader.readLine();
    while (line != null && !line.contains("Web Start")) {
        line = reader.readLine();
    }
    AssertJUnit.assertTrue(line.contains("Web Start"));
}
 
Example 3
Source File: AppiumDriverLocalService.java    From java-client with Apache License 2.0 5 votes vote down vote up
/**
 * Starts the defined appium server.
 *
 * @throws AppiumServerHasNotBeenStartedLocallyException If an error occurs while spawning the child process.
 * @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 = "The local appium server has not been started. "
                    + "The given Node.js executable: " + this.nodeJSExec.getAbsolutePath()
                    + " Arguments: " + 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();
    }
}
 
Example 4
Source File: XpiDriverService.java    From selenium with Apache License 2.0 4 votes vote down vote up
@Override
public void start() throws IOException {
  lock.lock();
  try {
    profile.setPreference(PORT_PREFERENCE, port);
    addWebDriverExtension(profile);
    profile.checkForChangesInFrozenPreferences();
    profileDir = profile.layoutOnDisk();

    ImmutableMap.Builder<String, String> envBuilder = new ImmutableMap.Builder<String, String>()
        .putAll(getEnvironment())
        .put("XRE_PROFILE_PATH", profileDir.getAbsolutePath())
        .put("MOZ_NO_REMOTE", "1")
        .put("MOZ_CRASHREPORTER_DISABLE", "1") // Disable Breakpad
        .put("NO_EM_RESTART", "1"); // Prevent the binary from detaching from the console

    if (Platform.getCurrent().is(Platform.LINUX) && profile.shouldLoadNoFocusLib()) {
      modifyLinkLibraryPath(envBuilder, profileDir);
    }
    Map<String, String> env = envBuilder.build();

    List<String> cmdArray = new ArrayList<>(getArgs());
    cmdArray.addAll(binary.getExtraOptions());
    cmdArray.add("-foreground");
    process = new CommandLine(binary.getPath(), Iterables.toArray(cmdArray, String.class));
    process.setEnvironmentVariables(env);
    process.updateDynamicLibraryPath(env.get(CommandLine.getLibraryPathPropertyName()));
    // On Snow Leopard, beware of problems the sqlite library
    if (! (Platform.getCurrent().is(Platform.MAC) && Platform.getCurrent().getMinorVersion() > 5)) {
      String firefoxLibraryPath = System.getProperty(
          FirefoxDriver.SystemProperty.BROWSER_LIBRARY_PATH,
          binary.getFile().getAbsoluteFile().getParentFile().getAbsolutePath());
      process.updateDynamicLibraryPath(firefoxLibraryPath);
    }

    process.copyOutputTo(getOutputStream());

    process.executeAsync();

    waitUntilAvailable();
  } finally {
    lock.unlock();
  }
}