Search in sources :

Example 6 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project scout.rt by eclipse.

the class BrowserLogRule method finished.

@Override
protected void finished(Description description) {
    Date end = new Date();
    long duration = end.getTime() - m_start.getTime();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
    LogEntries logEntries = m_driver.manage().logs().get(LogType.BROWSER);
    for (LogEntry logEntry : logEntries) {
        System.out.println(sdf.format(new Date(logEntry.getTimestamp())) + " " + logEntry.getLevel() + " " + logEntry.getMessage());
    }
    System.out.println(MessageFormat.format("^ | {1}.{2} [{0}] (took {3} ms)", sdf.format(end), description.getClassName(), description.getMethodName(), duration));
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) LogEntry(org.openqa.selenium.logging.LogEntry)

Example 7 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project ghostdriver by detro.

the class LogTest method shouldReturnLogTypeBrowser.

@Test
public void shouldReturnLogTypeBrowser() {
    WebDriver d = getDriver();
    d.get(server.getBaseUrl() + "/common/errors.html");
    // Throw 3 errors that are logged in the Browser's console
    WebElement throwErrorButton = d.findElement(By.cssSelector("input[type='button']"));
    throwErrorButton.click();
    throwErrorButton.click();
    throwErrorButton.click();
    // Retrieve and count the errors
    LogEntries logEntries = d.manage().logs().get("browser");
    assertEquals(3, logEntries.getAll().size());
    for (LogEntry logEntry : logEntries) {
        System.out.println(logEntry);
    }
    // Clears logs
    logEntries = d.manage().logs().get("browser");
    assertEquals(0, logEntries.getAll().size());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) WebElement(org.openqa.selenium.WebElement) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test)

Example 8 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project ghostdriver by detro.

the class LogTest method shouldReturnLogTypeHar.

@Test
public void shouldReturnLogTypeHar() {
    WebDriver d = getDriver();
    d.get(server.getBaseUrl() + "/common/iframes.html");
    LogEntries logEntries = d.manage().logs().get("har");
    for (LogEntry logEntry : logEntries) {
        System.out.println(logEntry);
    }
    String firstRequestMessage = logEntries.getAll().get(0).getMessage();
    String secondRequestMessage = d.manage().logs().get("har").getAll().get(0).getMessage();
    assertTrue(secondRequestMessage.length() < firstRequestMessage.length());
}
Also used : WebDriver(org.openqa.selenium.WebDriver) LogEntries(org.openqa.selenium.logging.LogEntries) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test)

Aggregations

LogEntries (org.openqa.selenium.logging.LogEntries)8 LogEntry (org.openqa.selenium.logging.LogEntry)7 Test (org.junit.Test)4 Date (java.util.Date)3 ChromeBrowserTest (com.vaadin.flow.testutil.ChromeBrowserTest)2 Optional (java.util.Optional)2 Level (java.util.logging.Level)2 StreamSupport (java.util.stream.StreamSupport)2 Assert (org.junit.Assert)2 By (org.openqa.selenium.By)2 WebDriver (org.openqa.selenium.WebDriver)2 WebElement (org.openqa.selenium.WebElement)2 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 JSONObject (org.json.JSONObject)1 After (org.junit.After)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Logs (org.openqa.selenium.logging.Logs)1