The following method works if that text takes only one line:
public void screen_heading_should_be(String scrheading) {
Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(ldriver)
.withTimeout(Duration.ofSeconds(10))
.pollingEvery(Duration.ofSeconds(1));
fluentWait.until(ExpectedConditions.textToBe(AppiumBy.id("screen_heading"), scrheading));
}
How do you wait for the exact text that takes two (or more) lines on the UI?
The text I'm waiting for:
"Please set your course
preferences to proceed."
scrheading is the one-line string ("Please set your course preferences to proceed.") that's present in my Step Definitions' Gherkin step (Cucumber), so, it has to be a user-friendly one-line string. Plus, texts in my app can even be on three and more lines, depending on the phone device's screen size/resolution (mobile UI automation).
I was thinking about applying this: screen_heading.getText().replaceAll("\\r\\n|\\r|\\n", " "), but it's a string which is not accepted by the 'ExpectedConditions' from above. 'By' is required instead.