Java 类org.openqa.selenium.logging.LogEntries 实例源码

项目:elpi    文件:WebdriverTestCase.java   
public boolean getTestLogs(String videoFileName) throws Exception {
    HTMLFormatter f = new HTMLFormatter();
    File logFile = new File(OUTPUT_DIR + videoFileName + ".html");
    if (!logFile.exists()) {
        logFile.createNewFile();
    }
    FileOutputStream fos = new FileOutputStream(logFile);
    PrintStream ps = new PrintStream(fos);

    ps.print(f.getHead(null));
    ps.println();

    LogEntries entries =  driver.manage().logs().get(LogType.CLIENT);
    for(LogEntry entry : entries.getAll()) {
        if (entry.getMessage().contains("Executing:") || entry.getMessage().contains("Executed:")) {
            ps.print(f.format(entry));
            ps.println();
        }
    }
    ps.print(f.getTail(null));
    ps.println();
    ps.close();
    return true;
}
项目:xframium-java    文件:SELENIUMCloudActionProvider.java   
@Override
public String getLog( DeviceWebDriver webDriver )
{
    try
       {
           LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER );
           if ( logEntries != null )
           {
               StringBuilder logBuilder = new StringBuilder();
               for ( LogEntry logEntry : logEntries )
                   logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" );

               logBuilder.toString();
           }
           return null;
       }
       catch ( Exception e )
       {
           log.info( "Could not generate device logs" );
           return null;
       }

}
项目:xframium-java    文件:SAUCELABSCloudActionProvider.java   
@Override
public String getLog( DeviceWebDriver webDriver )
{
    try
    {
        LogEntries logEntries = webDriver.manage().logs().get( LogType.BROWSER );
        if ( logEntries != null )
        {
            StringBuilder logBuilder = new StringBuilder();
            for ( LogEntry logEntry : logEntries )
                logBuilder.append( dateFormat.format( new Date( logEntry.getTimestamp() ) ) ).append( ": " ).append( logEntry.getMessage() ).append( "\r\n" );

            logBuilder.toString();
        }
        return null;
    }
    catch ( Exception e )
    {
        log.info( "Could not generate device logs" );
        return null;
    }

}
项目:jwebrobot    文件:ReporterTest.java   
@Test
public void shouldConvertLogEntries() {
    LogEntries logEntries = mock(LogEntries.class);
    when(logs.get(LogType.BROWSER)).thenReturn(logEntries);
    LogEntry logEntry = mock(LogEntry.class);
    when(logEntries.getAll()).thenReturn(asList(logEntry));

    when(logEntry.getLevel()).thenReturn(Level.FINEST);
    when(executorOptions.getBrowserLogLevel()).thenReturn(website.automate.waml.report.io.model.LogEntry.LogLevel.DEBUG);

    reporter.processLogEntries(context, actionReport);

    verify(logEntries).getAll();

    verify(actionReport).setLogEntries(logEntryListCaptor.capture());
    List<website.automate.waml.report.io.model.LogEntry> logEntryList = logEntryListCaptor.getValue();
    assertThat(logEntryList, hasSize(1));
}
项目:seleniumtestsframework    文件:CustomEventListener.java   
private void logErrors(String url, LogEntries logEntries) {
    if (logEntries.getAll().size() == 0) {
        TestLogging.log("********* No Severe Error on Browser Console *********", true);
    } else {
        for (LogEntry logEntry : logEntries) {
            if (logEntry.getLevel().equals(Level.SEVERE)) {
                TestLogging.log("URL: "+url);
                TestLogging.logWebStep("Time stamp: " + logEntry.getTimestamp() + ", " +
                        "Log level: " + logEntry
                        .getLevel() + ", Log message: " + logEntry.getMessage(), true);
                isJSErrorFound = true;
            }
        }
        assert !isJSErrorFound;
    }
}
项目:seleniumtestsframework    文件:CustomEventListener.java   
private void logErrors(String event, WebElement element, LogEntries logEntries) {
    if (logEntries.getAll().size() == 0) {
        TestLogging.log("********* No Severe Error on Browser Console *********", true);
    } else {
        for (LogEntry logEntry : logEntries) {
            if (logEntry.getLevel().equals(Level.SEVERE)) {
                TestLogging.log("Sever Console Error on Browser "+event+" clicking " +
                        "element: " +((HtmlElement)element).getBy());
                TestLogging.logWebStep("Time stamp: " + logEntry.getTimestamp() + ", " +
                        "Log level: " + logEntry
                        .getLevel() + ", Log message: " + logEntry.getMessage(), true);
                isJSErrorFound = true;
            }
        }
        assert !isJSErrorFound;
    }
}
项目:grid-refactor-remote-server    文件:DefaultPerSessionLogHandler.java   
/**
 * Fetches and stores available logs from the given session and driver.
 * 
 *  @param sessionId The id of the session.
 *  @param driver The driver to get the logs from.
 *  @throws IOException If there was a problem reading from file.
 */
@Override
public synchronized void fetchAndStoreLogsFromDriver(SessionId sessionId, WebDriver driver) 
    throws IOException {
  if (!perSessionDriverEntries.containsKey(sessionId)) {
    perSessionDriverEntries.put(sessionId, Maps.<String, LogEntries>newHashMap());
  }
  Map<String, LogEntries> typeToEntriesMap = perSessionDriverEntries.get(sessionId);
  if (storeLogsOnSessionQuit) {
    typeToEntriesMap.put(LogType.SERVER, getSessionLog(sessionId));
    Set<String> logTypeSet = driver.manage().logs().getAvailableLogTypes();
    for (String logType : logTypeSet) {
      typeToEntriesMap.put(logType, driver.manage().logs().get(logType));
    }
  }
}
项目:crowdsource    文件:BrowserLogFetchHook.java   
@cucumber.api.java.After
public void after(Scenario result) {
    if (webDriverProvider.hasActiveWebDriver()) {
        WebDriver webDriver = webDriverProvider.provideDriver();

        if (result != null) {
            LogEntries logs = webDriver.manage().logs().get(LogType.BROWSER);

            if (LOG.isInfoEnabled()) {
                String logOutput = logs.getAll().stream()
                        .map(LogEntry::toString)
                        .collect(joining("\n"));

                LOG.info("Browser console.log output: {}", "\n" + logOutput);
            }
        }
    }
}
项目:ScriptDriver    文件:RunTests.java   
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);
        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");        
}
项目:gatf    文件:SeleniumTest.java   
public SeleniumTestResult(WebDriver d, SeleniumTest test, Throwable cause, LoggingPreferences ___lp___) {
    this.status = false;
    this.internalTestRes = test.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));
}
项目:seletest    文件:TestListener.java   
@Override
public void onTestFailure(ITestResult testResult) {
    log.debug("Test "+ testResult.getName()+" failed!!!");
    try {
        log.debug("Collect client logs after failure of the @Test {}", testResult.getMethod());
        LogEntries entries=ApplicationContextProvider.getApplicationContext().getBean(StrategyFactory.class).getControllerStrategy(SessionContext.getSession().getControllerStrategy()).logs(LogType.BROWSER);
        StringBuilder list=new StringBuilder();
        for (LogEntry entry : entries) {
            list.append(entry.getMessage()).append("\n");
        }
        ApplicationContextProvider.getApplicationContext().getBean(FilesUtils.class).createHTML("Logs for Client", list.toString(), "Logs_"+testResult.getName());
        Reporter.log("<p class=\"testOutput\"><a href=\"Logs/Logs_"+testResult.getName()+".html\">Client Logs<a/></p>");
    }
    catch(Exception ex) {
        log.error("Exception trying to collect client logs: {}",ex.getMessage());
    }

    if(System.getProperty("email")!=null) {
        log.debug("Send email notification with failure of the @Test to address {} ", System.getProperty("email"));
        ApplicationContextProvider.getApplicationContext().getBean(MailUtils.class).sendMail(System.getProperty("email"),"Failure on test: "+testResult.getName(),"Exception occured is: "+testResult.getThrowable().getMessage());
    }
}
项目: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.assertEquals(2, all.size());
    AssertJUnit.assertTrue(all.get(0).getMessage().contains("A new session created. sessionID = "));
}
项目: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());
}
项目:ja11y    文件:AccessibilitySniffer.java   
public void runCodeSniffer() throws IOException {
    String jquery_content = Jsoup.connect("http://squizlabs.github.io/HTML_CodeSniffer/build/HTMLCS.js").ignoreContentType(true).execute().body();
    js.executeScript(jquery_content);
    js.executeScript("window.HTMLCS_RUNNER.run('WCAG2AA');");
    LogEntries logs = driver.manage().logs().get("browser");
    for (LogEntry entry : logs) {
        System.out.println(new Date(entry.getTimestamp()) + " " + entry.getLevel() + " " + entry.getMessage());
    }
}
项目:jlineup    文件:Browser.java   
private void checkForErrors(WebDriver driver) throws Exception {
    LogEntries logEntries;
    try {
        logEntries = driver.manage().logs().get(LogType.BROWSER);
    } catch (UnsupportedCommandException e) {
        logEntries = null;
    }
    if (logEntries != null) {
        if (!logEntries.getAll().isEmpty() && logEntries.getAll().get(0).getLevel() == Level.SEVERE) {
            shutdownCalled.getAndSet(true);
            throw new WebDriverException(logEntries.getAll().get(0).getMessage());
        }
    }
}
项目:grid-refactor-remote-server    文件:DefaultPerSessionLogHandler.java   
/**
 * New handler keeping track of log records per session.
 *
 * @param capacity     The capacity
 * @param minimumLevel Only keep track of records whose level is equal or greater than
 *                     minimumLevel.
 * @param formatter    Formatter to use when retrieving log messages.
 * @param captureLogsOnQuit Whether to enable log capture on quit.
 */
public DefaultPerSessionLogHandler(int capacity, Level minimumLevel, Formatter formatter, 
    boolean captureLogsOnQuit) {
  this.capacity = capacity;
  this.formatter = formatter;
  this.storeLogsOnSessionQuit = captureLogsOnQuit;
  this.perSessionRecords = Maps.<SessionId, List<LogRecord>>newHashMap();
  this.perThreadTempRecords = Maps.<ThreadKey, List<LogRecord>>newHashMap();
  this.threadToSessionMap = Maps.<ThreadKey, SessionId>newHashMap();
  this.sessionToThreadMap = Maps.<SessionId, ThreadKey>newHashMap();
  this.logFileRepository = new SessionLogsToFileRepository();
  this.perSessionDriverEntries = Maps.<SessionId, Map<String, LogEntries>>newHashMap();
}
项目:grid-refactor-remote-server    文件:DefaultPerSessionLogHandler.java   
/**
 * Returns the server log for the given session id.
 * 
 * @param sessionId The session id.
 * @return The available server log entries for the session.
 * @throws IOException If there was a problem reading from file.
 */
@Override
public synchronized LogEntries getSessionLog(SessionId sessionId) throws IOException {
  List<LogEntry> entries = Lists.<LogEntry>newLinkedList();
  LogRecord[] records = records(sessionId);
  if (records != null) {
    for (LogRecord record : records) {
      if (record.getLevel().intValue() >= serverLogLevel.intValue())
        entries.add(new LogEntry(record.getLevel(), record.getMillis(), record.getMessage()));
    }
  }
  return new LogEntries(entries);
}
项目:grid-refactor-remote-server    文件:DefaultPerSessionLogHandler.java   
/**
 * Gets all logs for a session.
 * 
 * @param sessionId The id of the session.
 * @return The logs for the session, ordered after log types in a session logs object. 
 */
@Override
public synchronized SessionLogs getAllLogsForSession(SessionId sessionId) {
  SessionLogs sessionLogs = new SessionLogs();
  if (perSessionDriverEntries.containsKey(sessionId)) {
    Map<String, LogEntries> typeToEntriesMap = perSessionDriverEntries.get(sessionId);
    for (String logType : typeToEntriesMap.keySet()) {
      sessionLogs.addLog(logType, typeToEntriesMap.get(logType));
    }
    perSessionDriverEntries.remove(sessionId);
  }
  return sessionLogs;
}
项目:grid-refactor-remote-server    文件:GetLogHandler.java   
@Override
public LogEntries call() throws Exception {
  if (LogType.SERVER.equals(type)) {
    return LoggingManager.perSessionLogHandler().getSessionLog(getSessionId());
  } else {
    return getDriver().manage().logs().get(type);
  }
}
项目:gatf    文件:SeleniumTest.java   
public SeleniumTestResult(WebDriver d, SeleniumTest test, LoggingPreferences ___lp___)
{
    this.status = true;
    this.internalTestRes = test.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())); 
        }
    }
}
项目:gatf    文件:SeleniumException.java   
public SeleniumException(WebDriver d, Throwable cause, SeleniumTest test) {
    super(cause);
    Map<String, SerializableLogEntries> lg = new HashMap<String, SerializableLogEntries>();
       Logs logs = d.manage().logs();
       for (String s : d.manage().logs().getAvailableLogTypes()) {
           LogEntries logEntries = logs.get(s);
           if(!logEntries.getAll().isEmpty()) {
               lg.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)));
       lg.put("gatf", new SerializableLogEntries(entries));
}
项目:testng_samples    文件:MyTest.java   
@AfterMethod
public void tearDown(Method m) throws IOException {
  LogEntries logEntries = driver.manage().logs().get("browser");
  File driverLog = new File(m.getName() + ".log");
  FileWriter out = new FileWriter(driverLog);
  for (LogEntry logEntry : logEntries.getAll()) {
    out.write(logEntry.toString() + "\n");
  }
  out.close();
}
项目:seleniumcapsules    文件:LogsTest.java   
@Test
public void getAvailableLogTypes() {
    WebDriver driver = new ChromeDriver();
    driver.get("http://ticketfly.com");

    Options manage = driver.manage();
    Logs logs = manage.logs();
    Set<String> availableLogTypes = logs.getAvailableLogTypes();
    System.out.println(availableLogTypes);
    availableLogTypes.stream().forEach(logType -> {
        System.out.println("logType=" + logType);
        LogEntries logEntries = logs.get(logType);
        List<LogEntry> all = logEntries.getAll();
        all.forEach(entry -> {
            System.out.println(entry.getLevel());
            System.out.println(entry.getMessage());
            System.out.println(entry.getTimestamp());
            System.out.println(entry.toMap());
            System.out.println(entry);
        });

        List<LogEntry> filter = logEntries.filter(Level.SEVERE);
        System.out.println("After filtering");
        filter.forEach(System.out::println);
        System.out.println("Done");
    });

}
项目:cerberus-source    文件:WebDriverService.java   
@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");
        }
    }

    return result;
}
项目:seleniumtestsframework    文件:CustomEventListener.java   
private LogEntries getBrowserLogs(WebDriver webDriver) {
    return webDriver.manage().logs().get(LogType.BROWSER);
}
项目:grid-refactor-remote-server    文件:NoOpSessionLogHandler.java   
@Override
public LogEntries getSessionLog(SessionId sessionId) {
  return new LogEntries(ImmutableList.<LogEntry>of());
}
项目:mineraloil-selenium    文件:Driver.java   
public LogEntries getConsoleLog() {
    log.info("Console Log output: ");
    executeScript("console.log('Logging Errors');");
    return getDriver().manage().logs().get(LogType.BROWSER);
}
项目:seletest    文件:WebDriverController.java   
/*************************************************************
 ************************LOGS SECTION*********************
 *************************************************************
 */
@Override
@RetryFailure(retryCount=3)
public LogEntries logs(String logtype) {
    return webDriver().manage().logs().get(logtype);
}
项目:seletest    文件:SeleniumController.java   
@Deprecated
@Override
public LogEntries logs(String logtype) {
    throw new RuntimeException(String.format("Method %s not implemented yet",new Object(){}.getClass().getEnclosingMethod().getName()));
}
项目:minium    文件:DelegatorWebDriver.java   
@Override
public LogEntries get(String logType) {
    ensureWebDriver();
    return delegate.manage().logs().get(logType);
}
项目:seletest    文件:WebController.java   
/**
 * Get logs (client,server,performance....etc.)
 * @param logtype
 * @return LogEntries the log entries
 */
LogEntries logs(String logtype);
项目:grid-refactor-remote-server    文件:PerSessionLogHandler.java   
public abstract LogEntries getSessionLog(SessionId sessionId) throws IOException;