Skip to content

Instantly share code, notes, and snippets.

@huguogang
Last active December 25, 2015 06:09
Show Gist options
  • Save huguogang/6929914 to your computer and use it in GitHub Desktop.
Save huguogang/6929914 to your computer and use it in GitHub Desktop.
check runtime script error for Selenium WebDriver
//make sure it's run after every page load
public static void injectSJTXE(WebDriver driver) throws IOException {
URL url;
String js;
url = Resources.getResource(ExtJSUtil.class, "SJTXE.js");
js = Resources.toString(url, Charsets.UTF_8);
((JavascriptExecutor) driver).executeScript(js);
}
//code to check if there are ExtJS Ajax error
Boolean hasJSError = (Boolean) ((JavascriptExecutor) driver).executeScript("return SJTXE.hasJSError();");
//or check it in @After for each test case
@After
public void tearDown() {
assertThat("No runtime JavaScript error",
(Boolean) ((JavascriptExecutor) driver).executeScript("return SJTXE.hasJSError();"),
equalTo(false));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment