org.openqa.selenium.logging.LoggingPreferences Java Examples

The following examples show how to use org.openqa.selenium.logging.LoggingPreferences. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Edition038_Android_Web_Console.java    From appiumpro with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: JsonOutputTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@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");
}
 
Example #3
Source File: JsonTest.java    From selenium with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #4
Source File: SeleniumTest.java    From gatf with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #5
Source File: ChromeDriverClient.java    From AndroidRobot with Apache License 2.0 6 votes vote down vote up
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);
    	}
    }
 
Example #6
Source File: BotWorker.java    From JYTB with GNU General Public License v3.0 5 votes vote down vote up
/**
     * 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");
    }
 
Example #7
Source File: PerSessionLogHandler.java    From selenium with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
  }
}
 
Example #8
Source File: DesiredCapabilitiesTest.java    From selenium with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #9
Source File: RemoteWebDriver.java    From selenium with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #10
Source File: GatfTestCaseExecutorUtil.java    From gatf with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #11
Source File: SeleniumTest.java    From gatf with Apache License 2.0 5 votes vote down vote up
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");
    }
}
 
Example #12
Source File: SeleniumTest.java    From gatf with Apache License 2.0 5 votes vote down vote up
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())); 
        }
    }*/
}
 
Example #13
Source File: WebDriverFactory.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #14
Source File: ExamplesTest.java    From carnotzet with Apache License 2.0 5 votes vote down vote up
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
	);
}
 
Example #15
Source File: BytecoderUnitTestRunner.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
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;
    }
 
Example #16
Source File: BotWorker.java    From JYTB with GNU General Public License v3.0 5 votes vote down vote up
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.");
    }
 
Example #17
Source File: Edition038_Android_Web_Console.java    From appiumpro with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source File: WebDriverFactory.java    From KITE with Apache License 2.0 5 votes vote down vote up
/**
   * 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;
  }
 
Example #19
Source File: DriverFactory.java    From NoraUi with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #20
Source File: JavaDriverLogsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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());
}
 
Example #21
Source File: JavaDriverLogsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 = "));
}
 
Example #22
Source File: ChromeDriverConfig.java    From jmeter-plugins-webdriver with Apache License 2.0 5 votes vote down vote up
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;
  }
 
Example #23
Source File: WebDriverCapabilities.java    From QVisual with Apache License 2.0 5 votes vote down vote up
private LoggingPreferences setupLogging() {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(DRIVER, ALL);
    logPrefs.enable(PERFORMANCE, ALL);

    return logPrefs;
}
 
Example #24
Source File: WebDriverFactory.java    From dropwizard-experiment with MIT License 4 votes vote down vote up
private static void withBrowserLogs(DesiredCapabilities caps) {
    LoggingPreferences logs = new LoggingPreferences();
    logs.enable(LogType.BROWSER, Level.ALL);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logs);
}
 
Example #25
Source File: TeasyCaps.java    From teasy with MIT License 4 votes vote down vote up
void setLoggingPrefs(MutableCapabilities options) {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
}
 
Example #26
Source File: MutableCapabilities.java    From selenium with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example #27
Source File: GatfTestCaseExecutorUtil.java    From gatf with Apache License 2.0 4 votes vote down vote up
public ConcSeleniumTestDT(int index, AcceptanceTestContext context, List<SeleniumTest> tests, LoggingPreferences lp) {
    this.index = index;
    this.context = context;
    this.tests = tests;
    this.lp = lp;
}
 
Example #28
Source File: SeleniumWebDriver.java    From che with Eclipse Public License 2.0 4 votes vote down vote up
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;
}
 
Example #29
Source File: Browser.java    From kurento-java with Apache License 2.0 2 votes vote down vote up
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);
    }

  }
 
Example #30
Source File: SeleniumTest.java    From gatf with Apache License 2.0 votes vote down vote up
public abstract List<SeleniumTestSession> execute(LoggingPreferences ___lp___) throws Exception;