XCUIElement#typeText对于两个文本字段失败

问题描述 投票:0回答:1

我在Xcode 11.1上观察到XCUITest的奇怪行为。我只有一个带有两个UITextField的情节提要,两个UITextFields都具有一个可访问性标识符集。我要在两个文本框中输入文字:

    class ExampleUITests: XCTestCase {  

        func testTypingInTextField() {  
            let app = XCUIApplication()  
            app.launch()  

            let field1 = app.textFields["Field1"]  
            field1.tap()  
            field1.typeText("foo")  

            let field2 = app.textFields["Field2"]  
            field2.tap()  
            field2.typeText("bar")  
        }  

    }  

在第二个字段中键入第二个字段失败,出现以下错误,并且光标在第二个文本字段中闪烁:

    Failed to synthesize event: Neither element nor any descendant has keyboard focus. Event dispatch snapshot: TextField, label: 'Field2'  
    Element debug description:  
    Attributes: TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2'  
    Element subtree:  
     →TextField, 0x600000cde760, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2'  
    Path to element:  
     →Application, 0x600000cddf80, pid: 50581, label: 'CO2Rechner'  
      ↳Window (Main), 0x600000cddea0, {{0.0, 0.0}, {375.0, 667.0}}  
       ↳Other, 0x600000cddce0, {{0.0, 0.0}, {375.0, 667.0}}  
        ↳Other, 0x600000cdddc0, {{0.0, 0.0}, {375.0, 667.0}}  
         ↳Other, 0x600000cdf020, {{0.0, 0.0}, {375.0, 667.0}}  
          ↳Other, 0x600000cde920, {{10.0, 30.0}, {355.0, 76.0}}  
           ↳TextField, 0x600000cde760, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2'  
    Query chain:  
     →Find: Target Application 'com.example.CO2Rechner'  
      Output: {  
        Application, pid: 50581, label: 'CO2Rechner'  
      }  
      ︎Find: Descendants matching type TextField  
        Output: {  
          TextField, {{10.0, 30.0}, {355.0, 34.0}}, label: 'Field1', value: foo  
          TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2'  
        }  
        ︎Find: Elements matching predicate '"Field2" IN identifiers'  
          Output: {  
            TextField, {{10.0, 72.0}, {355.0, 34.0}}, label: 'Field2'  
          }  

如果我删除要在field1中键入的代码,它将起作用。

我上传了example project here

我在这里想念什么?

ios xctest
1个回答
0
投票
模拟器中的[[“硬件»擦除所有内容和设置””解决了该问题。Beta可能还剩一些。
© www.soinside.com 2019 - 2024. All rights reserved.