View Javadoc
1   package com.github.searls.jasmine.runner;
2   
3   import org.apache.commons.lang3.StringUtils;
4   import org.apache.maven.plugin.logging.Log;
5   import org.openqa.selenium.By;
6   import org.openqa.selenium.WebDriver;
7   import org.openqa.selenium.WebElement;
8   
9   class ConsoleErrorChecker {
10    void checkForConsoleErrors(final WebDriver driver, final Log log) {
11      final WebElement head = driver.findElement(By.tagName("head"));
12      if (head != null) {
13        String jserrors = head.getAttribute("jmp_jserror");
14        if (StringUtils.isNotBlank(jserrors)) {
15          String errors = "JavaScript Console Errors:\n\n  * " + jserrors.replaceAll(":!:", "\n  * ") + "\n\n";
16          log.warn(errors);
17          throw new RuntimeException("There were javascript console errors.\n\n" + errors);
18        }
19      }
20    }
21  }