Xcode没有检测到正在键入的文本(UI测试)

时间:2016-05-11 16:47:57

标签: ios xcode xcode-ui-testing ui-testing

确定,

所以我正在运行一个UI测试,我在那里学习。在测试中有一段代码,我选择一个文本字段,点击"清除文字"按钮,输入一些文字然后点击"完成"在键盘上:

XCUIElement *textField = [app.tables.cells.textFields element];
XCTAssertTrue(textField.exists, "Text field couldn't be found");

// Clear the text field
[textField.buttons[@"Clear text"] tap];
XCTAssertTrue([textField.value length] == 0, @"The text field wasn't cleared.");

// Type in new data
[textField typeText:@"New Device"];
XCTAssertTrue([textField.value length] > 0, @"The text field is empty.");
NSString *textFieldValue = textField.value;
XCTAssertTrue([textFieldValue isEqualToString:@"New Device"], @"Strings do not equate.");

// Save
[app.keyboards.buttons[@"Done"] tap];

似乎这应该是一个简单的测试,但我遇到了一些问题:

  1. 运行测试时,虽然我告诉它键入" New Device"由于某种原因,它总是键入"现在设备"用小写" n"。检查文本字段值的XCTAssert语句总是会失败,除非我指示文本键入"现在设备",它没有问题(WTF!?)。
  2. 点击" Done"按钮,只有单词" now"留在文本区域。单词" Device"完全没有了。这是一个问题,因为引擎盖下的代码检查字符串是否至少为5个字符。
  3. 由于Xcode中没有关于UI测试的大量文档,所以我已经知道了。任何帮助将不胜感激。

0 个答案:

没有答案