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

项目:spa-perf    文件:SPAPerfChromeDriver.java   
private static DesiredCapabilities getPerformanceLoggingCapabilities() {
    DesiredCapabilities caps = DesiredCapabilities.chrome();

    // Enable performance logging
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.PERFORMANCE, Level.ALL);
    caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);

    // Enable timeline tracing
    Map<String, Object> chromeOptions = new HashMap<String, Object>();
    Map<String, String> perfLoggingPrefs = new HashMap<String, String>();
    // Tracing categories, please note NO SPACE NEEDED after the commas
    perfLoggingPrefs.put("traceCategories", "blink.console,disabled-by-default-devtools.timeline");
    chromeOptions.put("perfLoggingPrefs", perfLoggingPrefs);
    //chromeOptions.put("debuggerAddress", "127.0.0.1:10134");
    caps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    return caps;
}
项目: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;
}
项目:marathonv5    文件:DragAndDropTest.java   
public void dndWithMove() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    driver.clearlogs(LogType.DRIVER);
    System.err.println("About to sleep");
    new Actions(driver).dragAndDrop(listitem1, listitem5).perform();
    waitTillDropCompletes(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
项目:marathonv5    文件:DragAndDropTest.java   
public void dndWithCopy() throws Throwable {
    DesiredCapabilities caps = new DesiredCapabilities();
    // caps.setCapability("nativeEvents", true);
    driver = new JavaDriver(caps, caps);
    WebElement list = driver.findElement(By.cssSelector("list"));
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 4\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
    WebElement listitem1 = driver.findElement(By.cssSelector("list::nth-item(1)"));
    WebElement listitem5 = driver.findElement(By.cssSelector("list::nth-item(5)"));
    listitem1.click();
    driver.clearlogs(LogType.DRIVER);
    Keys copyKey = Keys.ALT;
    if (Platform.isWindows()) {
        copyKey = Keys.CONTROL;
    }
    new Actions(driver).keyDown(copyKey).dragAndDrop(listitem1, listitem5).keyUp(copyKey).perform();
    waitTillDropCompletes(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list);
    assertEquals(
            "[[\"List Item 0\",\"List Item 1\",\"List Item 2\",\"List Item 3\",\"List Item 0(1)\",\"List Item 5\",\"List Item 6\",\"List Item 7\",\"List Item 8\",\"List Item 9\"]]",
            list.getAttribute("content"));
}
项目: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    文件:Reporter.java   
void processLogEntries(ScenarioExecutionContext context, ActionReport actionReport) {
    try {
        List<org.openqa.selenium.logging.LogEntry> logEntries = context.getDriver().manage().logs().get(LogType.BROWSER).getAll();
        ExecutorOptions options = context.getGlobalContext().getOptions();

        // TODO extract mapper
        List<LogEntry> convertedLogEntries = new ArrayList<>();

        for (org.openqa.selenium.logging.LogEntry logEntry : logEntries) {
            LogLevel actualLevel = convertLogLevel(logEntry.getLevel());

            if (LogEntry.isIncluded(options.getBrowserLogLevel(), actualLevel)) {
                convertedLogEntries.add(new LogEntry(
                    actualLevel, new Date(logEntry.getTimestamp()), logEntry.getMessage()));
            }
        }

        actionReport.setLogEntries(convertedLogEntries);
    } catch (UnsupportedCommandException e) {
        // TODO set flag on the report: https://github.com/automate-website/waml-io/issues/2
        LOG.warn("Current WebDriver does not support browser logging!");
    }
}
项目: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));
}
项目:spa-perf    文件:SampleTestScript.java   
public static void TestGoogleSearch() throws MalformedURLException {
    //google.com
    SPAPerfChromeDriver driver = new SPAPerfChromeDriver();

    driver.get("https://news.google.com/");

    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Selenium Conference");
    element.sendKeys(Keys.ENTER);

    ConsolePrinter printer = new ConsolePrinter();

    printer.printLogToConsole(driver, LogType.PERFORMANCE);

    //driver.detach();
    driver.close();
}
项目:spa-perf    文件:SPAPerfChromeDriver.java   
public List<JsonObject> readPerfLog() throws Exception {
    List<LogEntry> entries = this.manage().logs().get(LogType.PERFORMANCE).getAll();

    List<JsonObject> events = new ArrayList<>();

    for (LogEntry entry : entries) {
        JsonObject message = JsonObject.readFrom(entry.getMessage()).get("message").asObject();

        if (message.get("method").asString() == "Tracing.dataCollected") {
            events.add(message.get("params").asObject());
        }
        if (message.get("method").asString() == "Tracing.bufferUsage") {
            throw new Exception("The DevTools trace buffer filled during the test!");
        }
    }

    return convertPerfRecordsToEvents(events);
}
项目: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);
        }
    }
项目: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");        
}
项目: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());
}
项目:NoraUi    文件:Step.java   
/**
 * CAUTION: This check do not work with IE: https://github.com/SeleniumHQ/selenium/issues/468
 * CAUTION: This feature is not supported by HtmlUnit web driver
 *
 * @return a String with the message of Alert, return null if no alert message.
 */
protected String getLastConsoleAlertMessage() {
    String msg;
    List<LogEntry> l = getDriver().manage().logs().get(LogType.BROWSER).getAll();
    for (int i = l.size() - 1; i >= 0; i--) {
        if (l.get(i).getMessage().contains(ALERT_KEY)) {
            msg = l.get(i).getMessage();
            return msg.substring(msg.indexOf('"') + 1, msg.length() - 1).replace(ALERT_KEY, "").replace(" (:", "");
        }
    }
    return null;
}
项目:NoraUi    文件:DriverFactory.java   
/**
 * Sets the logging level of the generated web driver.
 *
 * @param caps
 *            The web driver's capabilities
 * @param level
 *            The logging level
 */
private void setLoggingLevel(DesiredCapabilities 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);
}
项目:Bytecoder    文件:BytecoderUnitTestRunner.java   
private WebDriver newDriverForTest() {
    ChromeOptions theOptions = new ChromeOptions();
    theOptions.addArguments("headless");
    theOptions.addArguments("disable-gpu");

    LoggingPreferences theLoggingPreferences = new LoggingPreferences();
    theLoggingPreferences.enable(LogType.BROWSER, Level.ALL);
    theOptions.setCapability(CapabilityType.LOGGING_PREFS, theLoggingPreferences);

    DesiredCapabilities theCapabilities = DesiredCapabilities.chrome();
    theCapabilities.setCapability(ChromeOptions.CAPABILITY, theOptions);

    return new RemoteWebDriver(DRIVERSERVICE.getUrl(), theCapabilities);
}
项目: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
    );
}
项目:spring2ts    文件:ClientTester.java   
public void assertValid() {
    if(Selenide.$$("h2").size() != scriptsCount) {
        List<String> logs = Selenide.getWebDriverLogs(LogType.BROWSER);
        Assert.fail("Not all scripts executed successfully:\n" + Joiner.on("\n").join(logs));
    }
    List<String> failed = Selenide.$$("h2.check-failed").stream()
            .map(SelenideElement::text)
            .collect(Collectors.toList());
    if(failed.size() > 0) {
        Assert.fail("Failed tests: " + Iterables.toString(failed));
    }
}
项目:ja11y    文件:AccessibilitySinfferTest.java   
@Before
public void beforeTest() throws IOException {
    ChromeDriverManager.getInstance().setup();
    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    desiredCapabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
    driver = new ChromeDriver(desiredCapabilities);
    accessibilitySniffer = new AccessibilitySniffer(driver);

}
项目:delay-repay-bot    文件:PhantomJSTest.java   
public static DesiredCapabilities getDefaultDesiredCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("acceptSslCerts", true);
    capabilities.setCapability("takesScreenshot", true);
    capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, asList("--ignore-ssl-errors=true"));
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    return capabilities;
}
项目:delay-repay-bot    文件:PhantomJSTest.java   
public static DesiredCapabilities getChromeCapabilities() {
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);
    capabilities.setCapability("acceptSslCerts", true);
    capabilities.setCapability("takesScreenshot", true);
    capabilities.setCapability(ChromeDriverService.CHROME_DRIVER_EXE_PROPERTY, asList("--ignore-ssl-errors=true"));
    LoggingPreferences loggingPreferences = new LoggingPreferences();
    loggingPreferences.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);
    return capabilities;
}
项目: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());
        }
    }
}
项目:bobcat    文件:BrowserLogEntryCollector.java   
/**
 * @return List of log entries retrieved from browser
 */
public List<LogEntry> getBrowserLogEntries() {
  List<LogEntry> toReturn = Lists.newArrayList();
  List<org.openqa.selenium.logging.LogEntry> browserEntries =
      webDriver.manage().logs().get(LogType.BROWSER)
          .filter(Level.SEVERE);
  browserEntries.stream().
          forEach(browserEntry ->
            toReturn.add(new BrowserLogEntry(browserEntry.toString()))
          );

  return toReturn;
}
项目:spa-perf    文件:SPAPerfChromeDriver.java   
public void enablePerfProfiling(String fName)
{
    // Reset performance logs in driver
    this.manage().logs().get(LogType.PERFORMANCE).getAll();

    // Get the baseline of network metrics
    List<Map> currentNetworkActivity = (List<Map>)((JavascriptExecutor) this).executeScript("return window.performance.getEntries()");
    NetworkMetrics.previousNetworkActivityCounts = currentNetworkActivity.size();

    fileName = fName;
    selectedPerformanceCounters = ArrayUtils.addAll(TimelineMetrics.selectedPerformanceCounters, NetworkMetrics.selectedPerformanceCounters);

    // Generate the csv output file according to the row header and file path
    CSVPersistor csvFile = new CSVPersistor(fileName, selectedPerformanceCounters);
}
项目:grid-refactor-remote-server    文件:DefaultPerSessionLogHandler.java   
/**
 * Configures logging using a logging preferences object.
 * 
 * @param prefs The logging preferences object.
 */
@Override
public void configureLogging(LoggingPreferences prefs) {
  if (prefs == null) {
    return;
  }
  if (prefs.getEnabledLogTypes().contains(LogType.SERVER)) {      
    serverLogLevel = prefs.getLevel(LogType.SERVER);
  }
}
项目: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);
  }
}
项目:dropwizard-experiment    文件:ReportingWebDriverEventListener.java   
private static void saveLogs(String filename, WebDriver driver) {
    StringBuffer logs = new StringBuffer();
    for (LogEntry entry : driver.manage().logs().get(LogType.BROWSER)) {
        logs.append(Instant.ofEpochMilli(entry.getTimestamp()))
                .append(": ")
                .append(entry.getMessage())
                .append("\n");
    }
    try {
        Files.write(logs, new File(filename + ".txt"), Charsets.UTF_8);
    } catch (IOException e) {
        log.error("Unable to save logs from test failure.", e);
    }
}
项目:teasy    文件:SeleniumTestExecutionListener.java   
private void setLoggingPrefs(DesiredCapabilities capabilities) {
    LoggingPreferences logPrefs = new LoggingPreferences();
    logPrefs.enable(LogType.BROWSER, Level.ALL);
    capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
}
项目:devtools-driver    文件:IOSLogManager.java   
public IOSLogManager(LoggingPreferences prefs) {
  Level perfLevel = prefs.getLevel(LogType.PERFORMANCE);
  if (perfLevel.intValue() < Level.OFF.intValue()) {
    logs.put(LogType.PERFORMANCE, new WebDriverLog(LogType.PERFORMANCE, perfLevel));
  }
}
项目:devtools-driver    文件:IOSLogManager.java   
public Optional<PerformanceListener> performanceListener() {
  Log log = logs.get(LogType.PERFORMANCE);
  return log == null
      ? Optional.<PerformanceListener>absent()
      : Optional.of(new PerformanceListener(log));
}
项目:jwebrobot    文件:ReporterTest.java   
@Test
public void shouldNotThrowErrorIfBrowserLogForwardingIsNotSupportedByTheDriver() {
    when(logs.get(LogType.BROWSER)).thenThrow(UnsupportedCommandException.class);

    reporter.processLogEntries(context, actionReport);
}
项目:seleniumtestsframework    文件:CustomEventListener.java   
private LogEntries getBrowserLogs(WebDriver webDriver) {
    return webDriver.manage().logs().get(LogType.BROWSER);
}
项目:spa-perf    文件:TimelineMetrics.java   
private List getPerfLogFromDriver(SPAPerfChromeDriver driver) {
    return driver.manage().logs().get(LogType.PERFORMANCE).getAll();
}
项目:spa-perf    文件:SPAPerfChromeDriver.java   
public List<LogEntry> getPerformanceLog ()
{
    return this.manage().logs().get(LogType.PERFORMANCE).getAll();
}
项目:grid-refactor-remote-server    文件:GetAvailableLogTypesHandler.java   
@Override
public Set<String> call() throws Exception {
  return Sets.union(
      getDriver().manage().logs().getAvailableLogTypes(), ImmutableSet.of(LogType.SERVER));
}
项目:mineraloil-selenium    文件:Driver.java   
public LogEntries getConsoleLog() {
    log.info("Console Log output: ");
    executeScript("console.log('Logging Errors');");
    return getDriver().manage().logs().get(LogType.BROWSER);
}