From 8227c376c356ab084c90fcee3c6b0621d74cf4ff Mon Sep 17 00:00:00 2001 From: eoff Date: Thu, 19 Dec 2013 08:44:49 +0400 Subject: [PATCH] document loaded matcher --- .../webdriver/DocumentLoadedMatcher.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 webdriver-matchers/src/main/java/ru/yandex/qatools/matchers/webdriver/DocumentLoadedMatcher.java diff --git a/webdriver-matchers/src/main/java/ru/yandex/qatools/matchers/webdriver/DocumentLoadedMatcher.java b/webdriver-matchers/src/main/java/ru/yandex/qatools/matchers/webdriver/DocumentLoadedMatcher.java new file mode 100644 index 0000000..3e05586 --- /dev/null +++ b/webdriver-matchers/src/main/java/ru/yandex/qatools/matchers/webdriver/DocumentLoadedMatcher.java @@ -0,0 +1,40 @@ +package ru.yandex.qatools.matchers.webdriver; + +import org.hamcrest.Description; +import org.hamcrest.Factory; +import org.hamcrest.TypeSafeMatcher; +import org.openqa.selenium.JavascriptExecutor; +import org.openqa.selenium.WebDriver; + +/** + * User: eoff (eoff@yandex-team.ru) + * Date: 19.12.13 + */ +public class DocumentLoadedMatcher extends TypeSafeMatcher { + @Override + protected boolean matchesSafely(WebDriver item) { + JavascriptExecutor js = (JavascriptExecutor) item; + return (Boolean) js.executeScript( + "if (window.jQuery) { " + + " return jQuery.active == 0 && document.readyState === 'complete'" + + "} else {\n" + + " return document.readyState === 'complete'" + + "}" + ); + } + + @Override + protected void describeMismatchSafely(WebDriver item, Description mismatchDescription) { + mismatchDescription.appendText("Content not loaded"); + } + + @Override + public void describeTo(Description description) { + description.appendText("Content loaded"); + } + + @Factory + public static DocumentLoadedMatcher contentLoaded() { + return new DocumentLoadedMatcher(); + } +}