How to test that staticTexts contains a string using XCTest

前端 未结 4 1821
走了就别回头了
走了就别回头了 2021-02-07 04:19

In Xcode UI testing, how do I test that staticTexts contains a string?

In the debugger, I can run something like this to print out all the content of staticTexts:

4条回答
  •  没有蜡笔的小新
    2021-02-07 04:25

    You can use NSPredicate to filter elements.

      let searchText = "the content of the staticText"
      let predicate = NSPredicate(format: "label CONTAINS[c] %@", searchText)
      let elementQuery = app.staticTexts.containing(predicate)
      if elementQuery.count > 0 {
        // the element exists
      }
    

    With CONTAINS[c] you specify that the search is case insensitive.

    Have a look at Apples Predicate Programming Guide

提交回复
热议问题