Java Code Examples for org.openqa.selenium.logging.Logs#get()
The following examples show how to use
org.openqa.selenium.logging.Logs#get() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertOnly() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0);\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed")); }
Example 2
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertString() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, 'the # is not even');\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("Assertion failed: the # is not even")); }
Example 3
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertObject() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, {number: number, errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: ({number: 1.0, errorMsg: \"the # is not even\"})")); }
Example 4
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertObjects() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " number = 1;\n" + " console.assert(number % 2 === 0, {number: number}, {errorMsg: 'the # is not even'});\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: ({number: 1.0}) ({errorMsg: \"the # is not even\"})")); }
Example 5
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 6 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void assertParams() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " console.assert(false, 'the word is %s', 'foo');\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); assertEquals(1, logEntryList.size()); final LogEntry logEntry = logEntryList.get(0); assertTrue(logEntry.getMessage(), logEntry.getMessage() .contains("Assertion failed: the word is foo")); }
Example 6
Source File: ConsoleTest.java From htmlunit with Apache License 2.0 | 5 votes |
/** * @throws Exception if the test fails */ @Test @BuggyWebDriver public void simpleString() throws Exception { final String html = "<html>\n" + "<body>\n" + "<script>\n" + " for (i = 0; i < 4; i++) {\n" + " console.log('test log ' + i);\n" + " }\n" + "</script>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final Logs logs = driver.manage().logs(); final LogEntries logEntries = logs.get(LogType.BROWSER); final List<LogEntry> logEntryList = logEntries.getAll(); final int count = logEntryList.size(); assertTrue(count > 0); long timestamp = 0; for (int i = 0; i < 4; i++) { final LogEntry logEntry = logEntryList.get(i); assertTrue(logEntry.getMessage(), logEntry.getMessage().contains("test log " + i)); assertTrue(logEntry.getTimestamp() >= timestamp); timestamp = logEntry.getTimestamp(); } }
Example 7
Source File: SeleniumException.java From gatf with Apache License 2.0 | 5 votes |
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)); }
Example 8
Source File: WebDriverService.java From cerberus-source with GNU General Public License v3.0 | 5 votes |
@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; }
Example 9
Source File: JavaDriver.java From marathonv5 with Apache License 2.0 | 4 votes |
public void clearlogs(String logType) { Logs logs = manage().logs(); logs.get(logType); }