// 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
}
}
终于,查出来了! 使用application.navigationBars["Navigation bar Name"].searchFields["Label of the textField / Search Bar"].value 这将从文本字段中提取值。需要注意的是,检索到的值将为**“any”**类型
Can anyone write the below code with objective-c?
// 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
}
}
3条答案
按热度按时间ldxq2e6h1#
您使用XCTest API方法提取了该值。
正确的方法可以在EarlGrey常见问题解答https://github.com/google/EarlGrey/blob/master/docs/faq.md中找到
cnh2zyt32#
终于,查出来了!
使用
application.navigationBars["Navigation bar Name"].searchFields["Label of the textField / Search Bar"].value
这将从文本字段中提取值。需要注意的是,检索到的值将为**“any”**类型
2guxujil3#