在我的测试中,我有一个带有预先存在的文本的文本字段.我想删除内容并键入新字符串.
let textField = app.textFields
textField.tap()
// delete "Old value"
textField.typeText("New value")
Run Code Online (Sandbox Code Playgroud)
用硬件键盘删除字符串时没有为我生成记录.用软件键盘做同样的事后我得到了:
let key = app.keys["Usu?"] // Polish name for the key
key.tap()
key.tap()
... // x times
Run Code Online (Sandbox Code Playgroud)
要么
app.keys["Usu?"].pressForDuration(1.5)
Run Code Online (Sandbox Code Playgroud)
我担心我的测试是依赖于语言的,所以我为我支持的语言创建了类似的东西:
extension XCUIElementQuery {
var deleteKey: XCUIElement {
get {
// Polish name for the key
if self["Usu?"].exists {
return self["Usu?"]
} else {
return self["Delete"]
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
它在代码中看起来更好:
app.keys.deleteKey.pressForDuration(1.5)
Run Code Online (Sandbox Code Playgroud)
但它非常脆弱.从模拟器退出后Toggle software keyboard重置,我有一个失败的测试.我的解决方案不适用于CI测试.如何解决这个问题更加普遍?
在Xcode的UI测试,我怎么insertText了UIView符合UIKeyInput?
我创建了一个CodeInputView符合的UIKeyInput。
当我记录自己手动输入代码时,Xcode会写app.typeText("1234")。
但是,当我尝试播放该错误时,出现错误UI Testing Failure-元素和任何后代都不具有键盘焦点。而且,该问题的解决方案均无效。
我正在测试向我的应用程序添加评论,在我的其他 UI 测试中,我使用了该typeText功能并且一切正常。我还单击了“连接硬件键盘”关闭。应用程序终止测试并显示错误 UI 测试失败 - 在 addComment 方法期间,元素和任何后代都没有键盘焦点。有任何想法吗?
func testAddComment() {
let featuredPage = self.app.tabBars["Featured"]
if featuredPage.exists {
featuredPage.tap()
}
sleep(2)
let featuredOffer = self.app.tables.cells.elementBoundByIndex(1)
if featuredOffer.exists {
featuredOffer.tap()
}
sleep(2)
let addComment = self.app.staticTexts["Add a comment"]
if addComment.exists {
addComment.tap()
addComment.typeText("Test comment")
}
sleep(2)
let postComment = self.app.buttons["Send"]
if postComment.exists {
postComment.tap()
}
sleep(2)
}
Run Code Online (Sandbox Code Playgroud) 所以我以编程方式在我的视图中添加了一个子视图,当我这样做时,我将所有可访问性参数附加到它:
[labelView setAccessibilityLabel:@"label"];
[labelView setIsAccessibilityElement:YES];
[labelView setUserInteractionEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
但是当我像这样查询UI时:
let app = XCUIApplication()
app.staticTexts["label"]
Run Code Online (Sandbox Code Playgroud)
测试失败,因为它无法找到视图.
知道如何处理这个问题,如何为UI测试提供动态添加的视图?