Package net.serenitybdd.core.pages
Class PageObject
java.lang.Object
net.serenitybdd.core.pages.PageObject
- Direct Known Subclasses:
AnyPage,PageObject,UIInteractionSteps,UIQuerySteps
A base class representing a WebDriver page object.
- Author:
- johnsmart
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassstatic classstatic class -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPageObject(org.openqa.selenium.WebDriver driver) PageObject(org.openqa.selenium.WebDriver driver, int ajaxTimeout) protectedPageObject(org.openqa.selenium.WebDriver driver, com.google.common.base.Predicate<? super PageObject> callback) PageObject(org.openqa.selenium.WebDriver driver, EnvironmentVariables environmentVariables) -
Method Summary
Modifier and TypeMethodDescription<T extends WebElementFacade>
T<T extends WebElementFacade>
T$(WithByLocator locator) <T extends WebElementFacade>
T$(WithLocator locator) <T extends WebElementFacade>
T$(org.openqa.selenium.By bySelector) <T extends WebElementFacade>
T$(org.openqa.selenium.WebElement webElement) $$(org.openqa.selenium.By bySelector) voidvoidvoidOverride this methodvoidclickOn(org.openqa.selenium.WebElement webElement) final booleancompatibleWithUrl(String currentUrl) Does this page object work for this URL? When matching a URL, we check with and without trailing slashesbooleancontainsAllText(String... textValues) Check that the specified text appears somewhere in the page.booleancontainsElements(String xpathOrCssSelector, Object... arguments) booleancontainsElements(org.openqa.selenium.By bySelector) booleancontainsText(String textValue) booleancontainsTextInElement(org.openqa.selenium.WebElement webElement, String textValue) Deprecated.use element(webElement).containsText(textValue)protected booleanprotected boolean<T extends WebElementFacade>
TProvides a fluent API for querying web elements.<T extends WebElementFacade>
Telement(org.openqa.selenium.By bySelector) Provides a fluent API for querying web elements.<T extends WebElementFacade>
Telement(org.openqa.selenium.WebElement webElement) Provides a fluent API for querying web elements.enter(CharSequence... keysToSend) Clear a field and enter a value into it.evaluateJavascript(String script) evaluateJavascript(String script, Object... params) <T extends WebElementFacade>
T<T extends WebElementFacade>
T<T extends WebElementFacade>
Tfind(WithByLocator selector) <T extends WebElementFacade>
Tfind(WithLocator selector) <T extends WebElementFacade>
Tfind(org.openqa.selenium.By selector) findAll(WithByLocator bySelector) findAll(WithLocator bySelector) findAll(org.openqa.selenium.By bySelector) <T extends WebElementFacade>
T<T extends WebElementFacade>
TfindEach(WithByLocator bySelector) findEach(WithLocator bySelector) findEach(org.openqa.selenium.By bySelector) findEach(org.openqa.selenium.By... bySelectors) FindEach will return a stream of WebElementFacades matching the described nested structure.findFirst(org.openqa.selenium.By bySelector) <T extends WebElementFacade>
TfindNested(String... selectors) <T extends WebElementFacade>
TfindNested(org.openqa.selenium.By... selectors) findNestedElements(String... xpathOrCssSelectors) protected ThucydidesFluentAdapterfluent()org.openqa.selenium.AlertgetAlert()protected SystemClockgetClock()org.openqa.selenium.WebDriverprotected JavascriptExecutorFacadeprotected RenderedPageObjectViewgetSelectedLabelFrom(org.openqa.selenium.WebElement dropdown) getSelectedOptionLabelsFrom(org.openqa.selenium.WebElement dropdown) getSelectedOptionValuesFrom(org.openqa.selenium.WebElement dropdown) getSelectedValueFrom(org.openqa.selenium.WebElement dropdown) getTitle()Deprecated.booleanhasFocus(org.openqa.selenium.WebElement webElement) Deprecated.Use element(webElement).hasFocus() insteadlonginRadioButtonGroup(String name) isElementVisible(org.openqa.selenium.By byCriteria) Returns true if at least one matching element is found on the page and is visible.protected booleanisRelative(String startingUrl) boolean<T extends WebElementFacade>
T<T extends WebElementFacade>
TmoveTo(org.openqa.selenium.By locator) voidnavigateToPageNamed(String pageName) final voidopen()Open the webdriver browser to the base URL, determined by the DefaultUrl annotation if present.final voidOpen the webdriver browser using a paramaterized URL.final voidfinal voidvoidopenPageNamed(String pageName) Open an environment-specific page defined in the `serenity.conf` file under the `pages` section.final voidOpens page without checking URL patterns.final voidopenUnchecked(String... parameterValues) Opens page without checking URL patterns.final voidopenUnchecked(String urlTemplateName, String[] parameterValues) Opens page without checking URL patterns.final voidvoidvoidselectFromDropdown(org.openqa.selenium.WebElement dropdown, String visibleLabel) voidselectMultipleItemsFromDropdown(org.openqa.selenium.WebElement dropdown, String... selectedLabels) voidsetCheckbox(org.openqa.selenium.WebElement field, boolean value) voidsetDefaultBaseUrl(String defaultBaseUrl) <T extends PageObject>
TsetDriver(org.openqa.selenium.WebDriver driver) protected voidsetDriver(org.openqa.selenium.WebDriver driver, long timeout) voidsetImplicitTimeout(int duration, TemporalUnit unit) voidvoidsetPageUrls(PageUrls pageUrls) Only for testing purposes.voidsetWaitForElementTimeout(long waitForTimeoutInMilliseconds) voidsetWaitForTimeout(long waitForTimeoutInMilliseconds) voidUse the @At annotation (if present) to check that a page object is displaying the correct page.voidshouldBeVisible(org.openqa.selenium.By byCriteria) voidshouldBeVisible(org.openqa.selenium.WebElement field) Fail the test if this element is not displayed (rendered) on the screen.voidshouldContainAllText(String... textValues) Check that all of the specified texts appears somewhere in the page.voidshouldContainText(String textValue) Check that the specified text appears somewhere in the page.voidshouldContainTextInElement(org.openqa.selenium.WebElement webElement, String textValue) Deprecated.voidshouldNotBeVisible(org.openqa.selenium.By byCriteria) voidshouldNotBeVisible(org.openqa.selenium.WebElement field) voidshouldNotContainTextInElement(org.openqa.selenium.WebElement webElement, String textValue) Deprecated.<T extends PageObject>
TswitchToPage(Class<T> pageObjectClass) Deprecated.textContentOf(String xpathOrCssSelector, Object... arguments) textContentOf(WithByLocator locator) textContentOf(WithLocator locator) Return the text value of a given elementtextContentOf(org.openqa.selenium.By bySelector) textOf(WithByLocator locator) textOf(WithLocator locator) Return the text value of a given elementtextOf(org.openqa.selenium.By bySelector) List<org.openqa.selenium.WebElement>thenReturnElementList(org.openqa.selenium.By byListCriteria) toString()voidClear a field and enter a value into it.updateUrlWithBaseUrlIfDefined(String startingUrl) Upload a file via an HTML form.uploadData(byte[] data) uploadData(String data) protected voidwaitABit(long timeInMilliseconds) WaitForBuilder<? extends PageObject>waitFor(int duration) <T> TwaitFor(WebElementFacade webElement) <T> TwaitFor(org.openqa.selenium.support.ui.ExpectedCondition<T> expectedCondition) waitFor(org.openqa.selenium.WebElement webElement) waitForAbsenceOf(String xpathOrCssSelector, Object... arguments) waitForAbsenceOf(org.openqa.selenium.By byLocator) waitForAllTextToAppear(String... expectedTexts) Waits for all of a number of text blocks to appear on the screen.voidwaitForAnyRenderedElementOf(org.openqa.selenium.By... expectedElements) waitForAnyTextToAppear(String... expectedText) Waits for any of a number of text blocks to appear anywhere on the screen.waitForAnyTextToAppear(org.openqa.selenium.WebElement element, String... expectedText) waitForPresenceOf(String xpathOrCssSelector, Object... arguments) waitForRenderedElements(org.openqa.selenium.By byElementCriteria) waitForRenderedElementsToBePresent(org.openqa.selenium.By byElementCriteria) waitForRenderedElementsToDisappear(org.openqa.selenium.By byElementCriteria) waitForTextToAppear(String expectedText) Waits for a given text to appear anywhere on the page.waitForTextToAppear(String expectedText, long timeout) Waits for a given text to appear anywhere on the page.waitForTextToAppear(org.openqa.selenium.WebElement element, String expectedText) Waits for a given text to appear inside the element.waitForTextToDisappear(String expectedText) waitForTextToDisappear(String expectedText, long timeoutInMilliseconds) Waits for a given text to not be anywhere on the page.waitForTextToDisappear(org.openqa.selenium.WebElement element, String expectedText) Waits for a given text to disappear from the element.longwaitForTitleToAppear(String expectedTitle) waitForTitleToDisappear(String expectedTitle) ThucydidesFluentWait<org.openqa.selenium.WebDriver>waitingForNoLongerThan(int timeout) Alternative to withTimeoutOf() using a DSLwaitingForNoLongerThan(int timeout, TimeUnit units) Alternative to withTimeoutOf()org.openqa.selenium.support.ui.WebDriverWaitorg.openqa.selenium.interactions.Actions<T extends PageObject>
TwithDriver(org.openqa.selenium.WebDriver driver) static String[]withParameters(String... parameterValues) withTimeoutOf(int timeout, TemporalUnit units) withTimeoutOf(int timeout, TimeUnit units) Deprecated.TimeUnit has been replaced by TemporalUnit in Selenium.withTimeoutOf(Duration timeout)
-
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
-
-
Method Details
-
setImplicitTimeout
-
resetImplicitTimeout
public void resetImplicitTimeout() -
setDriver
protected void setDriver(org.openqa.selenium.WebDriver driver, long timeout) -
setDriver
-
withDriver
-
getWaitForTimeout
-
getWaitForElementTimeout
Deprecated. -
getImplicitWaitTimeout
-
setPages
-
switchToPage
Deprecated. -
upload
Upload a file via an HTML form. By default, this will look for a file on the file system, at the location provided. -
uploadData
- Throws:
IOException
-
uploadData
- Throws:
IOException
-
setPageUrls
Only for testing purposes. -
setWaitForTimeout
public void setWaitForTimeout(long waitForTimeoutInMilliseconds) -
setWaitForElementTimeout
public void setWaitForElementTimeout(long waitForTimeoutInMilliseconds) -
getRenderedView
-
getClock
-
getDriver
public org.openqa.selenium.WebDriver getDriver() -
getTitle
-
matchesAnyUrl
public boolean matchesAnyUrl() -
compatibleWithUrl
Does this page object work for this URL? When matching a URL, we check with and without trailing slashes -
waitForRenderedElements
-
withTimeoutOf
Deprecated.TimeUnit has been replaced by TemporalUnit in Selenium. For more consistancy use a TemporalUnit parameter. -
withTimeoutOf
-
withTimeoutOf
-
waitingForNoLongerThan
Alternative to withTimeoutOf() -
waitingForNoLongerThan
Alternative to withTimeoutOf() using a DSL -
waitFor
-
waitFor
-
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
-
waitForPresenceOf
-
waitForRenderedElementsToDisappear
-
waitForAbsenceOf
-
waitForAbsenceOf
-
waitForTextToAppear
Waits for a given text to appear anywhere on the page. -
waitForTitleToAppear
-
waitOnPage
public org.openqa.selenium.support.ui.WebDriverWait waitOnPage() -
waitForTitleToDisappear
-
waitForTextToAppear
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
-
waitForTextToDisappear
Waits for a given text to not be anywhere on the page. -
waitForTextToAppear
Waits for a given text to appear anywhere on the page. -
waitForAnyTextToAppear
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
Waits for all of a number of text blocks to appear on the screen. -
waitForAnyRenderedElementOf
-
waitABit
protected void waitABit(long timeInMilliseconds) -
waitFor
-
thenReturnElementList
public List<org.openqa.selenium.WebElement> thenReturnElementList(org.openqa.selenium.By byListCriteria) -
shouldContainText
Check that the specified text appears somewhere in the page. -
shouldContainAllText
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
Clear a field and enter a value into it. -
enter
Clear a field and enter a value into it. This is a more fluent alternative to using the typeInto method. -
selectFromDropdown
-
selectMultipleItemsFromDropdown
public void selectMultipleItemsFromDropdown(org.openqa.selenium.WebElement dropdown, String... selectedLabels) -
getSelectedOptionLabelsFrom
-
getSelectedOptionValuesFrom
-
getSelectedValueFrom
-
getSelectedLabelFrom
-
setCheckbox
public void setCheckbox(org.openqa.selenium.WebElement field, boolean value) -
containsText
-
containsAllText
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
-
isRelative
-
open
Open the webdriver browser using a paramaterized URL. Parameters are represented in the URL using {0}, {1}, etc. -
openUnchecked
Opens page without checking URL patterns. Same as open(String...)) otherwise. -
open
-
open
-
openUnchecked
Opens page without checking URL patterns. Same asopen(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: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.@DefaultUrl("http://localhost:8080/client/list") public class ClientList extends PageObject { ... @WhenPageOpens public void waitUntilTitleAppears() {...} } -
openUnchecked
public final void openUnchecked()Opens page without checking URL patterns. Same asopen()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
-
openUrl
-
callWhenPageOpensMethods
public void callWhenPageOpensMethods()Override this method -
withParameters
-
openPageNamed
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
Returns true if at least one matching element is found on the page and is visible. -
setDefaultBaseUrl
-
hasFocus
public boolean hasFocus(org.openqa.selenium.WebElement webElement) Deprecated.Use element(webElement).hasFocus() insteadReturns true if the specified element has the focus. -
blurActiveElement
public void blurActiveElement() -
getJavascriptExecutorFacade
-
element
Provides a fluent API for querying web elements. -
$
-
$
-
$
-
$
-
$
-
textOf
Return the text value of a given element -
textOf
-
textOf
-
textOf
-
textContentOf
Return the text value of a given element -
textContentOf
-
textContentOf
-
textContentOf
-
$$
-
$$
-
element
Provides a fluent API for querying web elements. -
find
-
find
-
find
-
find
-
findBy
-
findNested
-
find
-
findNested
-
findFirst
-
findFirst
-
findEach
-
findEach
-
findEach
-
findEach
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
-
findNestedElements
-
findEach
-
findAll
-
findAll
-
findAll
-
element
Provides a fluent API for querying web elements. -
findBy
-
findFirst
-
findAll
-
containsElements
public boolean containsElements(org.openqa.selenium.By bySelector) -
containsElements
-
evaluateJavascript
-
evaluateJavascript
-
addJQuerySupport
public void addJQuerySupport() -
driverIsJQueryCompatible
protected boolean driverIsJQueryCompatible() -
inRadioButtonGroup
-
driverIsInstantiated
protected boolean driverIsInstantiated() -
waitForWithRefresh
-
waitForCondition
-
waitFor
-
waitFor
-
waitForElement
-
getAlert
public org.openqa.selenium.Alert getAlert() -
withAction
public org.openqa.selenium.interactions.Actions withAction() -
fluent
-
moveTo
-
moveTo
-
waitForAngularRequestsToFinish
public void waitForAngularRequestsToFinish() -
toString
-