Text assertion (textIs, textContains, ...)

in Japanese(日本語)

Checks on an element's label (its displayed text).

The target is always "the element grabbed last" — selectors are not passed to these commands. First grab the element with select (or exist / tap / etc.), then verify it. The following three forms mean exactly the same thing, with the same recorded steps and the same number of device round trips:

select("#msg").textIs("Done")             // chain onto the return value
select("#msg"); lastElement.textIs("Done") // explicit lastElement
select("#msg"); textIs("Done")             // implicit (the last grabbed element)

Arguments are (expected, requireVisible:, strict:, waitSeconds:) for the positive forms and (expected, strict:, waitSeconds:) for the negative forms, and (strict:, waitSeconds:) for the empty forms (textMatchesDateFormat takes no strict: — see the table below). There is no form that takes a selector — textIs("#msg", "Done") does not compile.

In the implicit form (e.g. textIs("…") without lastElement), a string that is # followed only by letters/digits, or that contains || / >>, is treated as a mistyped selector and fails before running. To expect such a string, use the chained form (select("#tag").textIs("#swift")).

Functions

function negation comparison
select(selector).textIs(expected, requireVisible:, strict:, waitSeconds:) textIsNot(expected, strict:, waitSeconds:) exact match
textContains(expected, requireVisible:, strict:, waitSeconds:) textContainsNot(expected, strict:, waitSeconds:) substring match
textStartsWith(expected, requireVisible:, strict:, waitSeconds:) textStartsWithNot(expected, strict:, waitSeconds:) prefix match
textEndsWith(expected, requireVisible:, strict:, waitSeconds:) textEndsWithNot(expected, strict:, waitSeconds:) suffix match
textMatches(pattern, requireVisible:, strict:, waitSeconds:) textMatchesNot(pattern, strict:, waitSeconds:) regular expression (substring; use ^…$ for a full match)
textMatchesDateFormat(format, requireVisible:, waitSeconds:) — DateFormatter format string, e.g. "yyyy/MM/dd"
textIsNotEmpty(strict:, waitSeconds:) textIsEmpty(strict:, waitSeconds:) non-empty / empty

All of the above are chainable on the return value of exist / select, and each also has an implicit form (a free function that takes no selector; the same arguments as the chained form) that acts on the last grabbed element.

Example

select("#msg").textIs("Done")

exist("#total")
    .textStartsWith("Total")
    .textEndsWith("USD")

Notes