类org.openqa.selenium.logging.LoggingPreferences源码实例Demo

下面列出了怎么用org.openqa.selenium.logging.LoggingPreferences的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: JYTB   文件: BotWorker.java
private void setChromeDriver() {
        ChromeOptions options = new ChromeOptions();
        List<String> chromeOptions = new ArrayList<>();
        LoggingPreferences logPrefs = new LoggingPreferences();

        chromeOptions.add(String.format("--proxy-server=%s", proxies.getCurrentProxyModel().getIp()));
        chromeOptions.add(String.format("--user-agent=%s", userAgent.randomUA()));
        chromeOptions.add("--mute-audio");

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.addArguments(chromeOptions);
        options.setBinary(this.driverLocation);
        options.setHeadless(true);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());

        this.webDriver = new ChromeDriver(options);
        Log.WINFO(this.workerName, this.workerColor, "Chrome Driver Set.");
    }
 
@Test
public void testLogging_Hybrid() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("automationName", "UiAutomator2");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("app", APP_ANDROID);
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
    WebDriverWait wait = new WebDriverWait(driver, 10);

    // get to webview screen and enter webview mode
    wait.until(ExpectedConditions.presenceOfElementLocated(hybridScreen)).click();
    wait.until(ExpectedConditions.presenceOfElementLocated(urlInput));
    driver.context(getWebContext(driver));

    // now we can run the same routine as for the browser
    loggingRoutine(driver);
}
 
源代码3 项目: AndroidRobot   文件: ChromeDriverClient.java
public void createDriver(String pkg_name, String sn) {
    	if(this.driver == null) {
	        ChromeOptions chromeOptions = new ChromeOptions();
	        chromeOptions.setExperimentalOption("androidPackage", pkg_name);
	//        chromeOptions.setExperimentalOption("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
	//        chromeOptions.setExperimentalOption("debuggerAddress", "127.0.0.1:9222");
	        chromeOptions.setExperimentalOption("androidUseRunningApp", true);
	        chromeOptions.setExperimentalOption("androidDeviceSerial", sn);
	//        Map<String, Object> chromeOptions = new HashMap<String, Object>();
	//        chromeOptions.put("androidPackage", "com.eg.android.AlipayGphoneRC");
	//        chromeOptions.put("androidActivity", "com.eg.android.AlipayGphone.AlipayLogin");
	        DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	        LoggingPreferences logPrefs = new LoggingPreferences();
	        logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
	        capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
	        capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
//	        capabilities.setCapability(CapabilityType., value);
	        if(ChromeService.getService() != null)
	        	driver = new RobotRemoteWebDriver(ChromeService.getService().getUrl(), capabilities);
    	}
    }
 
源代码4 项目: gatf   文件: SeleniumTest.java
public SeleniumTestResult(WebDriver d, SeleniumTest test, Throwable cause, LoggingPreferences ___lp___) {
    this.status = false;
    this.internalTestRes = test.getSession().internalTestRs;
    /*Logs logs = d.manage().logs();
    for (String s : LOG_TYPES_SET) {
        if(!logs.getAvailableLogTypes().contains(s))continue;
        LogEntries logEntries = logs.get(s);
        if(logEntries!=null && !logEntries.getAll().isEmpty()) {
            this.logs.put(s, new SerializableLogEntries(logEntries.getAll())); 
        }
    }*/
    List<LogEntry> entries = new ArrayList<LogEntry>();
    entries.add(new LogEntry(Level.ALL, new Date().getTime(), cause.getMessage()));
    entries.add(new LogEntry(Level.ALL, new Date().getTime(), ExceptionUtils.getStackTrace(cause)));
    this.logs.put("gatf", new SerializableLogEntries(entries));
}
 
源代码5 项目: selenium   文件: JsonTest.java
@Test
public void shouldParseCapabilitiesWithLoggingPreferences() {
  String caps = String.format(
      "{\"%s\": {" +
      "\"browser\": \"WARNING\"," +
      "\"client\": \"DEBUG\", " +
      "\"driver\": \"ALL\", " +
      "\"server\": \"OFF\"}}",
      CapabilityType.LOGGING_PREFS);

  Capabilities converted = new Json().toType(caps, Capabilities.class);

  LoggingPreferences lp =
      (LoggingPreferences) converted.getCapability(CapabilityType.LOGGING_PREFS);
  assertThat(lp).isNotNull();
  assertThat(lp.getLevel(BROWSER)).isEqualTo(WARNING);
  assertThat(lp.getLevel(CLIENT)).isEqualTo(FINE);
  assertThat(lp.getLevel(DRIVER)).isEqualTo(ALL);
  assertThat(lp.getLevel(SERVER)).isEqualTo(OFF);
}
 
源代码6 项目: selenium   文件: JsonOutputTest.java
@Test
public void convertLoggingPreferencesToJson() {
  LoggingPreferences prefs = new LoggingPreferences();
  prefs.enable(LogType.BROWSER, Level.WARNING);
  prefs.enable(LogType.CLIENT, Level.FINE);
  prefs.enable(LogType.DRIVER, Level.ALL);
  prefs.enable(LogType.SERVER, Level.OFF);

  String json = convert(prefs);

  JsonObject converted = new JsonParser().parse(json).getAsJsonObject();

  assertThat(converted.get(BROWSER).getAsString()).isEqualTo("WARNING");
  assertThat(converted.get(CLIENT).getAsString()).isEqualTo("DEBUG");
  assertThat(converted.get(DRIVER).getAsString()).isEqualTo("ALL");
  assertThat(converted.get(SERVER).getAsString()).isEqualTo("OFF");
}
 
源代码7 项目: JYTB   文件: BotWorker.java
/**
     * Sets the webdriver to FireFox. We set our optimal parameters here
     * to ensure our proxy is set correctly.
     */
    private void setFirefoxDriver() {
        FirefoxOptions options = new FirefoxOptions();
        FirefoxProfile profile = new FirefoxProfile();
        FirefoxBinary binary = new FirefoxBinary(this.driverLocation);
        LoggingPreferences logPrefs = new LoggingPreferences();
        System.setProperty(FirefoxDriver.SystemProperty.DRIVER_USE_MARIONETTE,"true");
        // hide firefox logs from console
        System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE,"/tmp/rust_");

        profile.setPreference("media.volume_scale", "0.0");
        profile.setPreference("general.useragent.override", userAgent.randomUA());
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.http_port", this.proxies.getCurrentProxyModel().getPort());
        profile.setPreference("network.proxy.ssl", this.proxies.getCurrentProxyModel().getIp());
        profile.setPreference("network.proxy.ssl_port", this.proxies.getCurrentProxyModel().getPort());

        logPrefs.enable(LogType.BROWSER, Level.ALL);
        logPrefs.enable(LogType.PERFORMANCE, Level.INFO);
        options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

        options.setProfile(profile);
        options.setHeadless(true);
        options.setBinary(binary);
//        options.setProxy(this.proxies.getCurrentProxy());
        options.setCapability("proxy", this.proxies.getCurrentProxy());
        this.webDriver = new FirefoxDriver(options);

        Log.WINFO(this.workerName, this.workerColor, "Firefox Driver Set");
    }
 
@Test
public void testLogging_Chrome() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setCapability("platformName", "Android");
    capabilities.setCapability("automationName", "UiAutomator2");
    capabilities.setCapability("deviceName", "Android Emulator");
    capabilities.setCapability("browserName", "Chrome");
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    driver = new AndroidDriver<>(new URL("http://localhost:4723/wd/hub"), capabilities);
    loggingRoutine(driver);
}
 
Capabilities createCapabilities() {
      DesiredCapabilities capabilities = new DesiredCapabilities();
      capabilities.setCapability(CapabilityType.PROXY, createProxy());
      LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
      

      if(isAndroidEnabled() || isHeadlessEnabled() || isIncognitoEnabled()) {
          //Map<String, String> chromeOptions = new HashMap<String, String>();
          //chromeOptions.put("androidPackage", "com.android.chrome");
          ChromeOptions chromeOptions = new ChromeOptions();
          if (isAndroidEnabled()) {
              chromeOptions.setExperimentalOption("androidPackage", "com.android.chrome");
          }
          if (isHeadlessEnabled()) {
              chromeOptions.addArguments("--headless");

          }
          if (isIncognitoEnabled()) {
              chromeOptions.addArguments("--incognito");

          }
          capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
      }

      if(isInsecureCertsEnabled()) {
            capabilities.setCapability("acceptInsecureCerts", true);
      }

      return capabilities;
  }
 
源代码10 项目: QVisual   文件: WebDriverCapabilities.java
private LoggingPreferences setupLogging() {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(DRIVER, ALL);
    logPrefs.enable(PERFORMANCE, ALL);

    return logPrefs;
}
 
源代码11 项目: marathonv5   文件: JavaDriverLogsTest.java
public void loggingWorks() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.INFO);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertTrue(all.get(0).getMessage().contains("A new session created. sessionID = "));
}
 
源代码12 项目: marathonv5   文件: JavaDriverLogsTest.java
public void loglevelsAreRespected() {
    LoggingPreferences prefs = new LoggingPreferences();
    prefs.enable(LogType.DRIVER, Level.WARNING);
    DesiredCapabilities caps = JavaDriver.defaultCapabilities();
    caps.setCapability(CapabilityType.LOGGING_PREFS, prefs);
    driver = new JavaDriver(caps, caps);
    LogEntries logEntries = driver.manage().logs().get(LogType.DRIVER);
    List<LogEntry> all = logEntries.getAll();
    AssertJUnit.assertEquals(0, all.size());
}
 
源代码13 项目: NoraUi   文件: DriverFactory.java
/**
 * Sets the logging level of the generated web driver.
 *
 * @param caps
 *            The web driver's MutableCapabilities (FirefoxOptions)
 * @param level
 *            The logging level
 */
private void setLoggingLevel(MutableCapabilities caps) {
    final LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    logPrefs.enable(LogType.CLIENT, Level.OFF);
    logPrefs.enable(LogType.DRIVER, Level.OFF);
    logPrefs.enable(LogType.PERFORMANCE, Level.OFF);
    logPrefs.enable(LogType.PROFILER, Level.OFF);
    logPrefs.enable(LogType.SERVER, Level.OFF);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
}
 
源代码14 项目: Bytecoder   文件: BytecoderUnitTestRunner.java
private static synchronized BrowserWebDriverContainer initializeSeleniumContainer() {

        if (SELENIUMCONTAINER == null) {
            java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);

            final ChromeOptions theOptions = new ChromeOptions().setHeadless(true);
            theOptions.addArguments("--js-flags=experimental-wasm-eh");
            theOptions.addArguments("--enable-experimental-wasm-eh");
            theOptions.addArguments("disable-infobars"); // disabling infobars
            theOptions.addArguments("--disable-dev-shm-usage"); // overcome limited resource problems
            theOptions.addArguments("--no-sandbox"); // Bypass OS security model
            theOptions.setExperimentalOption("useAutomationExtension", false);
            final LoggingPreferences theLoggingPreferences = new LoggingPreferences();
            theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
            theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);
            theOptions.setCapability("goog:loggingPrefs", theLoggingPreferences);

            Testcontainers.exposeHostPorts(getTestWebServerPort());

            SELENIUMCONTAINER = new BrowserWebDriverContainer()
                    .withCapabilities(theOptions)
                    .withRecordingMode(BrowserWebDriverContainer.VncRecordingMode.SKIP, new File("."));
            SELENIUMCONTAINER.start();

            Runtime.getRuntime().addShutdownHook(new Thread(() -> SELENIUMCONTAINER.stop()));
        }
        return SELENIUMCONTAINER;
    }
 
源代码15 项目: carnotzet   文件: ExamplesTest.java
private static WebDriver createBrowserSession() throws MalformedURLException {
	DesiredCapabilities capabilities = DesiredCapabilities.chrome();
	capabilities.setJavascriptEnabled(true);
	LoggingPreferences logPreferences = new LoggingPreferences();
	logPreferences.enable(LogType.BROWSER, Level.ALL);
	capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPreferences);
	return new RemoteWebDriver(
			new URL("http://" + runtime.getContainer("selenium-chrome").getIp() + ":4444/wd/hub"),
			capabilities
	);
}
 
@SuppressWarnings("unchecked")
private static LoggingPreferences getLogPrefs(String value) {
    LoggingPreferences logs = new LoggingPreferences();
    try {
        ObjectMapper mapper = new ObjectMapper();
        HashMap<String, String> prefs = mapper.readValue(value, HashMap.class);
        for (String logType : prefs.keySet()) {
            logs.enable(logType, Level.parse(prefs.get(logType)));
        }
    } catch (IOException ex) {
        LOGGER.log(Level.SEVERE, null, ex);
    }
    return logs;
}
 
源代码17 项目: gatf   文件: SeleniumTest.java
public SeleniumTestResult(WebDriver d, SeleniumTest test, LoggingPreferences ___lp___)
{
    this.status = true;
    this.internalTestRes = test.getSession().internalTestRs;
    /*Logs logs = d.manage().logs();
    for (String s : LOG_TYPES_SET) {
        if(!logs.getAvailableLogTypes().contains(s))continue;
        LogEntries logEntries = logs.get(s);
        if(logEntries!=null && !logEntries.getAll().isEmpty()) {
            this.logs.put(s, new SerializableLogEntries(logEntries.getAll())); 
        }
    }*/
}
 
源代码18 项目: gatf   文件: SeleniumTest.java
protected void newWindow(LoggingPreferences lp) {
    try
    {
        Method m = getClass().getMethod("setupDriver"+getSession().browserName, new Class[]{LoggingPreferences.class});
        if(m!=null) {
            m.invoke(this, new Object[]{lp});
        }
        getSession().__wpos__++;
    }
    catch (Exception e)
    {
        throw new RuntimeException("Invalid browser name specified");
    }
}
 
源代码19 项目: gatf   文件: GatfTestCaseExecutorUtil.java
public ConcSeleniumTest(int index, AcceptanceTestContext context, List<SeleniumTest> tests, List<Object[]> testdata, LoggingPreferences lp, boolean dorep, int runNum, String runPrefix,
        String node) {
    this.index = index;
    this.context = context;
    this.tests = tests;
    this.testdata = testdata;
    this.lp = lp;
    this.runNum = runNum;
    this.runPrefix = runPrefix;
    this.node = node;
    this.dorep = dorep;
}
 
源代码20 项目: selenium   文件: RemoteWebDriver.java
private void init(Capabilities capabilities) {
  capabilities = capabilities == null ? new ImmutableCapabilities() : capabilities;

  logger.addHandler(LoggingHandler.getInstance());

  converter = new JsonToWebElementConverter(this);
  executeMethod = new RemoteExecuteMethod(this);
  keyboard = new RemoteKeyboard(executeMethod);
  mouse = new RemoteMouse(executeMethod);

  ImmutableSet.Builder<String> builder = new ImmutableSet.Builder<>();

  boolean isProfilingEnabled = capabilities.is(CapabilityType.ENABLE_PROFILING_CAPABILITY);
  if (isProfilingEnabled) {
    builder.add(LogType.PROFILER);
  }

  LoggingPreferences mergedLoggingPrefs = new LoggingPreferences();
  mergedLoggingPrefs.addPreferences((LoggingPreferences) capabilities.getCapability(LOGGING_PREFS));

  if (!mergedLoggingPrefs.getEnabledLogTypes().contains(LogType.CLIENT) ||
      mergedLoggingPrefs.getLevel(LogType.CLIENT) != Level.OFF) {
    builder.add(LogType.CLIENT);
  }

  Set<String> logTypesToInclude = builder.build();

  LocalLogs performanceLogger = LocalLogs.getStoringLoggerInstance(logTypesToInclude);
  LocalLogs clientLogs = LocalLogs.getHandlerBasedLoggerInstance(LoggingHandler.getInstance(),
      logTypesToInclude);
  localLogs = LocalLogs.getCombinedLogsHolder(clientLogs, performanceLogger);
  remoteLogs = new RemoteLogs(executeMethod, localLogs);
}
 
源代码21 项目: selenium   文件: DesiredCapabilitiesTest.java
@Test
public void testExtractDebugLogLevelFromCapabilityMap() {
  Map<String, Object> capabilitiesMap
      = ImmutableMap.of(CapabilityType.LOGGING_PREFS, ImmutableMap.of("browser", "DEBUG"));

  DesiredCapabilities caps = new DesiredCapabilities(capabilitiesMap);
  LoggingPreferences prefs =
      (LoggingPreferences) caps.getCapability(CapabilityType.LOGGING_PREFS);
  assertThat(prefs.getLevel("browser")).isSameAs(Level.FINE);
}
 
源代码22 项目: selenium   文件: PerSessionLogHandler.java
/**
 * Configures logging using a logging preferences object.
 *
 * @param prefs The logging preferences object.
 */
// TODO(simons): Of course, this effects all loggers, not just the one for the session.
public void configureLogging(LoggingPreferences prefs) {
  if (prefs == null) {
    return;
  }
  if (prefs.getEnabledLogTypes().contains(LogType.SERVER)) {
    serverLogLevel = prefs.getLevel(LogType.SERVER);
  }
}
 
源代码23 项目: teasy   文件: TeasyCaps.java
void setLoggingPrefs(MutableCapabilities options) {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
}
 
源代码24 项目: KITE   文件: WebDriverFactory.java
/**
   * Build capabilities for client web driver
   *
   * @param client the Client object
   * @return capabilities appium driver
   */
  private static MutableCapabilities buildBrowserCapabilities(Client client) {
    MutableCapabilities capabilities = new MutableCapabilities();
    BrowserSpecs specs = client.getBrowserSpecs();
    if (specs.getVersion() != null) {
      capabilities.setCapability(CapabilityType.VERSION, specs.getVersion());
    }
    if (specs.getPlatform() != null) {
      capabilities.setCapability(CapabilityType.PLATFORM_NAME, specs.getPlatform());
    }

//    if (client.getCapability().getGateway().toString() != null && !"none".equalsIgnoreCase(client.getCapability().getGateway().toString())) {
//      capabilities.setCapability("gateway", client.getCapability().getGateway().toString());
//    }

    // Only consider next code block if this is a client.
    switch (specs.getBrowserName()) {
      case "chrome":
        capabilities.setCapability(ChromeOptions.CAPABILITY, setCommonChromeOptions(client.getCapability(), specs));
        break;
      case "firefox":
        capabilities.merge(setCommonFirefoxOptions(client.getCapability(), specs));
        break;
      case "MicrosoftEdge":
        EdgeOptions MicrosoftEdgeOptions = new EdgeOptions();
        capabilities.setCapability("edgeOptions", MicrosoftEdgeOptions);
        capabilities.setCapability("avoidProxy", true);
        break;
      case "safari":
        SafariOptions options = new SafariOptions();
        options.setUseTechnologyPreview(client.getCapability().isTechnologyPreview());
        capabilities.setCapability(SafariOptions.CAPABILITY, options);
        break;
      default:
        capabilities.setCapability(CapabilityType.BROWSER_NAME, specs.getBrowserName());
        break;
    }
    // Add log preference to webdriver
    // TODO put log preference into config file
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
//    capabilities.setCapability("goog:loggingPrefs", logPrefs);
    // Capabilities for mobile client/app
    if (specs.getPlatform().toString().equalsIgnoreCase("android")
      ||specs.getPlatform().toString().equalsIgnoreCase("ios")) {
      // deviceName:
      // On iOS, this should be one of the valid devices returned by instruments with instruments -s devices.
      // On Android this capability is currently ignored, though it remains required.
      capabilities.setCapability("deviceName", specs.getDeviceName());
      capabilities.setCapability("platformName", specs.getPlatform());
      capabilities.setCapability("platformVersion", specs.getPlatformVersion());
      if (specs.getPlatform().name().equalsIgnoreCase("ios")) {
        capabilities.setCapability("automationName", "XCUITest");
        capabilities.setCapability("autoAcceptAlerts", true);
      } else {
        capabilities.setCapability("autoGrantPermissions", true);
        capabilities.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 300);
      }
      capabilities.setCapability("noReset", true);
    }
    return capabilities;
  }
 
源代码25 项目: che   文件: SeleniumWebDriver.java
private RemoteWebDriver doCreateDriver(URL webDriverUrl) {
  DesiredCapabilities capability;

  switch (browser) {
    case GOOGLE_CHROME:
      LoggingPreferences loggingPreferences = new LoggingPreferences();
      loggingPreferences.enable(LogType.PERFORMANCE, Level.ALL);
      loggingPreferences.enable(LogType.BROWSER, Level.ALL);

      ChromeOptions options = new ChromeOptions();
      options.addArguments("--no-sandbox");
      options.addArguments("--dns-prefetch-disable");
      options.addArguments("--ignore-certificate-errors");

      // set parameters required for automatic download capability
      Map<String, Object> chromePrefs = new HashMap<>();
      chromePrefs.put("download.default_directory", downloadDir);
      chromePrefs.put("download.prompt_for_download", false);
      chromePrefs.put("download.directory_upgrade", true);
      chromePrefs.put("safebrowsing.enabled", true);
      chromePrefs.put("profile.default_content_settings.popups", 0);
      chromePrefs.put("plugins.plugins_disabled", "['Chrome PDF Viewer']");
      options.setExperimentalOption("prefs", chromePrefs);

      capability = DesiredCapabilities.chrome();
      capability.setCapability(ChromeOptions.CAPABILITY, options);
      capability.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
      capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      break;

    default:
      capability = DesiredCapabilities.firefox();
      capability.setCapability("dom.max_script_run_time", 240);
      capability.setCapability("dom.max_chrome_script_run_time", 240);
  }

  RemoteWebDriver driver = new RemoteWebDriver(webDriverUrl, capability);
  if (driver.getErrorHandler().isIncludeServerErrors()
      && driver.getCapabilities().getCapability("message") != null) {
    String errorMessage =
        format(
            "Web driver creation error occurred: %s",
            driver.getCapabilities().getCapability("message"));
    LOG.error(errorMessage);
    throw new RuntimeException(errorMessage);
  }

  driver.manage().window().setSize(new Dimension(1920, 1080));

  return driver;
}
 
源代码26 项目: gatf   文件: GatfTestCaseExecutorUtil.java
public ConcSeleniumTestDT(int index, AcceptanceTestContext context, List<SeleniumTest> tests, LoggingPreferences lp) {
    this.index = index;
    this.context = context;
    this.tests = tests;
    this.lp = lp;
}
 
源代码27 项目: selenium   文件: MutableCapabilities.java
public void setCapability(String key, Object value) {
  Require.nonNull("Capability name", key);

  // We have to special-case some keys and values because of the popular idiom of calling
  // something like "capabilities.setCapability(SafariOptions.CAPABILITY, new SafariOptions());"
  // and this is no longer needed as options are capabilities. There will be a large amount of
  // legacy code that will always try and follow this pattern, however.
  if (OPTION_KEYS.contains(key) && value instanceof Capabilities) {
    merge((Capabilities) value);
    return;
  }

  if (value == null) {
    caps.remove(key);
    return;
  }

  if ("loggingPrefs".equals(key) && value instanceof Map) {
    LoggingPreferences prefs = new LoggingPreferences();
    @SuppressWarnings("unchecked") Map<String, String> prefsMap = (Map<String, String>) value;

    prefsMap.forEach((pKey, pValue) -> prefs.enable(pKey, LogLevelMapping.toLevel(pValue)));
    caps.put(key, prefs);
    return;
  }

  if ("platform".equals(key) && value instanceof String) {
    try {
      caps.put(key, Platform.fromString((String) value));
    } catch (WebDriverException e) {
      caps.put(key, value);
    }
    return;
  }

  if ("unexpectedAlertBehaviour".equals(key)) {
    caps.put("unexpectedAlertBehaviour", value);
    caps.put("unhandledPromptBehavior", value);
    return;
  }

  caps.put(key, value);
}
 
源代码28 项目: dropwizard-experiment   文件: WebDriverFactory.java
private static void withBrowserLogs(DesiredCapabilities caps) {
    LoggingPreferences logs = new LoggingPreferences();
    logs.enable(LogType.BROWSER, Level.ALL);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logs);
}
 
源代码29 项目: kurento-java   文件: Browser.java
public void init() {

    log.debug("Starting browser {}", getId());

    Class<? extends WebDriver> driverClass = browserType.getDriverClass();

    try {
      DesiredCapabilities capabilities = new DesiredCapabilities();

      LoggingPreferences logs = new LoggingPreferences();
      logs.enable(LogType.BROWSER, Level.INFO);
      capabilities.setCapability(CapabilityType.LOGGING_PREFS, logs);

      if (driverClass.equals(FirefoxDriver.class)) {

        createFirefoxBrowser(capabilities);

      } else if (driverClass.equals(ChromeDriver.class)) {

        createChromeBrowser(capabilities);

      } else if (driverClass.equals(InternetExplorerDriver.class)) {

        if (scope == BrowserScope.SAUCELABS) {
          capabilities.setBrowserName(DesiredCapabilities.internetExplorer().getBrowserName());
          capabilities.setCapability("ignoreProtectedModeSettings", true);
          createSaucelabsDriver(capabilities);
        }

      } else if (driverClass.equals(SafariDriver.class)) {

        if (scope == BrowserScope.SAUCELABS) {
          capabilities.setBrowserName(DesiredCapabilities.safari().getBrowserName());
          createSaucelabsDriver(capabilities);
        }
      }

      // Timeouts
      changeTimeout(timeout);

      log.debug("Browser {} started", getId());

      calculateUrl();

      log.debug("Browser {} loading url {}", getId(), url);

      driver.get(url.toString());
      driver.navigate().refresh();

      log.debug("Browser {} initialized", getId());

    } catch (MalformedURLException e) {
      log.error("MalformedURLException in Browser.init", e);
    }

  }
 
源代码30 项目: gatf   文件: SeleniumTest.java
public abstract List<SeleniumTestSession> execute(LoggingPreferences ___lp___) throws Exception; 
 类所在包
 类方法
 同包方法