コード例 #1
0
  private static EventFiringWebDriver getChromeInstance() {
    String chromeBinaryPath = "";
    String osName = System.getProperty("os.name").toUpperCase();

    if (osName.contains("WINDOWS")) {
      chromeBinaryPath = "/chromedriver_win32/chromedriver.exe";
    } else if (osName.contains("MAC")) {
      chromeBinaryPath = "/chromedriver_mac32/chromedriver";

      File chromedriver =
          new File(ClassLoader.getSystemResource("ChromeDriver" + chromeBinaryPath).getPath());

      // set application user permissions to 455
      chromedriver.setExecutable(true);
    } else if (osName.contains("LINUX")) {
      chromeBinaryPath = "/chromedriver_linux64/chromedriver";

      File chromedriver =
          new File(ClassLoader.getSystemResource("ChromeDriver" + chromeBinaryPath).getPath());

      // set application user permissions to 455
      chromedriver.setExecutable(true);
    }

    System.setProperty(
        "webdriver.chrome.driver",
        new File(ClassLoader.getSystemResource("ChromeDriver" + chromeBinaryPath).getPath())
            .getPath());

    // TODO change mobile tests to use @UserAgent annotation
    if ("CHROMEMOBILEMERCURY".equals(browserName)) {
      chromeOptions.addArguments("--user-agent=" + userAgentRegistry.getUserAgent("iPhone"));
    }

    //    chromeOptions.addArguments("user-data-dir="
    //        + ClassLoader.getSystemResource("ChromeProfiles/default/").getPath().substring(1));

    if ("true".equals(Configuration.getDisableFlash())) {
      chromeOptions.addArguments("disable-bundled-ppapi-flash");
      chromeOptions.addArguments("process-per-site");
      chromeOptions.addArguments("start-maximized");
    }

    caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    setBrowserLogging(Level.SEVERE);

    ExtHelper.addExtensions(Configuration.getExtensions());

    return new EventFiringWebDriver(new ChromeDriver(caps));
  }
コード例 #2
0
  private static EventFiringWebDriver getFFInstance() {
    // Windows 8 requires to set webdriver.firefox.bin system variable
    // to path where executive file of FF is placed
    if ("WINDOWS 8".equalsIgnoreCase(System.getProperty("os.name"))) {
      System.setProperty(
          "webdriver.firefox.bin",
          "c:"
              + File.separator
              + "Program Files (x86)"
              + File.separator
              + "Mozilla Firefox"
              + File.separator
              + "Firefox.exe");
    }

    // Check if user who is running tests have write access in ~/.mozilla dir and home dir
    if ("LINUX".equals(System.getProperty("os.name").toUpperCase())) {
      File homePath = new File(System.getenv("HOME") + File.separator);
      File mozillaPath = new File(homePath + File.separator + ".mozilla");
      File tmpFile;
      if (mozillaPath.exists()) {
        try {
          tmpFile = File.createTempFile("webdriver", null, mozillaPath);
        } catch (IOException ex) {
          PageObjectLogging.log("Can't create file", ex, false);
          throw new WebDriverException(
              "Can't create file in path: %s".replace("%s", mozillaPath.getAbsolutePath()));
        }
      } else {
        try {
          tmpFile = File.createTempFile("webdriver", null, homePath);
        } catch (IOException ex) {
          PageObjectLogging.log("Can't create file", ex, false);
          throw new WebDriverException(
              "Can't create file in path: %s".replace("%s", homePath.getAbsolutePath()));
        }
      }
      tmpFile.delete();
    }

    firefoxProfile =
        new FirefoxProfile(
            new File(ClassLoader.getSystemResource("FirefoxProfiles/Default").getPath()));

    if (unstablePageLoadStrategy) {
      firefoxProfile.setPreference("webdriver.load.strategy", "unstable");
    }

    if ("true".equals(Configuration.getDisableFlash())) {
      firefoxProfile.setPreference("plugin.state.flash", 0);
    }

    caps.setCapability(FirefoxDriver.PROFILE, firefoxProfile);

    // Adding console logging for FF browser
    setBrowserLogging(Level.SEVERE);

    ExtHelper.addExtensions(Configuration.getExtensions());

    return new EventFiringWebDriver(new FirefoxDriver(caps));
  }