Esempio n. 1
0
  private static WebDriver getFirefoxDriver() {

    FirefoxProfile profile = new FirefoxProfile();

    profile.setAcceptUntrustedCertificates(true);

    return new FirefoxDriver(profile);
  }
Esempio n. 2
0
 public void setup() throws InterruptedException {
   FirefoxProfile profile = new FirefoxProfile();
   profile.setAcceptUntrustedCertificates(true);
   profile.setAssumeUntrustedCertificateIssuer(false);
   driver = new FirefoxDriver(profile);
   // baseUrl = "http://www.uat-thetimes.co.uk/";
   driver.manage().deleteAllCookies();
   driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
 }
  public static void main(String[] args) {

    FirefoxProfile profile = new FirefoxProfile();

    profile.setAssumeUntrustedCertificateIssuer(true);

    profile.setAcceptUntrustedCertificates(true);

    FirefoxDriver driver = new FirefoxDriver(profile);
  }
  private static Capabilities getCapabilities(String driverType) {
    DesiredCapabilities result = new DesiredCapabilities();

    switch (driverType) {
      case BrowserType.FIREFOX:
        result = DesiredCapabilities.firefox();
        FirefoxProfile profile =
            (FirefoxProfile) ConfigLoader.config().getProperty("firefox.profile");
        if (profile == null) {
          profile = new FirefoxProfile();
          if (ConfigLoader.config().getBoolean("webdriver.accept.java", true)) {
            profile.setPreference("plugin.state.java", 2);
          }
          if (ConfigLoader.config().getBoolean("webdriver.accept.ssl", true)) {
            profile.setAcceptUntrustedCertificates(true);
            profile.setAssumeUntrustedCertificateIssuer(true);
          }
          if (ConfigLoader.config().getBoolean("webdriver.autodownload", true)) {
            profile.setPreference("browser.download.folderList", 2);
            profile.setPreference("browser.helperApps.alwaysAsk.force", false);
            profile.setPreference("browser.download.manager.showWhenStarting", false);
            profile.setPreference("browser.helperApps.neverAsk.saveToDisk", autoDownloadFiles());
          }
        }
        result.setCapability(FirefoxDriver.PROFILE, profile);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      case BrowserType.IE:
        result = DesiredCapabilities.internetExplorer();
        result.setCapability("ignoreProtectedModeSettings", true);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      case BrowserType.CHROME:
        result = DesiredCapabilities.chrome();
        ChromeOptions chromOptions = new ChromeOptions();
        //
        //	chromOptions.setExperimentalOption("excludeSwitches",Lists.newArrayList("ignore-certificate-errors"));
        chromOptions.addArguments("chrome.switches", "--disable-extensions");
        result.setCapability(ChromeOptions.CAPABILITY, chromOptions);
        result.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        break;
      default:
        result = new DesiredCapabilities(driverType, "", Platform.ANY);
        break;
    }
    String proxy = ConfigLoader.config().getString("webdriver.proxy");
    if (!Strings.isNullOrEmpty(proxy)) {
      Proxy p = new Proxy();
      p.setHttpProxy(proxy).setSslProxy(proxy);
      result.setCapability(CapabilityType.PROXY, p);
      log.info("Using proxy {}", proxy);
    }
    return concatenate(result, capabilities);
  }
  /**
   * private method to load the Firefox Driver
   *
   * @param loadRemote
   */
  private static RemoteWebDriver loadFireFoxDriver(boolean loadRemote) throws Exception {

    log.info("Entering BrowserFactory class loadFireFoxDriver...");
    String loadffProfile = CommonUtils.readFromConfig("loadffProfile");

    RemoteWebDriver remoteDriver = null;

    FirefoxProfile profile = null;

    if ("true".equalsIgnoreCase(loadffProfile)) {
      String profilePath = CommonUtils.readFromConfig("FIREFOXPROFILEDIR");
      File profileDir = new File(profilePath);
      profile = new FirefoxProfile(profileDir);
      profile.setAcceptUntrustedCertificates(false);
    }

    DesiredCapabilities capabilities = DesiredCapabilities.firefox();
    if (loadRemote) {

      log.info("loading firefox driver in remote");
      log.info("Loading  Remote Run URL " + CommonUtils.readFromConfig("RemoteWebAppUrl"));
      URL url = new URL(CommonUtils.readFromConfig("RemoteWebAppUrl"));

      if ("true".equalsIgnoreCase(loadffProfile)) {
        log.info("loading firefox profile in remote");
        capabilities.setCapability(FirefoxDriver.PROFILE, profile);
        log.info("loading firefox profile in remote sucessful");
      }
      remoteDriver = new RemoteWebDriver(url, capabilities);
      log.info("loading firefox driver in remote successful");

    } else {
      if ("true".equalsIgnoreCase(loadffProfile)) {
        log.info("loading firefox driver with profile");

        remoteDriver = new FirefoxDriver(profile);
        log.info("loading firefox driver loadffProfile profile successfully");
      } else {
        log.info("loading firefox driver without profile");
        remoteDriver = new FirefoxDriver();

        log.info("loading firefox driver without profile successfully");
      }
    }

    log.info("Exiting BrowserFactory class loadFireFoxDriver...");

    return remoteDriver;
  }
Esempio n. 6
0
  @Test
  public void canBlockInvalidSslCertificates() {
    FirefoxProfile profile = new FirefoxProfile();
    profile.setAcceptUntrustedCertificates(false);
    String url = GlobalTestEnvironment.get().getAppServer().whereIsSecure("simpleTest.html");

    WebDriver secondDriver = null;
    try {
      secondDriver = newFirefoxDriver(profile);
      secondDriver.get(url);
      String gotTitle = secondDriver.getTitle();
      assertFalse("Hello WebDriver".equals(gotTitle));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Creating driver with untrusted certificates set to false failed.");
    } finally {
      if (secondDriver != null) {
        secondDriver.quit();
      }
    }
  }
 private DesiredCapabilities getBrowserCapabilities(Browser browser) {
   DesiredCapabilities capabilities = new DesiredCapabilities();
   if (browser.getName().equals("internet explorer")) {
     capabilities.setCapability(
         InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
   } else if (Browser.CHROME == browser) {
     ChromeOptions options = new ChromeOptions();
     options.addArguments(
         Arrays.asList("allow-running-insecure-content", "ignore-certificate-errors"));
     options.addArguments("--start-maximized");
     capabilities.setCapability(ChromeOptions.CAPABILITY, options);
   } else {
     FirefoxProfile profile = new FirefoxProfile();
     if (Browser.MOBILE == browser) {
       profile.setPreference(
           "general.useragent.override",
           "Mozilla/5.0 (iPhone; U; CPU iPhone OS 3_0 like Mac OS X; en-us) AppleWebKit/528.18 (KHTML, like Gecko) Version/4.0 Mobile/7A341 Safari/528.16");
       profile.setAcceptUntrustedCertificates(true);
     }
     if (Browser.NOCOOKIE == browser) {
       profile.setPreference("network.cookie.cookieBehavior", 2);
     }
     profile.setEnableNativeEvents(true);
     capabilities.setCapability(FirefoxDriver.PROFILE, profile);
   }
   if (Browser.NOJS == browser) {
     capabilities.setJavascriptEnabled(false);
   } else {
     capabilities.setJavascriptEnabled(true);
   }
   capabilities.setBrowserName(browser.getName());
   if (StringUtils.isNotEmpty(browser.getVersion())) {
     capabilities.setVersion(browser.getVersion());
   }
   capabilities.setPlatform(Platform.ANY);
   capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
   capabilities.setCapability("trustAllSSLCertificates", true);
   return capabilities;
 }
Esempio n. 8
0
  static void populateProfile(FirefoxProfile profile, Capabilities capabilities) {
    if (capabilities == null) {
      return;
    }
    if (capabilities.getCapability(SUPPORTS_WEB_STORAGE) != null) {
      Boolean supportsWebStorage = (Boolean) capabilities.getCapability(SUPPORTS_WEB_STORAGE);
      profile.setPreference("dom.storage.enabled", supportsWebStorage);
    }
    if (capabilities.getCapability(ACCEPT_SSL_CERTS) != null) {
      Boolean acceptCerts = (Boolean) capabilities.getCapability(ACCEPT_SSL_CERTS);
      profile.setAcceptUntrustedCertificates(acceptCerts);
    }
    if (capabilities.getCapability(LOGGING_PREFS) != null) {
      LoggingPreferences logsPrefs = (LoggingPreferences) capabilities.getCapability(LOGGING_PREFS);
      for (String logtype : logsPrefs.getEnabledLogTypes()) {
        profile.setPreference("webdriver.log." + logtype, logsPrefs.getLevel(logtype).intValue());
      }
    }

    if (capabilities.getCapability(HAS_NATIVE_EVENTS) != null) {
      Boolean nativeEventsEnabled = (Boolean) capabilities.getCapability(HAS_NATIVE_EVENTS);
      profile.setEnableNativeEvents(nativeEventsEnabled);
    }
  }