Text
Resolves to the visible (i.e. not hidden by CSS) innerText
of:
- a given WebElement, represented by Answerable<Element>
a group of WebElements, represented by Answerable<ElementArray>
The result includes the visible text of any sub-elements, without any leading or trailing whitespace.
Examples:
<h1>Shopping list</h1>
<ul id="shopping-list">
<li>Coffee<li>
<li class="bought">Honey<li>
<li>Chocolate<li>
</ul>
import { actorCalled } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
import { BrowseTheWeb, by, Target, Text } from '@serenity-js/webdriverio';
const header = () =>
Target.the('header').located(by.tagName('h1'))
actorCalled('Lisa')
.whoCan(BrowseTheWeb.using(browser))
.attemptsTo(
Ensure.that(Text.of(header()), equals('Shopping list')),
)
import { actorCalled } from '@serenity-js/core';
import { Ensure, equals } from '@serenity-js/assertions';
import { BrowseTheWeb, by, Target, Text } from '@serenity-js/webdriverio';
const shoppingListItems = () =>
Target.the('shopping list items').located(by.css('#shopping-list li'))
actorCalled('Lisa')
.whoCan(BrowseTheWeb.using(browser))
.attemptsTo(
Ensure.that(
Text.ofAll(shoppingListItems()),
equals([ 'Coffee', 'Honey', 'Chocolate' ])
),
)
import { actorCalled } from '@serenity-js/core';
import { contain, Ensure } from '@serenity-js/assertions';
import { BrowseTheWeb, by, CSSClasses, Target, Text } from '@serenity-js/webdriverio';
const shoppingListItemCalled = (name: string) =>
Target.the('shopping list items').located(by.css('#shopping-list li'))
.where(Text, equals(name))
.first()
actorCalled('Lisa')
.whoCan(BrowseTheWeb.using(browser))
.attemptsTo(
Ensure.that(
CSSClasses.of(shoppingListItemCalled('Honey)),
contain('bought')
),
)
See also:
Static Method Summary
Static Public Methods | ||
public static |
of(element: Answerable<Element<'async'>>): Question<Promise<string>> & MetaQuestion<Answerable<Element<'async'>>, Promise<string>> Retrieves text of a single WebElement, represented by Answerable<Element>. |
|
public static |
ofAll(elements: Answerable<ElementArray>): Question<Promise<string[]>> & MetaQuestion<Answerable<Element<'async'>>, Promise<string[]>> Retrieves text of a group of WebElements, represented by Answerable<ElementArray> |
Static Public Methods
public static of(element: Answerable<Element<'async'>>): Question<Promise<string>> & MetaQuestion<Answerable<Element<'async'>>, Promise<string>> source
Retrieves text of a single WebElement, represented by Answerable<Element>.
Params:
Name | Type | Attribute | Description |
element | Answerable<Element<'async'>> |
See:
public static ofAll(elements: Answerable<ElementArray>): Question<Promise<string[]>> & MetaQuestion<Answerable<Element<'async'>>, Promise<string[]>> source
Retrieves text of a group of WebElements, represented by Answerable<ElementArray>
Params:
Name | Type | Attribute | Description |
elements | Answerable<ElementArray> |
Returns:
Question<Promise<string[]>> & MetaQuestion<Answerable<Element<'async'>>, Promise<string[]>> |