本文整理汇总了Java中org.openqa.selenium.logging.LogEntry类的典型用法代码示例。如果您正苦于以下问题:Java LogEntry类的具体用法?Java LogEntry怎么用?Java LogEntry使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LogEntry类属于org.openqa.selenium.logging包,在下文中一共展示了LogEntry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTestLogs
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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;
}
示例2: getLog
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@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;
}
}
示例3: getLog
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@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;
}
}
示例4: shouldConvertLogEntries
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@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));
}
示例5: readPerfLog
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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);
}
示例6: after
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@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);
}
}
}
}
示例7: dumpLog
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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");
}
示例8: storeBrowsersLogs
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@FailedTest
public static void storeBrowsersLogs() {
List<String> lines = new ArrayList<>();
for (String browserKey : browserLogs.keySet()) {
for (LogEntry logEntry : browserLogs.get(browserKey)) {
lines.add(logEntry.toString());
}
File file = new File(getDefaultOutputTestPath() + browserKey + ".log");
try {
FileUtils.writeLines(file, lines);
} catch (IOException e) {
log.error("Error while writing browser log to a file", e);
}
}
}
示例9: dumpBrowserLogs
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
protected void dumpBrowserLogs(String testName) {
try {
Logs logs = webdriver.manage().logs();
for(String type : logs.getAvailableLogTypes()) {
String fileName = testName + "_" + type;
List<LogEntry> allLogs = logs.get(type).getAll();
if (allLogs.size() > 0) {
WEBDRIVER_LOGS_DIR_PATH.mkdirs();
writeLines(new File(WEBDRIVER_LOGS_DIR_PATH, fileName), allLogs);
}
}
} catch (Exception e) {
logger.error("Cannot dumpBrowserLogs('" + testName + "')", e);
}
}
示例10: SeleniumTestResult
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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));
}
示例11: onTestFailure
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@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());
}
}
示例12: getLogs
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
@Override
public List<LogEntry> getLogs() {
List<LogEntry> logs = Lists.newArrayList();
String result = logoutput != null ? logoutput.toString() : "";
String[] lines = result.split("\\r?\\n");
log.fine("getting logcat");
for (String line : lines) {
Level l;
if (line.startsWith("I")) {
l = Level.INFO;
} else if (line.startsWith("W")) {
l = Level.WARNING;
} else if (line.startsWith("S")) {
l = Level.SEVERE;
} else {
l = Level.FINE;
}
logs.add(new LogEntry(l, System.currentTimeMillis(), line));
log.fine(line);
}
return logs;
}
示例13: loggingWorks
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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 = "));
}
示例14: loglevelsAreRespected
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
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());
}
示例15: getLastConsoleAlertMessage
import org.openqa.selenium.logging.LogEntry; //导入依赖的package包/类
/**
* 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;
}