Search in sources :

Example 1 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project flow by vaadin.

the class WebComponentsIT method testPolyfillLoaded.

@Test
public void testPolyfillLoaded() {
    open();
    Assert.assertTrue(driver.findElements(By.tagName("script")).stream().anyMatch(element -> element.getAttribute("src").endsWith("webcomponents-loader.js")));
    LogEntries logs = driver.manage().logs().get("browser");
    if (logs != null) {
        Optional<LogEntry> anyError = StreamSupport.stream(logs.spliterator(), true).filter(entry -> entry.getLevel().intValue() > Level.INFO.intValue()).filter(entry -> !entry.getMessage().contains("favicon.ico")).findAny();
        anyError.ifPresent(entry -> Assert.fail(entry.getMessage()));
    }
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) LogEntry(org.openqa.selenium.logging.LogEntry) By(org.openqa.selenium.By) Optional(java.util.Optional) StreamSupport(java.util.stream.StreamSupport) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest) Assert(org.junit.Assert) Level(java.util.logging.Level) LogEntries(org.openqa.selenium.logging.LogEntries) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 2 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project flow by vaadin.

the class EmptyListsIT method emptyListsAreProperlyHandled.

@Test
public void emptyListsAreProperlyHandled() {
    open();
    WebElement template = findElement(By.id("template"));
    Assert.assertTrue(isPresentInShadowRoot(template, By.className("item")));
    findElement(By.id("set-empty")).click();
    LogEntries logs = driver.manage().logs().get("browser");
    if (logs != null) {
        Optional<LogEntry> anyError = StreamSupport.stream(logs.spliterator(), true).filter(entry -> entry.getLevel().intValue() > Level.INFO.intValue()).filter(entry -> !entry.getMessage().contains("favicon.ico")).findAny();
        anyError.ifPresent(entry -> Assert.fail(entry.getMessage()));
    }
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) LogEntry(org.openqa.selenium.logging.LogEntry) By(org.openqa.selenium.By) Optional(java.util.Optional) WebElement(org.openqa.selenium.WebElement) StreamSupport(java.util.stream.StreamSupport) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest) Assert(org.junit.Assert) Level(java.util.logging.Level) LogEntries(org.openqa.selenium.logging.LogEntries) WebElement(org.openqa.selenium.WebElement) LogEntry(org.openqa.selenium.logging.LogEntry) Test(org.junit.Test) ChromeBrowserTest(com.vaadin.flow.testutil.ChromeBrowserTest)

Example 3 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project elastest-torm by elastest.

the class EtmBaseTest method teardown.

@AfterEach
void teardown() throws IOException {
    if (driver != null) {
        log.info("Browser console at the end of the test");
        LogEntries logEntries = driver.manage().logs().get(BROWSER);
        logEntries.forEach((entry) -> log.info("[{}] {} {}", new Date(entry.getTimestamp()), entry.getLevel(), entry.getMessage()));
    }
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) Date(java.util.Date) AfterEach(org.junit.jupiter.api.AfterEach)

Example 4 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project cerberus-source by cerberustesting.

the class WebDriverService method getSeleniumLog.

@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;
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) ArrayList(java.util.ArrayList) Logs(org.openqa.selenium.logging.Logs) LogEntry(org.openqa.selenium.logging.LogEntry) Date(java.util.Date)

Example 5 with LogEntries

use of org.openqa.selenium.logging.LogEntries in project chrome_page_performance_sqlite_java by sergueik.

the class ChromePagePerformanceUtilTest method afterMethod.

@After
public void afterMethod() {
    System.err.println("After Method:");
    int cnt = 0;
    int maxCnt = 5;
    LogEntries logEntries = driver.manage().logs().get(LogType.PERFORMANCE);
    for (LogEntry logEntry : logEntries) {
        if (cnt++ > maxCnt) {
            break;
        }
        // System.err.println("Log entry: " + logEntry.getMessage());
        System.err.println(String.format("Log entry %d: ", cnt));
        Map<String, Object> o = (Map<String, Object>) logEntry.toJson();
        JSONObject logEntryJSONObject = new JSONObject(o.get("message"));
        Iterator<String> logEntryKeys = logEntryJSONObject.keys();
        while (logEntryKeys.hasNext()) {
            String logEntryKey = logEntryKeys.next();
            System.err.println(logEntryKey);
        }
    }
}
Also used : LogEntries(org.openqa.selenium.logging.LogEntries) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) LogEntry(org.openqa.selenium.logging.LogEntry) After(org.junit.After)

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