【发布时间】:2020-01-24 21:55:25
【问题描述】:
如何测试焦点是否在输入字段上?
我尝试这样做: 在我的 .po.ts 中
getEditInputField(fieldName: string) {
return $(`input[data-e2e=${fieldName}]`)
}
在我的 .spec.ts 中
it("should focus the Abschlag input field", async () => {
expect(await budgetBilling.getEditInputField("Abschlag").isSelected()).toBe(true)
})
但是如果我像.toBe(false) 那样测试测试,量角器在两种情况下都会让测试通过。但在toBe(false) 的情况下应该会失败。
然后我找到了这个解决方案: protractor: test for focus of field
并像这样使用它:
it("should focus the Abschlag input field", async () => {
// await browser.waitForAngular()
expect(await budgetBilling.getEditInputField("Abschlag").getAttribute('id')).toEqual(await browser.driver.switchTo().activeElement().getAttribute('id'))
})
测试按预期通过。但是,如果我将其更改为 getEditInputField("something") 并且“某事”也是同一表单上的输入字段,但未选择/聚焦,则测试也通过了。但在这种情况下它应该失败。
而waitForAngular() 是否包含似乎并不重要。
我是不是做错了什么,或者有人知道如何在量角器中测试某个字段是否被选中/聚焦?
【问题讨论】:
标签: angular protractor