.toHaveText(text)
Asserts elements or alerts have text matching text
.
Usage
expect(value).toHaveText(text)
Parameters
text
(String
): Text to compare against.options
(Object?
): Options for.getText
when asserting an element.
Returns
Promise
: A promise that resolves if the assertion is successful.
Support
Platform | Supported |
---|---|
iOS | Yes |
Android | Yes |
Web | Yes |
Examples
Element text:
const { element, by, expect } = require("appdriver");
(async () => {
const $text = await element(by.label("text"))
return expect($text).toHaveText("Hello World!");
})();
Input text:
const { element, by, expect } = require("appdriver");
(async () => {
const $input = await element(by.label("text-input"))
return expect($input).toHaveText("Hello World!");
})();
Button (nested text):
const { element, by, expect } = require("appdriver");
(async () => {
const $button = await element(by.label("button"))
return expect($button).toHaveText("Press Me!", { recursive: true });
})();
Alert:
const { alert, expect } = require("appdriver");
(async () => {
await expect(alert).toHaveText([
"Alert",
"Hello World!"
].join("\n"));
})();