我跟在標題下的Swift示例有沒有辦法從FAQ返回特定元素以嘗試從元素中檢索屬性。GREYActionBlock返回特定的元素屬性不起作用
我直接從FAQ中複製了示例,但在調用performAction之後,textValue仍然具有其原始值。事實上,無論我在動作塊中設置inout參數,變量都會在動作返回時保留其原始值。
我錯過了什麼?下面是我的代碼有:
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
這似乎與你使用塊的方式有關,如果你將'GREYActionBlock.actionWithName(...'直接賦值給var並使用它(而不是調用函數'grey_getText '得到它)? – Gautam