List of usage examples for org.openqa.selenium.logging Logs get
LogEntries get(String logType);
From source file:com.dhenton9000.selenium.generic.GenericAutomationRepository.java
/** * dump the driver logs//ww w. j a v a 2s .c om */ public void dumpLogs() { Logs logs = driver.manage().logs(); LogEntries logEntries = logs.get(LogType.DRIVER); LOG.debug("dumping click driver errors"); for (LogEntry logEntry : logEntries) { LOG.debug(logEntry.getMessage()); } logEntries = logs.get(LogType.BROWSER); LOG.debug("dumping click browser errors"); for (LogEntry logEntry : logEntries) { LOG.debug(logEntry.getMessage()); } }
From source file:com.google.caja.plugin.WebDriverHandle.java
License:Apache License
public void captureResults(String name) { if (driver == null) { return;/*from w w w . j a va2s . c o m*/ } String dir = TestFlag.CAPTURE_TO.getString(""); if ("".equals(dir)) { return; } if (!dir.endsWith("/")) { dir = dir + "/"; } mkdirs(dir); // Try to capture the final html try { String source = driver.getPageSource(); if (source != null) { saveToFile(dir + name + ".capture.html", source); } } catch (WebDriverException e) { Echo.echo("capture html failed: " + e); } // Try to capture a screenshot if (driver instanceof TakesScreenshot) { TakesScreenshot ss = (TakesScreenshot) driver; try { byte[] bytes = ss.getScreenshotAs(OutputType.BYTES); saveToFile(dir + name + ".capture.png", bytes); } catch (WebDriverException e) { Echo.echo("capture screenshot failed: " + e); } } // Try to capture logs try { Logs logs = driver.manage().logs(); if (logs != null) { if (logs.getAvailableLogTypes().contains(LogType.BROWSER)) { LogEntries entries = logs.get(LogType.BROWSER); if (entries != null) { StringBuilder sb = new StringBuilder(); for (LogEntry e : entries) { sb.append(e.toString() + "\n"); } saveToFile(dir + name + ".capture.log", sb.toString()); } } } } catch (WebDriverException e) { Echo.echo("capture logs failed: " + e); } }
From source file:com.redskyit.scriptDriver.RunTests.java
License:MIT License
private void dumpLog() throws Exception { Logs log = driver.manage().logs(); LogEntries entries = log.get(LogType.BROWSER); // System.out.println(entries); List<LogEntry> list = entries.getAll(); boolean fail = false; for (int i = 0; i < list.size(); i++) { LogEntry e = list.get(i);/*www .ja v a2 s . c o m*/ System.out.println(e); if (e.getLevel().getName().equals("SEVERE") && e.getMessage().indexOf("Uncaught ") != -1 && e.getMessage().indexOf(" Error:") != -1) { System.out.println("*** Uncaught Error ***"); fail = true; } } if (fail) throw new Exception("Unhandled Exception! Check console log for details"); }
From source file:com.technophobia.webdriver.util.WebDriverBrowserLogs.java
License:Open Source License
public void printBrowserLogs() { if (logger.isTraceEnabled()) { final Logs logs = webDriver.manage().logs(); if (logs != null) { final LogEntries logEntries = logs.get(LogType.BROWSER); final StringBuilder buf = new StringBuilder(); buf.append("BROWSER LOGS:\n\n"); for (final LogEntry entry : logEntries) { buf.append(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage() + "\n"); }//from w ww . j a va 2 s .c o m logger.trace(buf.toString()); } } }
From source file:gheckodrivertest.BestJobsFirstPage.java
public static void main(String[] args) // TODO code application logic here { try {/*from w ww . j a v a2 s . c om*/ //System.setProperty("webdriver.gecko.driver", "D:\\Documentatie\\Selenium\\geckodriver\\geckodriver.exe"); System.setProperty("webdriver.gecko.driver", "D:\\gdrwrapper.bat"); System.setProperty("webdriver.gecko.logfile", "D:\\geckodriver.log"); WebDriver driver = new FirefoxDriver(); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); logPrefs.enable(LogType.CLIENT, Level.ALL); logPrefs.enable(LogType.DRIVER, Level.ALL); logPrefs.enable(LogType.SERVER, Level.ALL); logPrefs.enable(LogType.PERFORMANCE, Level.ALL); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); driver.get("http:\\bestjobs.eu"); WebElement btnEnter = driver.findElement(By.xpath("html/body/div[1]/div/div/div/div/div[2]/a/button")); btnEnter.click(); //driver.manage().timeouts().wait(30); System.out.println(driver.getTitle()); /** * <li * class="sign-up-switch amplitude" data - key = "sign_up_email_started" * > <a * href = "/en/register" > Register < / a * > < / li * > */ // WebElement liSignIn = driver.findElement(By.className("sign-up-switch amplitude")); By btnRegister = By.linkText("Register"); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(btnRegister)); WebElement anchSignIn = driver.findElement(By.linkText("Register")); anchSignIn.click(); //driver.manage().timeouts().wait(30); Logs logs = driver.manage().logs(); LogEntries logEntries = logs.get(LogType.BROWSER); for (LogEntry logEntry : logEntries) { System.out.println("browser entry: " + logEntry.getMessage()); } //driver.quit(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:info.magnolia.integrationtests.uitest.AbstractMagnoliaUITest.java
License:Open Source License
protected void captureLogs() { final Logs driverLogs = driver.manage().logs(); // To capture all logs: "driver" seems very verbose, though. Using org.openqa.selenium.logging.LogCombiner could be helpful, but then we lose the "source" of the entries. // final Set<String> availableLogTypes = driverLogs.getAvailableLogTypes(); final LogEntries browserLog = driverLogs.get("browser"); // Use a specific logger category final Logger log = LoggerFactory .getLogger(getClass().getName() + "." + testName.getMethodName() + ".BrowserLog"); log.info("Log entries for {}", testName.getMethodName());// TODO call testName() for (LogEntry logEntry : browserLog) { // just logging it all in info, so as to keep the original timestamp (otherwise we could use logEntry.getLevel()) log.info(logEntry.toString());//w w w. j av a2 s . c om } }
From source file:org.cerberus.service.engine.impl.WebDriverService.java
License:Open Source License
@Override public List<String> getSeleniumLog(Session session) { List<String> result = new ArrayList(); Logs logs = session.getDriver().manage().logs(); for (String logType : logs.getAvailableLogTypes()) { LogEntries logEntries = logs.get(logType); result.add("********************" + logType + "********************\n"); for (LogEntry logEntry : logEntries) { result.add(new Date(logEntry.getTimestamp()) + " : " + logEntry.getLevel() + " : " + logEntry.getMessage() + "\n"); }/*from ww w .ja va 2 s.c o m*/ } return result; }
From source file:org.jboss.arquillian.graphene.context.TestGrapheneProxyHandler.java
License:Open Source License
@Test public void test_webDriver_methods_which_should_not_return_proxy() { IsNotProxyable isNotProxyable = new IsNotProxyable(); // when/*from w w w. j a va 2 s . co m*/ WebDriver driver = Mockito.mock(WebDriver.class, isNotProxyable); Options options = mock(Options.class, isNotProxyable); Navigation navigation = mock(Navigation.class, isNotProxyable); ImeHandler ime = mock(ImeHandler.class, isNotProxyable); Logs logs = mock(Logs.class, isNotProxyable); // then try { driver.toString(); driver.close(); driver.equals(new Object()); driver.get(""); driver.getClass(); driver.getCurrentUrl(); driver.getPageSource(); driver.getTitle(); driver.getWindowHandle(); driver.hashCode(); driver.quit(); driver.toString(); options.addCookie(mock(Cookie.class)); options.deleteAllCookies(); options.deleteCookie(mock(Cookie.class)); options.deleteCookieNamed(""); options.getCookieNamed(""); navigation.back(); navigation.forward(); navigation.to(""); navigation.to(new URL("http://localhost/")); ime.activateEngine(""); ime.deactivate(); ime.getActiveEngine(); ime.isActivated(); logs.get(""); } catch (Exception e) { throw new RuntimeException(e); } assertEquals(Arrays.asList(), isNotProxyable.getViolations()); }
From source file:org.musetest.selenium.plugins.WebdriverCapturePlugin.java
License:Open Source License
private void collectLogs() { if (_logs_collected) return;/* ww w .j a v a2 s. com*/ if (_collect_logs) { try { final Logs logs = getDriver().manage().logs(); for (String type : logs.getAvailableLogTypes()) { StringBuilder builder = new StringBuilder(); for (LogEntry entry : logs.get(type).getAll()) { if (builder.length() > 0) builder.append("\n"); builder.append(entry.toString()); } _data.add(new LogData(type, builder.toString().getBytes())); } } catch (Exception e) { LOG.error("Unable to access WebDriver logs", e); } _logs_collected = true; } }