All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ru.yandex.qatools.matchers.webdriver.driver.HasTextMatcher Maven / Gradle / Ivy

The newest version!
package ru.yandex.qatools.matchers.webdriver.driver;

import org.hamcrest.CoreMatchers;
import org.hamcrest.Description;
import org.hamcrest.Factory;
import org.hamcrest.Matcher;
import org.hamcrest.TypeSafeMatcher;
import org.openqa.selenium.WebDriver;

public class HasTextMatcher extends TypeSafeMatcher {
    private Matcher matcher;

    protected HasTextMatcher(Matcher matcher) {
        this.matcher = matcher;
    }

    @Override
    protected boolean matchesSafely(WebDriver wd) {
        return matcher.matches(wd.getPageSource());
    }

    @Override
    public void describeTo(Description description) {
        description.appendText("webdriver has page with text ").appendDescriptionOf(matcher);
    }

    @Override
    protected void describeMismatchSafely(WebDriver item, Description mismatchDescription) {
        matcher.describeMismatch(item.getPageSource(), mismatchDescription);
    }

    @Factory
    public static Matcher textOnCurrentPageContains(String text) {
        return textOnCurrentPage(CoreMatchers.containsString(text));
    }

    @Factory
    public static Matcher textOnCurrentPage(Matcher text) {
        return new HasTextMatcher(text);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy