How to verify value contains multiple strings in XCUITest

268 views Asked by At

In an XCUITest (UI test), is it possible to find a label that has three substrings in it?

For example, if I wanted to find a label with "contentsA", "contentsB", and "contentsC" in it, is there a wild card or some other way

I tried this

let labelValue = "contentsA with blah blah blah contentsB with blah blah contentsC"

let a = app.staticTexts.containing("contentsA")
let b = app.staticTexts.containing("contentsB")
let c = app.staticTexts.containing("contentsC")

Assert(a && b && c)

But this didn't work as expected.

1

There are 1 answers

3
Lou Franco On

You can pass an NSPredicate to containing, which would allow more complex querying

Something like this:

app.staticTexts.containing(NSPredicate(format: 
  "label CONTAINS 'contentsA' AND label CONTAINS 'contentsB' AND label CONTAINS 'contentsC'"))