/**
  * 自动根据操作系统的类型执行对应的命令类型。执行完成后以String形式返回执行结果<br>
  * 如命令:"svn info ...",即可以在windows下执行也可以在Linux下执行<br>
  * 使用此命令时只需关注命令内容,而无需再判断操作系统适配<br>
  *
  * @param command
  * @return
  */
 public static String executeLinuxOrWindowsCmd(String command) {
   if (OS.isFamilyWindows()) {
     return executeWindowsCmd(command);
   } else if (OS.isFamilyUnix()) {
     return executeLinuxCmd(command);
   } else {
     return "仅支持Linux和Windows命令";
   }
 }
Пример #2
0
 public static void main(String[] args) throws Exception {
   SeleniumJavaRobot seleniumJavaRobot = new SeleniumJavaRobot();
   String browser;
   seleniumJavaRobot.autoRestart = false;
   if (OS.isFamilyMac()) {
     browser = "safari";
   } else {
     browser = "firefox";
   }
   seleniumJavaRobot.url = "http://localhost:7777/__attester__/slave.html";
   String usageString =
       String.format(
           "Usage: selenium-java-robot [options]\nOptions:\n  --auto-restart\n  --url <url> [default: %s]\n  --browser <browser> [default: %s, accepted values: %s]\n  -DpropertyName=value",
           seleniumJavaRobot.url, browser, BROWSERS_LIST.toString());
   for (int i = 0, l = args.length; i < l; i++) {
     String curParam = args[i];
     if ("--browser".equalsIgnoreCase(curParam) && i + 1 < l) {
       browser = args[i + 1];
       i++;
     } else if ("--url".equalsIgnoreCase(curParam) && i + 1 < l) {
       seleniumJavaRobot.url = args[i + 1];
       i++;
     } else if ("--auto-restart".equalsIgnoreCase(curParam)) {
       seleniumJavaRobot.autoRestart = true;
     } else if ("--version".equalsIgnoreCase(curParam)) {
       System.out.println(Main.class.getPackage().getImplementationVersion());
       return;
     } else if ("--help".equalsIgnoreCase(curParam)) {
       System.out.println(usageString);
       return;
     } else {
       Matcher matcher = SET_SYSTEM_PROPERTY_REGEXP.matcher(curParam);
       if (matcher.matches()) {
         System.setProperty(matcher.group(1), matcher.group(2));
       } else {
         System.err.println("Unknown command line option: " + curParam);
         System.err.println(usageString);
         return;
       }
     }
   }
   seleniumJavaRobot.robotizedBrowserFactory =
       LocalRobotizedBrowserFactory.createRobotizedWebDriverFactory(browser);
   seleniumJavaRobot.start();
   closeOnStreamEnd(seleniumJavaRobot, System.in);
   closeOnProcessEnd(seleniumJavaRobot);
 }