private static void log(String command, String description, boolean success, boolean ifLowLevel) { logsResults.add(success); String escapedDescription = escapeHtml(description); String className = success ? "success" : "error"; StringBuilder builder = new StringBuilder(); if (ifLowLevel) { builder.append( "<tr class=\"" + className + " lowLevelAction" + "\"><td>" + command + "</td><td>" + escapedDescription + "</td><td> <br/> </td></tr>"); } else { builder.append( "<tr class=\"" + className + "\"><td>" + command + "</td><td>" + escapedDescription + "</td><td> <br/> </td></tr>"); } CommonUtils.appendTextToFile(logPath, builder.toString()); logJSError(NewDriverProvider.getWebDriver()); }
@Override public void beforeNavigateTo(String url, WebDriver driver) { StringBuilder builder = new StringBuilder(); builder.append( "<tr class=\"success\"><td>Navigate to</td><td>" + url + "</td><td> <br/> </td></tr>"); CommonUtils.appendTextToFile(logPath, builder.toString()); logJSError(driver); }
@Override public void afterNavigateTo(String url, WebDriver driver) { StringBuilder builder = new StringBuilder(); if (!AlertHandler.isAlertPresent(driver)) { if (url.equals(driver.getCurrentUrl())) { builder.append( "<tr class=\"success\"><td>Url after navigation</td><td>" + driver.getCurrentUrl() + "</td><td> <br/> </td></tr>"); CommonUtils.appendTextToFile(logPath, builder.toString()); } else { if (driver.getCurrentUrl().contains("data:text/html,chromewebdata ")) { driver.get(url); } logWarning("Url after navigation", driver.getCurrentUrl()); } } else { logWarning("Url after navigation", "Unable to check URL after navigation - alert present"); } logJSError(driver); }
public static void log(String command, String description, boolean success, WebDriver driver) { logsResults.add(success); imageCounter += 1; new Shooter().savePageScreenshot(screenPath + imageCounter, driver); CommonUtils.appendTextToFile(screenPath + imageCounter + ".html", getPageSource(driver)); String className = success ? "success" : "error"; StringBuilder builder = new StringBuilder(); builder.append( "<tr class=\"" + className + "\"><td>" + command + "</td><td>" + description + "</td><td> <br/><a href='screenshots/screenshot" + imageCounter + ".png'>Screenshot</a><br/><a href='screenshots/screenshot" + imageCounter + ".html'>HTML Source</a></td></tr>"); CommonUtils.appendTextToFile(logPath, builder.toString()); logJSError(driver); }
@Override public void onTestFailure(ITestResult result) { driver = NewDriverProvider.getWebDriver(); if (driver == null) { driver = NewDriverProvider.getWebDriver(); } imageCounter += 1; if ("true".equals(Configuration.getLogEnabled())) { try { new Shooter().savePageScreenshot(screenPath + imageCounter, driver); CommonUtils.appendTextToFile(screenPath + imageCounter + ".html", getPageSource(driver)); } catch (Exception e) { log( "onException", "driver has no ability to catch screenshot or html source - driver may died", false); } String exception = escapeHtml( result.getThrowable().toString() + "\n" + ExceptionUtils.getStackTrace(result.getThrowable())); StringBuilder builder = new StringBuilder(); builder.append( "<tr class=\"error\"><td>error</td><td><pre>" + exception + "</pre></td><td> <br/><a href='screenshots/screenshot" + imageCounter + ".png'>Screenshot</a><br/><a href='screenshots/screenshot" + imageCounter + ".html'>HTML Source</a></td></tr>"); CommonUtils.appendTextToFile(logPath, builder.toString()); logJSError(driver); onTestSuccess(result); } }
@Override public void beforeClickOn(WebElement element, WebDriver driver) { logJSError(driver); }