如何在 UI 测试中获取对 TextField 的引用 Xcode 7
How to obtain reference to TextField in UI Tests in Xcode 7
我正在尝试在 Xcode 7 beta 中使用 UI 测试。
我有一个带有两个文本字段的故事板。两个文本字段都有出口和不同的恢复 ID。我记录了测试,但生成的代码非常难读且无法运行:
app.otherElements.containingType(.TextField, identifier:"y").childrenMatchingType(.TextField).elementBoundByIndex(0).typeText("hello")
我还尝试了以下方法,是否会基于占位符文本工作?!?
app.textFields["PlaceholderText"].typeText("hello")
在 UI 测试中获取对 TextField 的引用的正确方法是什么?
您需要在故事板中为该特定文本字段设置辅助功能标识符。检查下图:
因此您可以像这样使用可访问性标识符查询 textField :
let app = XCUIApplication()
app.launch()
let nameTextField = app.textFields["nameTextField"]
nameTextField.tap()
nameTextField.typeText("Hello John")
我正在尝试在 Xcode 7 beta 中使用 UI 测试。 我有一个带有两个文本字段的故事板。两个文本字段都有出口和不同的恢复 ID。我记录了测试,但生成的代码非常难读且无法运行:
app.otherElements.containingType(.TextField, identifier:"y").childrenMatchingType(.TextField).elementBoundByIndex(0).typeText("hello")
我还尝试了以下方法,是否会基于占位符文本工作?!?
app.textFields["PlaceholderText"].typeText("hello")
在 UI 测试中获取对 TextField 的引用的正确方法是什么?
您需要在故事板中为该特定文本字段设置辅助功能标识符。检查下图:
因此您可以像这样使用可访问性标识符查询 textField :
let app = XCUIApplication()
app.launch()
let nameTextField = app.textFields["nameTextField"]
nameTextField.tap()
nameTextField.typeText("Hello John")