com.codeborne.selenide.Condition [src]

Условия используются в конструкциях should / shouldNot / waitUntil / waitWhile. Мы рекомендуем статически импортировать используемые условия, чтобы получить все преимущества читаемого кода.

  • visible | appear // e.g. $("input").shouldBe(visible)

  • present | exist // условия присутствия элемента в DOM

  • hidden | disappear | not(visible)

  • readonly // e.g. $("input").shouldBe(readonly)

  • name // e.g. $("input").shouldHave(name("fname"))

  • value // e.g. $("input").shouldHave(value("John"))

  • type // e.g. $("#input").shouldHave(type("checkbox"))

  • id // e.g. $("#input").shouldHave(id("myForm"))

  • empty // e.g. $("h2").shouldBe(empty)

  • attribute(name) // e.g. $("#input").shouldHave(attribute("required"))

  • attribute(name, value) // e.g. $("#list li").shouldHave(attribute("class", "active checked"))

  • cssClass(String) // e.g. $("#list li").shouldHave(cssClass("checked"))

  • focused

  • enabled

  • disabled

  • selected

  • matchText(String regex)

  • text(String substring)

  • exactText(String wholeText)

  • textCaseSensitive(String substring)

  • exactTextCaseSensitive(String wholeText)

  • and

  • or

  • not

Можно составлять более сложные условия на основе уже имеющихся:

Condition clickable = and("can be clicked", visible, enabled);
$$(".button").findBy(clickable).click()
//...
log("Hidden or disabled items: " + $$(".item").filterBy(not(clickable)).size());

Можно легко добавлять свои условия, реализовав подкласс com.codeborne.selenide.Condition.

e.g.:

    public static Condition css(final String propName, final String propValue) {
        return new Condition("css") {
            @Override
            public boolean apply(WebElement element) {
                return propValue.equalsIgnoreCase(element.getCssValue(propName));
            }

            @Override
            public String actualValue(WebElement element) {
                return element.getCssValue(propName);
            }
        };
    }

// Пример использования:
$("h1").shouldHave(css("font-size", "16px"));

Last updated