Java Code Examples for org.openqa.selenium.logging.LoggingPreferences#enable()
The following examples show how to use
org.openqa.selenium.logging.LoggingPreferences#enable() .
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: JsonOutputTest.java From selenium with Apache License 2.0 | 6 votes |
@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 2
Source File: ChromeDriverClient.java From AndroidRobot with Apache License 2.0 | 6 votes |
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 3
Source File: Edition038_Android_Web_Console.java From appiumpro with Apache License 2.0 | 6 votes |
@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 4
Source File: BotWorker.java From JYTB with GNU General Public License v3.0 | 5 votes |
/** * 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 5
Source File: WebDriverFactory.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@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 6
Source File: ExamplesTest.java From carnotzet with Apache License 2.0 | 5 votes |
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 7
Source File: BytecoderUnitTestRunner.java From Bytecoder with Apache License 2.0 | 5 votes |
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 8
Source File: WebDriverFactory.java From KITE with Apache License 2.0 | 5 votes |
/** * 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 9
Source File: DriverFactory.java From NoraUi with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 10
Source File: JavaDriverLogsTest.java From marathonv5 with Apache License 2.0 | 5 votes |
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 11
Source File: JavaDriverLogsTest.java From marathonv5 with Apache License 2.0 | 5 votes |
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 12
Source File: WebDriverCapabilities.java From QVisual with Apache License 2.0 | 5 votes |
private LoggingPreferences setupLogging() { LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(DRIVER, ALL); logPrefs.enable(PERFORMANCE, ALL); return logPrefs; }
Example 13
Source File: ChromeDriverConfig.java From jmeter-plugins-webdriver with Apache License 2.0 | 5 votes |
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 14
Source File: Edition038_Android_Web_Console.java From appiumpro with Apache License 2.0 | 5 votes |
@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 15
Source File: BotWorker.java From JYTB with GNU General Public License v3.0 | 5 votes |
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 16
Source File: TeasyCaps.java From teasy with MIT License | 4 votes |
void setLoggingPrefs(MutableCapabilities options) { LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); options.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); }
Example 17
Source File: SeleniumWebDriver.java From che with Eclipse Public License 2.0 | 4 votes |
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 18
Source File: WebDriverFactory.java From dropwizard-experiment with MIT License | 4 votes |
private static void withBrowserLogs(DesiredCapabilities caps) { LoggingPreferences logs = new LoggingPreferences(); logs.enable(LogType.BROWSER, Level.ALL); caps.setCapability(CapabilityType.LOGGING_PREFS, logs); }
Example 19
Source File: Browser.java From kurento-java with Apache License 2.0 | 2 votes |
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); } }