如何使用 UIVeri5 将文本写入 sap.m.Input?

How to write text into sap.m.Input with UIVeri5?

在为 SAP UI5 application with UIVeri5: How can I enter programmatically some text into an element of type sap.m.Input 编写测试时?我用方法 inputKeys 尝试了如下:

it("should enter some text", function() {

    let inputElement = element(by.control({
        viewName   : "com.example.myapp.View.main",
        controlType: "sap.m.Input"
    }));
    expect( inputElement ).toBeDefined(); // is okay

    inputElement.sendKeys("Some Text"); // fails!

    // ...
});

已找到元素,但语句 inputElement.sendKeys("Some Text") 失败并出现以下错误:

 Control Element sap.m.Input#__xmlview0--myInput has no dom representation

我在 Protractor 的 ElementFinder 中找不到任何其他似乎适合实现此目的的方法。

我为我的问题找到了 解决方法,即使用量角器方法 by.id() 通过其生成的 ID 引用 sap.m.Input 元素:

let inputElement = element( by.id("__xmlview0--myInput-inner") ); 

inputElement.sendKeys("Some Text"); // now it works

但是,我认为这是解决方法而不是解决方案,因为 UIVeri5's documentation 说 "Avoid ID Locators that Use Generated IDs"。

我发现将 interaction: "focus" 添加到选择器时有效:

let inputElement = element(by.control({
    viewName   : "com.example.myapp.View.main",
    controlType: "sap.m.Input",
    interaction: "focus" // this is new!
}));

inputElement.sendKeys("Some Text"); // works

另请参阅 UIVeri5 文档中的 section on "Interaction Adapters"