Enum Class PageFunctions
- All Implemented Interfaces:
Serializable
,Comparable<PageFunctions>
,Constable
A utility class to handle Page
object.
Methods in this class return a function whose parameter is a Page
object of Playwright.
It is common to see a situation, where a single method call to a page object cannot determine a single element to be returned.
In such a case, you can use functions provided by LocatorFunctions
in combination.
new Click(PageFunctions.locatorBySelector("#js-sidebar-opener").andThen(LocatorFunctions.byText(sideMenuItem)))
This is an example to find a locator, which is specified by a text sideMenuItem
under a locator specified by a selector
string #js-sidebar-opener
.
In general methods in this class are named in the following manner.
{typeName}By{SelectionMethod}
typeName
can be, for instance, locator
, linkLocator
.
SelectionMethod
can be Name
, Text
, Label
, Selector
, etc.
Functions returned by methods in this class can be pretty printed on a call of toString
method call.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Method Summary
Modifier and TypeMethodDescriptionstatic Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> buttonLocatorByName
(String name) Returns a function that resolve a locator to a button object in aPage
, whose name is equal toname
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByExactText
(String text) Returns a function that gives a locator of a link whose text equals to a giventext
inside aPage
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByName
(String name) Returns a function that resolves a locator specified byname
in a givenPage
object.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByName
(String name, boolean lenient) Returns a function that resolves a givenname
to a locator of a link whose name matches with it.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByText
(String text) Returns a function that gives a locator of a link whose text contains a giventext
inside aPage
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByText
(String text, boolean lenient) static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByLabel
(String label) Returns a function that resolves a locator whose label matches withlabel
in a givenPage
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByLabel
(String label, boolean lenient) Returns a function that resolves a locator whose label matches withlabel
in a givenPage
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByPlaceholder
(String placeholder) Returns a function that resolves a locator whose placeholder isplaceholder
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorBySelector
(String selector) Returns a function that resolves a locator specified byselector
in a givenPage
.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByText
(String text) Returns a function that resolves a locator whose text containstext
in a given page.static Function
<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByText
(String text, boolean lenient) Returns a function that resolves a locator which matchestext
in a givenPage
object.toTitle()
Returns a function that gives a title of the given page.static PageFunctions
Returns the enum constant of this class with the specified name.static PageFunctions[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
linkLocatorByName
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByName(String name) Returns a function that resolves a locator specified by
name
in a givenPage
object.This is a shorthand method for
linkLocatorByName(name, false)
.- Parameters:
name
- A name of a link.- Returns:
- A function that resolves a locator specified by
name
in a givenPage
object.
-
linkLocatorByName
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByName(String name, boolean lenient) Returns a function that resolves a givenname
to a locator of a link whose name matches with it.- Parameters:
name
- A name of a link locator to be matched.lenient
-true
- partial match /false
- exact match.- Returns:
- A function that resolves a given
name
to a locator of a link whose name matches with it.
-
locatorByText
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByText(String text) Returns a function that resolves a locator whose text containstext
in a given page.- Parameters:
text
- A text to be contained by the matching locator.- Returns:
- a function that resolves a locator whose text contains
text
in a given page.
-
locatorByText
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByText(String text, boolean lenient) Returns a function that resolves a locator which matches
text
in a givenPage
object. Iflenient
istrue
, a locator whose text contains it is considered matched. Iflenient
isfalse
, a locator whose text equals totext
is considered matched.The match is done by:
Page#GetByText(text, new Page.GetByTextOptions().setExact(!lenient)
- Parameters:
text
- A text to be matched.lenient
-true
- lenient /false
- strict.- Returns:
- A function that resolves a locator which matches
text
in a givenPage
object.
-
buttonLocatorByName
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> buttonLocatorByName(String name) Returns a function that resolve a locator to a button object in aPage
, whose name is equal toname
.- Parameters:
name
- A string to be matched with a locator's name.- Returns:
- A function that resolve a locator to a button object in a
Page
, whose name is equal toname
.
-
locatorByLabel
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByLabel(String label) Returns a function that resolves a locator whose label matches withlabel
in a givenPage
.- Parameters:
label
- A string to be matched with a label of a locator.- Returns:
- A function that resolves a locator whose label matches with
label
.
-
locatorByLabel
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByLabel(String label, boolean lenient) Returns a function that resolves a locator whose label matches with
label
in a givenPage
.The resolution is done by a following method-call.
Page#getByLabel(label, new Page.GetByLabelOptions().setExact(!lenient))
If
lenient
is set totrue
, a locator whose label containslabel
will be considered matched. If it isfalse
, a locator whose label is equal tolabel
will be considered matched.- Parameters:
label
- A string to be matched with a label of a locator.lenient
-true
- lenient /false
- strict.- Returns:
- a function that resolves a locator whose label matches with
label
in a givenPage
.
-
locatorByPlaceholder
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorByPlaceholder(String placeholder) Returns a function that resolves a locator whose placeholder isplaceholder
.- Parameters:
placeholder
- A string to be matched with a locator's placeholder.- Returns:
- A function that resolves a locator whose placeholder is
placeholder
.
-
locatorBySelector
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> locatorBySelector(String selector) Returns a function that resolves a locator specified byselector
in a givenPage
.- Parameters:
selector
- A selector string that specifies a locator.- Returns:
- A function that resolves a locator specified by
selector
in a givenPage
.
-
linkLocatorByText
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByText(String text) Returns a function that gives a locator of a link whose text contains a giventext
inside aPage
.- Parameters:
text
- A string to be matched with a text of a link in a givenPage. @return A function that gives a locator of a link whose text matches a given
textinside a
Page`.
-
linkLocatorByExactText
public static Function<com.microsoft.playwright.Page, com.microsoft.playwright.Locator> linkLocatorByExactText(String text) Returns a function that gives a locator of a link whose text equals to a giventext
inside aPage
.- Parameters:
text
- A string to be matched with a text of a link in a givenPage. @return A function that gives a locator of a link whose text equals to a given
textinside a
Page`.
-
toTitle
-
linkLocatorByText
-