return 特定元素 属性 的 GREYActionBlock 不工作
GREYActionBlock to return specific element property not working
我正在按照 标题下的 Swift 示例进行操作,有没有办法将 return 特定元素 从 FAQ 到尝试从元素中检索 属性。
我直接从FAQ上复制了例子,但是调用performAction后,textValue还是原来的值。事实上,无论我在操作块中将 inout 参数设置为什么,一旦操作 returns.
,变量就会保留其原始值
我错过了什么?这是我的代码:
func grey_getText(inout text: String) -> GREYActionBlock {
return GREYActionBlock.actionWithName("get text",
constraints: grey_respondsToSelector(Selector("text")),
performBlock: { element, errorOrNil -> Bool in
text = element.text
print("in block: \(text)")
return true
})
}
并且在测试方法中:
var textValue = ""
let domainField = EarlGrey().selectElementWithMatcher(grey_text("Floor One"))
domainField.assertWithMatcher(grey_sufficientlyVisible())
domainField.performAction(grey_getText(&textValue))
print("outside block: \(textValue)")
打印
in block: Floor One
outside block:
我正在使用 XCode 版本 7.3.1
检查此拉取请求中的代码以正确实现 grey_getText。
https://github.com/google/EarlGrey/pull/139
EarlGrey 团队知道文档已过时,我们正在研究解决方案。
func incrementer(inout x: Int) -> () -> () {
print("in incrementer \(x)")
func plusOne() {
print("in plusOne before \(x)")
x += 1;
print("in plusOne after \(x)")
}
return plusOne
}
var y = 0;
let f = incrementer(&y)
print("before \(y)")
f();
print("after \(y)")
虽然我们希望 y 在执行结束时为 1,但 y 仍为 0。这是实际输出:
in incrementer 0
before 0
in plusOne before 0
in plusOne after 1
after 0
这是因为in-out参数不是“call-by-reference", but "call-by-copy-restore”。正如 bootstraponline 指向的 PR 指定的那样。
我正在按照 标题下的 Swift 示例进行操作,有没有办法将 return 特定元素 从 FAQ 到尝试从元素中检索 属性。
我直接从FAQ上复制了例子,但是调用performAction后,textValue还是原来的值。事实上,无论我在操作块中将 inout 参数设置为什么,一旦操作 returns.
,变量就会保留其原始值我错过了什么?这是我的代码:
func grey_getText(inout text: String) -> GREYActionBlock {
return GREYActionBlock.actionWithName("get text",
constraints: grey_respondsToSelector(Selector("text")),
performBlock: { element, errorOrNil -> Bool in
text = element.text
print("in block: \(text)")
return true
})
}
并且在测试方法中:
var textValue = ""
let domainField = EarlGrey().selectElementWithMatcher(grey_text("Floor One"))
domainField.assertWithMatcher(grey_sufficientlyVisible())
domainField.performAction(grey_getText(&textValue))
print("outside block: \(textValue)")
打印
in block: Floor One
outside block:
我正在使用 XCode 版本 7.3.1
检查此拉取请求中的代码以正确实现 grey_getText。 https://github.com/google/EarlGrey/pull/139
EarlGrey 团队知道文档已过时,我们正在研究解决方案。
func incrementer(inout x: Int) -> () -> () {
print("in incrementer \(x)")
func plusOne() {
print("in plusOne before \(x)")
x += 1;
print("in plusOne after \(x)")
}
return plusOne
}
var y = 0;
let f = incrementer(&y)
print("before \(y)")
f();
print("after \(y)")
虽然我们希望 y 在执行结束时为 1,但 y 仍为 0。这是实际输出:
in incrementer 0
before 0
in plusOne before 0
in plusOne after 1
after 0
这是因为in-out参数不是“call-by-reference", but "call-by-copy-restore”。正如 bootstraponline 指向的 PR 指定的那样。