Class PageObject

java.lang.Object
net.serenitybdd.core.pages.PageObject
Direct Known Subclasses:
AnyPage, PageObject, UIInteractionSteps, UIQuerySteps

public abstract class PageObject extends Object
A base class representing a WebDriver page object.
Author:
johnsmart
  • Constructor Details

    • PageObject

      protected PageObject()
    • PageObject

      protected PageObject(org.openqa.selenium.WebDriver driver, com.google.common.base.Predicate<? super PageObject> callback)
    • PageObject

      public PageObject(org.openqa.selenium.WebDriver driver, int ajaxTimeout)
    • PageObject

      public PageObject(org.openqa.selenium.WebDriver driver)
    • PageObject

      public PageObject(org.openqa.selenium.WebDriver driver, EnvironmentVariables environmentVariables)
  • Method Details

    • setImplicitTimeout

      public void setImplicitTimeout(int duration, TemporalUnit unit)
    • resetImplicitTimeout

      public void resetImplicitTimeout()
    • setDriver

      protected void setDriver(org.openqa.selenium.WebDriver driver, long timeout)
    • setDriver

      public <T extends PageObject> T setDriver(org.openqa.selenium.WebDriver driver)
    • withDriver

      public <T extends PageObject> T withDriver(org.openqa.selenium.WebDriver driver)
    • getWaitForTimeout

      public Duration getWaitForTimeout()
    • getWaitForElementTimeout

      @Deprecated public Duration getWaitForElementTimeout()
      Deprecated.
    • getImplicitWaitTimeout

      public Duration getImplicitWaitTimeout()
    • setPages

      public void setPages(Pages pages)
    • switchToPage

      @Deprecated public <T extends PageObject> T switchToPage(Class<T> pageObjectClass)
      Deprecated.
    • upload

      public FileToUpload upload(String filename)
      Upload a file via an HTML form. By default, this will look for a file on the file system, at the location provided.
    • uploadData

      public FileToUpload uploadData(String data) throws IOException
      Throws:
      IOException
    • uploadData

      public FileToUpload uploadData(byte[] data) throws IOException
      Throws:
      IOException
    • setPageUrls

      public void setPageUrls(PageUrls pageUrls)
      Only for testing purposes.
    • setWaitForTimeout

      public void setWaitForTimeout(long waitForTimeoutInMilliseconds)
    • setWaitForElementTimeout

      public void setWaitForElementTimeout(long waitForTimeoutInMilliseconds)
    • getRenderedView

      protected RenderedPageObjectView getRenderedView()
    • getClock

      protected SystemClock getClock()
    • getDriver

      public org.openqa.selenium.WebDriver getDriver()
    • getTitle

      public String getTitle()
    • matchesAnyUrl

      public boolean matchesAnyUrl()
    • compatibleWithUrl

      public final boolean compatibleWithUrl(String currentUrl)
      Does this page object work for this URL? When matching a URL, we check with and without trailing slashes
    • waitForRenderedElements

      public PageObject waitForRenderedElements(org.openqa.selenium.By byElementCriteria)
    • withTimeoutOf

      @Deprecated public RenderedPageObjectView withTimeoutOf(int timeout, TimeUnit units)
      Deprecated.
      TimeUnit has been replaced by TemporalUnit in Selenium. For more consistancy use a TemporalUnit parameter.
    • withTimeoutOf

      public RenderedPageObjectView withTimeoutOf(int timeout, TemporalUnit units)
    • withTimeoutOf

      public RenderedPageObjectView withTimeoutOf(Duration timeout)
    • waitingForNoLongerThan

      public RenderedPageObjectView waitingForNoLongerThan(int timeout, TimeUnit units)
      Alternative to withTimeoutOf()
    • waitingForNoLongerThan

      public PageObject.WaitingBuilder waitingForNoLongerThan(int timeout)
      Alternative to withTimeoutOf() using a DSL
    • waitFor

      public PageObject waitFor(String xpathOrCssSelector, Object firstArgument, Object... arguments)
    • waitFor

      public PageObject waitFor(String xpathOrCssSelector)
    • waitFor

      public <T> T waitFor(org.openqa.selenium.support.ui.ExpectedCondition<T> expectedCondition)
    • waitFor

      public <T> T waitFor(String message, org.openqa.selenium.support.ui.ExpectedCondition<T> expectedCondition)
    • waitForRenderedElementsToBePresent

      public PageObject waitForRenderedElementsToBePresent(org.openqa.selenium.By byElementCriteria)
    • waitForPresenceOf

      public PageObject waitForPresenceOf(String xpathOrCssSelector, Object... arguments)
    • waitForRenderedElementsToDisappear

      public PageObject waitForRenderedElementsToDisappear(org.openqa.selenium.By byElementCriteria)
    • waitForAbsenceOf

      public PageObject waitForAbsenceOf(String xpathOrCssSelector, Object... arguments)
    • waitForAbsenceOf

      public PageObject waitForAbsenceOf(org.openqa.selenium.By byLocator)
    • waitForTextToAppear

      public PageObject waitForTextToAppear(String expectedText)
      Waits for a given text to appear anywhere on the page.
    • waitForTitleToAppear

      public PageObject waitForTitleToAppear(String expectedTitle)
    • waitOnPage

      public org.openqa.selenium.support.ui.WebDriverWait waitOnPage()
    • waitForTitleToDisappear

      public PageObject waitForTitleToDisappear(String expectedTitle)
    • waitForTextToAppear

      public PageObject waitForTextToAppear(org.openqa.selenium.WebElement element, String expectedText)
      Waits for a given text to appear inside the element.
    • waitForTextToDisappear

      public PageObject waitForTextToDisappear(org.openqa.selenium.WebElement element, String expectedText)
      Waits for a given text to disappear from the element.
    • waitForTextToDisappear

      public PageObject waitForTextToDisappear(String expectedText)
    • waitForTextToDisappear

      public PageObject waitForTextToDisappear(String expectedText, long timeoutInMilliseconds)
      Waits for a given text to not be anywhere on the page.
    • waitForTextToAppear

      public PageObject waitForTextToAppear(String expectedText, long timeout)
      Waits for a given text to appear anywhere on the page.
    • waitForAnyTextToAppear

      public PageObject waitForAnyTextToAppear(String... expectedText)
      Waits for any of a number of text blocks to appear anywhere on the screen.
    • waitForAnyTextToAppear

      public PageObject waitForAnyTextToAppear(org.openqa.selenium.WebElement element, String... expectedText)
    • waitForAllTextToAppear

      public PageObject waitForAllTextToAppear(String... expectedTexts)
      Waits for all of a number of text blocks to appear on the screen.
    • waitForAnyRenderedElementOf

      public PageObject waitForAnyRenderedElementOf(org.openqa.selenium.By... expectedElements)
    • waitABit

      protected void waitABit(long timeInMilliseconds)
    • waitFor

      public WaitForBuilder<? extends PageObject> waitFor(int duration)
    • thenReturnElementList

      public List<org.openqa.selenium.WebElement> thenReturnElementList(org.openqa.selenium.By byListCriteria)
    • shouldContainText

      public void shouldContainText(String textValue)
      Check that the specified text appears somewhere in the page.
    • shouldContainAllText

      public void shouldContainAllText(String... textValues)
      Check that all of the specified texts appears somewhere in the page.
    • containsTextInElement

      @Deprecated public boolean containsTextInElement(org.openqa.selenium.WebElement webElement, String textValue)
      Deprecated.
      use element(webElement).containsText(textValue)
      Does the specified web element contain a given text value. Useful for dropdowns and so on.
    • shouldContainTextInElement

      @Deprecated public void shouldContainTextInElement(org.openqa.selenium.WebElement webElement, String textValue)
      Deprecated.
    • shouldNotContainTextInElement

      @Deprecated public void shouldNotContainTextInElement(org.openqa.selenium.WebElement webElement, String textValue)
      Deprecated.
    • typeInto

      public void typeInto(org.openqa.selenium.WebElement field, String value)
      Clear a field and enter a value into it.
    • enter

      public PageObject.FieldEntry enter(CharSequence... keysToSend)
      Clear a field and enter a value into it. This is a more fluent alternative to using the typeInto method.
    • selectFromDropdown

      public void selectFromDropdown(org.openqa.selenium.WebElement dropdown, String visibleLabel)
    • selectMultipleItemsFromDropdown

      public void selectMultipleItemsFromDropdown(org.openqa.selenium.WebElement dropdown, String... selectedLabels)
    • getSelectedOptionLabelsFrom

      public Set<String> getSelectedOptionLabelsFrom(org.openqa.selenium.WebElement dropdown)
    • getSelectedOptionValuesFrom

      public Set<String> getSelectedOptionValuesFrom(org.openqa.selenium.WebElement dropdown)
    • getSelectedValueFrom

      public String getSelectedValueFrom(org.openqa.selenium.WebElement dropdown)
    • getSelectedLabelFrom

      public String getSelectedLabelFrom(org.openqa.selenium.WebElement dropdown)
    • setCheckbox

      public void setCheckbox(org.openqa.selenium.WebElement field, boolean value)
    • containsText

      public boolean containsText(String textValue)
    • containsAllText

      public boolean containsAllText(String... textValues)
      Check that the specified text appears somewhere in the page.
    • shouldBeVisible

      public void shouldBeVisible(org.openqa.selenium.WebElement field)
      Fail the test if this element is not displayed (rendered) on the screen.
    • shouldBeVisible

      public void shouldBeVisible(org.openqa.selenium.By byCriteria)
    • shouldNotBeVisible

      public void shouldNotBeVisible(org.openqa.selenium.WebElement field)
    • shouldNotBeVisible

      public void shouldNotBeVisible(org.openqa.selenium.By byCriteria)
    • waitForTimeoutInMilliseconds

      public long waitForTimeoutInMilliseconds()
    • implicitTimoutMilliseconds

      public long implicitTimoutMilliseconds()
    • updateUrlWithBaseUrlIfDefined

      public String updateUrlWithBaseUrlIfDefined(String startingUrl)
    • isRelative

      protected boolean isRelative(String startingUrl)
    • open

      public final void open(String[] parameterValues)
      Open the webdriver browser using a paramaterized URL. Parameters are represented in the URL using {0}, {1}, etc.
    • openUnchecked

      public final void openUnchecked(String... parameterValues)
      Opens page without checking URL patterns. Same as open(String...)) otherwise.
    • open

      public final PageObject.OpenWithParams open(String urlTemplateName)
    • open

      public final void open(String urlTemplateName, String[] parameterValues)
    • openUnchecked

      public final void openUnchecked(String urlTemplateName, String[] parameterValues)
      Opens page without checking URL patterns. Same as open(String, String[]) otherwise.
    • open

      public final void open()
      Open the webdriver browser to the base URL, determined by the DefaultUrl annotation if present. If the DefaultUrl annotation is not present, the default base URL will be used. If the DefaultUrl annotation is present, a URL based on the current base url from the system-wide default url and the relative path provided in the DefaultUrl annotation will be used to determine the URL to open. For example, consider the following class:
           
               @DefaultUrl("http://localhost:8080/client/list")
               public class ClientList extends PageObject {
                   ...
      
                   @WhenPageOpens
                   public void waitUntilTitleAppears() {...}
               }
           
       
      Suppose you are using a base URL of http://stage.acme.com. When you call open() for this class, it will open http://stage.acme.com/client/list. It will then invoke the waitUntilTitleAppears() method.
    • openUnchecked

      public final void openUnchecked()
      Opens page without checking URL patterns. Same as open() otherwise.
    • shouldBeDisplayed

      public void shouldBeDisplayed()
      Use the @At annotation (if present) to check that a page object is displaying the correct page. Will throw an exception if the current URL does not match the expected one.
    • openAt

      public final void openAt(String relativeUrl)
    • openUrl

      public final void openUrl(String absoluteUrl)
    • callWhenPageOpensMethods

      public void callWhenPageOpensMethods()
      Override this method
    • withParameters

      public static String[] withParameters(String... parameterValues)
    • openPageNamed

      public void openPageNamed(String pageName)
      Open an environment-specific page defined in the `serenity.conf` file under the `pages` section.
      Parameters:
      pageName -
    • clickOn

      public void clickOn(org.openqa.selenium.WebElement webElement)
    • isElementVisible

      public Boolean isElementVisible(org.openqa.selenium.By byCriteria)
      Returns true if at least one matching element is found on the page and is visible.
    • setDefaultBaseUrl

      public void setDefaultBaseUrl(String defaultBaseUrl)
    • hasFocus

      public boolean hasFocus(org.openqa.selenium.WebElement webElement)
      Deprecated.
      Use element(webElement).hasFocus() instead
      Returns true if the specified element has the focus.
    • blurActiveElement

      public void blurActiveElement()
    • getJavascriptExecutorFacade

      protected JavascriptExecutorFacade getJavascriptExecutorFacade()
    • element

      public <T extends WebElementFacade> T element(org.openqa.selenium.WebElement webElement)
      Provides a fluent API for querying web elements.
    • $

      public <T extends WebElementFacade> T $(WithLocator locator)
    • $

      public <T extends WebElementFacade> T $(WithByLocator locator)
    • $

      public <T extends WebElementFacade> T $(org.openqa.selenium.WebElement webElement)
    • $

      public <T extends WebElementFacade> T $(String xpathOrCssSelector, Object... arguments)
    • $

      public <T extends WebElementFacade> T $(org.openqa.selenium.By bySelector)
    • textOf

      public String textOf(WithLocator locator)
      Return the text value of a given element
    • textOf

      public String textOf(WithByLocator locator)
    • textOf

      public String textOf(String xpathOrCssSelector, Object... arguments)
    • textOf

      public String textOf(org.openqa.selenium.By bySelector)
    • textContentOf

      public String textContentOf(WithLocator locator)
      Return the text value of a given element
    • textContentOf

      public String textContentOf(WithByLocator locator)
    • textContentOf

      public String textContentOf(String xpathOrCssSelector, Object... arguments)
    • textContentOf

      public String textContentOf(org.openqa.selenium.By bySelector)
    • $$

      public ListOfWebElementFacades $$(String xpathOrCssSelector, Object... arguments)
    • $$

      public ListOfWebElementFacades $$(org.openqa.selenium.By bySelector)
    • element

      public <T extends WebElementFacade> T element(org.openqa.selenium.By bySelector)
      Provides a fluent API for querying web elements.
    • find

      public <T extends WebElementFacade> T find(org.openqa.selenium.By selector)
    • find

      public <T extends WebElementFacade> T find(WithByLocator selector)
    • find

      public <T extends WebElementFacade> T find(WithLocator selector)
    • find

      public <T extends WebElementFacade> T find(List<org.openqa.selenium.By> selectors)
    • findBy

      public <T extends WebElementFacade> T findBy(List<String> selectors)
    • findNested

      public <T extends WebElementFacade> T findNested(org.openqa.selenium.By... selectors)
    • find

      public <T extends WebElementFacade> T find(String selector)
    • findNested

      public <T extends WebElementFacade> T findNested(String... selectors)
    • findFirst

      public Optional<WebElementFacade> findFirst(String xpathOrCSSSelector)
    • findFirst

      public Optional<WebElementFacade> findFirst(org.openqa.selenium.By bySelector)
    • findEach

      public Stream<WebElementFacade> findEach(org.openqa.selenium.By bySelector)
    • findEach

      public Stream<WebElementFacade> findEach(WithByLocator bySelector)
    • findEach

      public Stream<WebElementFacade> findEach(WithLocator bySelector)
    • findEach

      public Stream<WebElementFacade> findEach(org.openqa.selenium.By... bySelectors)
      FindEach will return a stream of WebElementFacades matching the described nested structure. Only the last selector will return a list; the initial selectors will be used to locate the list of elements.
      Parameters:
      bySelectors -
      Returns:
    • findEach

      public Stream<WebElementFacade> findEach(String... xpathOrCssSelectors)
    • findNestedElements

      public ListOfWebElementFacades findNestedElements(String... xpathOrCssSelectors)
    • findEach

      public Stream<WebElementFacade> findEach(String xpathOrCSSSelector)
    • findAll

      public ListOfWebElementFacades findAll(org.openqa.selenium.By bySelector)
    • findAll

      public ListOfWebElementFacades findAll(WithLocator bySelector)
    • findAll

      public ListOfWebElementFacades findAll(WithByLocator bySelector)
    • element

      public <T extends WebElementFacade> T element(String xpathOrCssSelector, Object... arguments)
      Provides a fluent API for querying web elements.
    • findBy

      public <T extends WebElementFacade> T findBy(String xpathOrCssSelector, Object... arguments)
    • findFirst

      public Optional<WebElementFacade> findFirst(String xpathOrCssSelector, Object... arguments)
    • findAll

      public ListOfWebElementFacades findAll(String xpathOrCssSelector, Object... arguments)
    • containsElements

      public boolean containsElements(org.openqa.selenium.By bySelector)
    • containsElements

      public boolean containsElements(String xpathOrCssSelector, Object... arguments)
    • evaluateJavascript

      public Object evaluateJavascript(String script)
    • evaluateJavascript

      public Object evaluateJavascript(String script, Object... params)
    • addJQuerySupport

      public void addJQuerySupport()
    • driverIsJQueryCompatible

      protected boolean driverIsJQueryCompatible()
    • inRadioButtonGroup

      public RadioButtonGroup inRadioButtonGroup(String name)
    • driverIsInstantiated

      protected boolean driverIsInstantiated()
    • waitForWithRefresh

      public ThucydidesFluentWait<org.openqa.selenium.WebDriver> waitForWithRefresh()
    • waitForCondition

      public SerenityFluentWait waitForCondition()
    • waitFor

      public WebElementFacade waitFor(org.openqa.selenium.WebElement webElement)
    • waitFor

      public WebElementFacade waitFor(WebElementFacade webElement)
    • waitForElement

      public WebElementFacadeWait waitForElement()
    • getAlert

      public org.openqa.selenium.Alert getAlert()
    • withAction

      public org.openqa.selenium.interactions.Actions withAction()
    • fluent

      protected ThucydidesFluentAdapter fluent()
    • moveTo

      public <T extends WebElementFacade> T moveTo(String xpathOrCssSelector, Object... arguments)
    • moveTo

      public <T extends WebElementFacade> T moveTo(org.openqa.selenium.By locator)
    • waitForAngularRequestsToFinish

      public void waitForAngularRequestsToFinish()
    • toString

      public String toString()
      Overrides:
      toString in class Object