java.lang.Object
net.serenitybdd.screenplay.playwright.assertions.Ensure

public class Ensure extends Object
Perform assertions about the state of elements, pages, and URLs using Playwright's native assertion API with built-in auto-retry.

Sample usage:

     actor.attemptsTo(
         // Element assertions
         Ensure.that("#element").isVisible(),
         Ensure.that("#element").hasText("Hello"),
         Ensure.that("#element").containsText("ello"),
         Ensure.that("#element").hasTextMatching("Hel.*"),
         Ensure.that("#element").hasAttribute("class", "active"),
         Ensure.that("#element").hasClass("active"),
         Ensure.that(".items").hasCount(5),

         // URL assertions
         Ensure.thatTheCurrentUrl().contains("/dashboard"),

         // Page title assertions
         Ensure.thatThePageTitle().isEqualTo("Dashboard"),
         Ensure.thatThePageTitle().contains("Dashboard")
     );
 
  • Constructor Summary

    Constructors
    Constructor
    Description
    Ensure(Target target, Double timeout)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    net.serenitybdd.screenplay.Performable
    containsText(String expectedText)
    Check whether the element contains the specified text.
    net.serenitybdd.screenplay.Performable
    currentValue(String expectedValue)
    Check whether the input element has the expected value.
    net.serenitybdd.screenplay.Performable
    hasAttribute(String name, String value)
    Check whether the element has an attribute with the expected value.
    net.serenitybdd.screenplay.Performable
    Check whether the element has an attribute containing the expected substring.
    net.serenitybdd.screenplay.Performable
    hasClass(String className)
    Check whether the element has the specified CSS class.
    net.serenitybdd.screenplay.Performable
    hasCount(int count)
    Check that the locator resolves to the expected number of elements.
    net.serenitybdd.screenplay.Performable
    hasCSSValue(String name, String value)
    Check whether the element has the expected CSS property value.
    net.serenitybdd.screenplay.Performable
    hasText(String expectedText)
    Check whether the element has the exact text.
    net.serenitybdd.screenplay.Performable
    Check whether the element text matches a regex pattern (as string).
    net.serenitybdd.screenplay.Performable
    Check whether the element text matches a regex pattern.
    net.serenitybdd.screenplay.Performable
    hasValue(String expectedValue)
    Alias for currentValue.
    net.serenitybdd.screenplay.Performable
    Check whether the element is checked (for checkbox/radio).
    net.serenitybdd.screenplay.Performable
    Check whether the element is disabled.
    net.serenitybdd.screenplay.Performable
    Check whether the element is editable.
    net.serenitybdd.screenplay.Performable
    Check whether the input element is empty.
    net.serenitybdd.screenplay.Performable
    Check whether the element is enabled.
    net.serenitybdd.screenplay.Performable
    Check whether the element has focus.
    net.serenitybdd.screenplay.Performable
    Check whether the element is not visible.
    net.serenitybdd.screenplay.Performable
    Check whether the element is NOT checked.
    net.serenitybdd.screenplay.Performable
    Check whether the element is not empty.
    net.serenitybdd.screenplay.Performable
    Check whether the element is visible.
    static Ensure
    that(String selector)
    Start an assertion about an element identified by a selector.
    static Ensure
    that(Target target)
    Start an assertion about a Target element.
    static net.serenitybdd.screenplay.playwright.assertions.UrlEnsure
    Start an assertion about the current URL.
    static net.serenitybdd.screenplay.playwright.assertions.PageTitleEnsure
    Start an assertion about the page title.
    Set a custom timeout for this assertion.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • that

      public static Ensure that(String selector)
      Start an assertion about an element identified by a selector.
    • that

      public static Ensure that(Target target)
      Start an assertion about a Target element.
    • thatTheCurrentUrl

      public static net.serenitybdd.screenplay.playwright.assertions.UrlEnsure thatTheCurrentUrl()
      Start an assertion about the current URL.
    • thatThePageTitle

      public static net.serenitybdd.screenplay.playwright.assertions.PageTitleEnsure thatThePageTitle()
      Start an assertion about the page title.
    • withTimeout

      public Ensure withTimeout(Double timeout)
      Set a custom timeout for this assertion.
    • isVisible

      public net.serenitybdd.screenplay.Performable isVisible()
      Check whether the element is visible.
    • isHidden

      public net.serenitybdd.screenplay.Performable isHidden()
      Check whether the element is not visible.
    • isChecked

      public net.serenitybdd.screenplay.Performable isChecked()
      Check whether the element is checked (for checkbox/radio).
    • isNotChecked

      public net.serenitybdd.screenplay.Performable isNotChecked()
      Check whether the element is NOT checked.
    • isEnabled

      public net.serenitybdd.screenplay.Performable isEnabled()
      Check whether the element is enabled.
    • isDisabled

      public net.serenitybdd.screenplay.Performable isDisabled()
      Check whether the element is disabled.
    • isEditable

      public net.serenitybdd.screenplay.Performable isEditable()
      Check whether the element is editable.
    • isFocused

      public net.serenitybdd.screenplay.Performable isFocused()
      Check whether the element has focus.
    • isEmpty

      public net.serenitybdd.screenplay.Performable isEmpty()
      Check whether the input element is empty.
    • isNotEmpty

      public net.serenitybdd.screenplay.Performable isNotEmpty()
      Check whether the element is not empty.
    • hasText

      public net.serenitybdd.screenplay.Performable hasText(String expectedText)
      Check whether the element has the exact text.
    • containsText

      public net.serenitybdd.screenplay.Performable containsText(String expectedText)
      Check whether the element contains the specified text.
    • hasTextMatching

      public net.serenitybdd.screenplay.Performable hasTextMatching(String regex)
      Check whether the element text matches a regex pattern (as string).
    • hasTextMatching

      public net.serenitybdd.screenplay.Performable hasTextMatching(Pattern pattern)
      Check whether the element text matches a regex pattern.
    • currentValue

      public net.serenitybdd.screenplay.Performable currentValue(String expectedValue)
      Check whether the input element has the expected value.
    • hasValue

      public net.serenitybdd.screenplay.Performable hasValue(String expectedValue)
      Alias for currentValue.
    • hasAttribute

      public net.serenitybdd.screenplay.Performable hasAttribute(String name, String value)
      Check whether the element has an attribute with the expected value.
    • hasAttributeContaining

      public net.serenitybdd.screenplay.Performable hasAttributeContaining(String name, String substring)
      Check whether the element has an attribute containing the expected substring.
    • hasClass

      public net.serenitybdd.screenplay.Performable hasClass(String className)
      Check whether the element has the specified CSS class.
    • hasCount

      public net.serenitybdd.screenplay.Performable hasCount(int count)
      Check that the locator resolves to the expected number of elements.
    • hasCSSValue

      public net.serenitybdd.screenplay.Performable hasCSSValue(String name, String value)
      Check whether the element has the expected CSS property value.