Exemplo n.º 1
0
 /* Execute networksetup, returning the output */
 protected String runNetworkSetup(String... args) {
   CommandLine command = new CommandLine(findNetworkSetupBin(), args);
   command.execute();
   String output = command.getStdOut();
   if (!command.isSuccessful()) {
     throw new RuntimeException("exec return code " + command.getStdOut() + ": " + output);
   }
   return output;
 }
Exemplo n.º 2
0
  private static String executeCommand(String commandName, String... args) {
    CommandLine cmd = new CommandLine(commandName, args);
    cmd.execute();

    String output = cmd.getStdOut();
    if (!cmd.isSuccessful()) {
      throw new WindowsRegistryException("exec return code " + cmd.getExitCode() + ": " + output);
    }
    return output;
  }
  /**
   * Looks into the Capabilities, the current $PATH and the System Properties for {@link
   * PhantomJSDriverService#PHANTOMJS_EXECUTABLE_PATH_PROPERTY}.
   *
   * <p>NOTE: If the Capability, the $PATH and the System Property are set, the Capability takes
   * priority over the System Property, that in turn takes priority over the $PATH.
   *
   * @param desiredCapabilities Capabilities in which we will look for the path to PhantomJS
   * @param docsLink The link to the PhantomJS documentation page
   * @param downloadLink The link to the PhantomJS download page
   * @return The driver executable as a {@link File} object
   * @throws IllegalStateException If the executable not found or cannot be executed
   */
  @SuppressWarnings("deprecation")
  protected static File findPhantomJS(
      Capabilities desiredCapabilities, String docsLink, String downloadLink) {
    String phantomjspath = null;
    if (desiredCapabilities != null
        && desiredCapabilities.getCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY) != null) {
      phantomjspath =
          (String) desiredCapabilities.getCapability(PHANTOMJS_EXECUTABLE_PATH_PROPERTY);
    } else {
      phantomjspath = CommandLine.find(PHANTOMJS_DEFAULT_EXECUTABLE);
      phantomjspath = System.getProperty(PHANTOMJS_EXECUTABLE_PATH_PROPERTY, phantomjspath);
    }

    checkState(
        phantomjspath != null,
        "The path to the driver executable must be set by the %s capability/system property/PATH variable;"
            + " for more information, see %s. "
            + "The latest version can be downloaded from %s",
        PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
        docsLink,
        downloadLink);

    File phantomjs = new File(phantomjspath);
    checkExecutable(phantomjs);
    return phantomjs;
  }
Exemplo n.º 4
0
 /**
  * Finds reg.exe
  *
  * @return the exact path to reg.exe, or just the string "reg" if it couldn't be found (in which
  *     case you can pass that to exec to try to run it from the path)
  */
 public static String findReg() {
   if (reg != null) {
     return reg;
   }
   File systemRoot = findSystemRoot();
   File regExe = new File(systemRoot, "system32/reg.exe");
   if (regExe.exists()) {
     reg = regExe.getAbsolutePath();
     return reg;
   }
   regExe = new File("c:\\ntreskit\\reg.exe");
   if (regExe.exists()) {
     reg = regExe.getAbsolutePath();
     return reg;
   }
   reg = CommandLine.findExecutable("reg.exe");
   if (reg != null) {
     return reg;
   }
   log.severe("OS Version: " + System.getProperty("os.version"));
   throw new WindowsRegistryException(
       "Couldn't find reg.exe!\n"
           + "Please download it from Microsoft and install it in a standard location.\n"
           + "See here for details: http://wiki.openqa.org/display/SRC/Windows+Registry+Support");
 }
Exemplo n.º 5
0
 private String findNetworkSetupBin() {
   String defaultPath =
       "/System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Support/networksetup";
   File defaultLocation = new File(defaultPath);
   if (defaultLocation.exists()) {
     return defaultLocation.getAbsolutePath();
   }
   String networkSetupBin = CommandLine.find("networksetup");
   if (networkSetupBin != null) {
     return networkSetupBin;
   }
   if (defaultLocation.getParentFile().exists()) {
     String[] files = defaultLocation.getParentFile().list();
     String guess =
         chooseSuitableNetworkSetup(
             System.getProperty("os.version"), System.getProperty("os.arch"), files);
     if (guess != null) {
       File guessedLocation = new File(defaultLocation.getParentFile(), guess);
       log.warning(
           "Couldn't find 'networksetup' in expected location; we're taking "
               + "a guess and using "
               + guessedLocation.getAbsolutePath()
               + " instead.  Please create a symlink called 'networksetup' to make "
               + "this warning go away.");
       return guessedLocation.getAbsolutePath();
     }
   }
   throw new MacNetworkSetupException(
       "networksetup couldn't be found in the path!\n"
           + "Please add the directory containing 'networksetup' to your PATH environment\n"
           + "variable.");
 }
  public String computeLibraryPath(File launcherPath) {
    final String libraryPathEnvironmentVariable;
    final String currentLibraryPath;

    if (WindowsUtils.thisIsWindows()) {
      return null;
    }
    libraryPathEnvironmentVariable = CommandLine.getLibraryPathPropertyName();
    currentLibraryPath = WindowsUtils.loadEnvironment().getProperty(libraryPathEnvironmentVariable);

    return currentLibraryPath + File.pathSeparator + launcherPath.getParent();
  }
  public File asAFile() {
    Optional<String> defaultPath = Optional.fromNullable(CommandLine.find(exeName));

    Optional<String> configuredBinaryPath =
        Optional.fromNullable(environmentVariables.getProperty(exeProperty));
    String exePath = configuredBinaryPath.or(defaultPath).orNull();

    File executableLocation = (exePath != null) ? new File(exePath) : null;

    if (reportMissingBinary) {
      checkForMissingBinaries(executableLocation);
    }
    return executableLocation;
  }
  /**
   * 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();
    }
  }
Exemplo n.º 9
0
  @Parameterized.Parameters
  public static Iterable<String> parameters() {
    ImmutableSortedSet.Builder<String> browsers = ImmutableSortedSet.naturalOrder();

    if (CommandLine.find("chromedriver") != null) {
      browsers.add("*googlechrome");
    }

    if (CommandLine.find("geckodriver") != null) {
      browsers.add("*firefox");
    }

    switch (Platform.getCurrent().family()) {
      case MAC:
        //        browsers.add("*safari");
        break;

      case WINDOWS:
        browsers.add("*MicrosoftEdge");
        break;
    }

    return browsers.build();
  }
Exemplo n.º 10
0
 private String findScutilBin() {
   String defaultPath = "/usr/sbin/scutil";
   File defaultLocation = new File(defaultPath);
   if (defaultLocation.exists()) {
     return defaultLocation.getAbsolutePath();
   }
   String scutilBin = CommandLine.find("scutil");
   if (scutilBin != null) {
     return scutilBin;
   }
   throw new MacNetworkSetupException(
       "scutil couldn't be found in the path!\n"
           + "Please add the directory containing 'scutil' to your PATH environment\n"
           + "variable.");
 }
Exemplo n.º 11
0
 /* Execute scutil and quit, returning the output */
 protected String runScutil(String arg) {
   CommandLine command = new CommandLine(findScutilBin());
   command.setInput(arg + "\nquit\n");
   command.execute();
   String output = command.getStdOut();
   if (!command.isSuccessful()) {
     throw new RuntimeException("exec return code " + command.getExitCode() + ": " + output);
   }
   return output;
 }
  @Override
  public boolean isRunning() {
    lock.lock();
    try {
      if (process == null) {
        return false;
      }

      if (!process.isRunning()) {
        return false;
      }

      try {
        ping(500, TimeUnit.MILLISECONDS);
        return true;
      } catch (UrlChecker.TimeoutException e) {
        return false;
      }
    } finally {
      lock.unlock();
    }
  }
 public BrowserInstallation findFileInPath(String fileName) {
   return retrieveValidInstallationPath(CommandLine.findExecutable(fileName));
 }
  /** @return String logs if the server has been run. null is returned otherwise. */
  public String getStdOut() {
    if (process != null) return process.getStdOut();

    return null;
  }
 private void destroyProcess() {
   if (process.isRunning()) {
     process.destroy();
   }
 }