0

我正在使用 EarlGrey 框架,我想选择整个文本并从文本字段或搜索栏中捕获它。有没有办法做到这一点?

提前致谢!

4

2 回答 2

1

您使用 XCTest APIs 方法提取了该值。

正确的方法可以在 EarlGrey FAQ https://github.com/google/EarlGrey/blob/master/docs/faq.md中找到

// Swift
//
// Must use a wrapper class to force pass by reference in Swift 3 closures.
// inout params cannot be modified within closures. http://stackoverflow.com/a/28252105
open class Element {
  var text = ""
}

/*
 *  Example Usage:
 *
 *  let element = Element()
 *  domainField.performAction(grey_replaceText("hello.there"))
 *             .performAction(grey_getText(element))
 *
 *  GREYAssertTrue(element.text != "", reason: "get text failed")
 */
public func grey_getText(_ elementCopy: Element) -> 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
    }
}
于 2020-02-28T13:11:10.720 回答
0

终于,发现了!

使用application.navigationBars["Navigation bar Name"].searchFields["Label of the textField / Search Bar"].value

这从文本字段中获取了值。需要注意的一件事是,检索到的值将是“任何”类型

于 2019-12-16T11:59:20.153 回答