Bar*_*zyk 117 xcode ios swift ios9 xcode-ui-testing
这是我的情况:
let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.tap()
passwordSecureTextField.typeText("wrong_password") //here is an error
Run Code Online (Sandbox Code Playgroud)
UI测试失败 - 元素和任何后代都没有键盘焦点.元件:
怎么了?这对正常工作很好textFields,但只会出现问题secureTextFields.任何解决方法?
小智 193
这个问题给我带来了痛苦的世界,但我已经设法找到了一个合适的解决方案.在模拟器中,确保"硬件 - >键盘 - >连接硬件键盘"已关闭.
Ale*_*sov 17
最近我们发现了一个黑客从接受的答案持久化解决方案.要禁用模拟器设置:'硬件 - >键盘 - >连接硬件键盘'从命令行应该写:
defaults write com.apple.iphonesimulator ConnectHardwareKeyboard 0
Run Code Online (Sandbox Code Playgroud)
它不会影响正在运行的模拟器 - 您需要重新启动模拟器或启动新模拟器才能使该设置生效.
Ole*_*ndr 14
我写了一个小扩展(Swift),对我来说非常适合.这是代码:
extension XCTestCase {
func tapElementAndWaitForKeyboardToAppear(element: XCUIElement) {
let keyboard = XCUIApplication().keyboards.element
while (true) {
element.tap()
if keyboard.exists {
break;
}
NSRunLoop.currentRunLoop().runUntilDate(NSDate(timeIntervalSinceNow: 0.5))
}
}
}
Run Code Online (Sandbox Code Playgroud)
主要思想是在键盘出现之前继续点击元素(文本字段).
Rya*_*ske 11
斯坦尼斯拉夫有正确的想法.
在团队环境中,您需要能够自动运行的东西.我想出了一个修复这里在我的博客.
基本上你只需粘贴:
UIPasteboard.generalPasteboard().string = "Their password"
let passwordSecureTextField = app.secureTextFields["password"]
passwordSecureTextField.pressForDuration(1.1)
app.menuItems["Paste"].tap()
Run Code Online (Sandbox Code Playgroud)
导致此错误的另一个原因是,如果您试图输入被设置为可访问性元素(view.isAccessibilityElement = true)的文本,则在文本字段的父视图中进行操作。在这种情况下,XCTest无法获得子视图上的句柄以输入文本并返回错误。
UI测试失败-元素或任何后代都不具有键盘焦点。
并不是没有元素具有焦点(您经常会在UITextField中看到键盘向上和光标闪烁),而是它可以到达的任何元素都没有焦点。尝试在UISearchBar中输入文本时遇到了这个问题。搜索栏本身不是文本字段,将其设置为可访问性元素时,将阻止对基础UITextField的访问。为了解决这个问题,searchBar.accessibilityIdentifier = "My Identifier"是在设置UISearchBar但是isAccessibilityElement未设置为true。之后,请测试以下形式的代码:
app.otherElements["My Identifier"].tap()
app.otherElements["My Identifier"].typeText("sample text")
Run Code Online (Sandbox Code Playgroud)
作品
就我而言,这Hardware -> Keyboard -> Connect Hardware Keyboard->禁用对我不起作用。
但是当我跟着
1) Hardware -> Keyboard -> Connect Hardware Keyboard->启用并运行应用程序
2) Hardware -> Keyboard -> Connect Hardware Keyboard->禁用。
它对我有用
小智 5
func pasteTextFieldText(app:XCUIApplication, element:XCUIElement, value:String, clearText:Bool) {
// Get the password into the pasteboard buffer
UIPasteboard.generalPasteboard().string = value
// Bring up the popup menu on the password field
element.tap()
if clearText {
element.buttons["Clear text"].tap()
}
element.doubleTap()
// Tap the Paste button to input the password
app.menuItems["Paste"].tap()
}
Run Code Online (Sandbox Code Playgroud)
在启动应用程序和在文本字段中输入数据之间进行睡眠,如下所示:
sleep(2)
Run Code Online (Sandbox Code Playgroud)
就我而言,我每次都会不断收到此错误,只有这种解决方案帮助了我。
| 归档时间: |
|
| 查看次数: |
21396 次 |
| 最近记录: |