0

我是这个框架的新手。您能否帮我让多个元素的文本与 UI 上的相同匹配器匹配。

4

1 回答 1

1

您可以使用以下函数获取元素的文本

open class GreyElement {
    var text = ""
}

func grey_getText(_ elementCopy: GreyElement) -> GREYActionBlock {
    return GREYActionBlock.action(withName: "get text",
                              constraints: grey_respondsToSelector(#selector(getter: UILabel.text))) { element,
                                errorOrNil -> Bool in
                                let elementObject = element as? NSObject
                                let text = elementObject?.perform(#selector(getter: UILabel.text),
                                                                  with: nil)?.takeRetainedValue() as? String
                                elementCopy.text = text ?? ""
                                return true
    }
}

然后在您的测试代码中:

var label = GreyElement()

for i in 0..<100 {
    EarlGrey.selectElement(...).perform(grey_getText(text))
    XCTAssert(label.count > 10)
}

XCTest 版本:

for element in app.staticText[...].allElementsBoundByIndex {
    XCTAssert(element.label.count > 10)
}
于 2019-09-23T17:17:36.763 回答