【发布时间】:2019-04-24 15:47:52
【问题描述】:
我正在使用 nightwatch 测试框架来测试 <input /> 的某些功能,但它在比赛问题上失败了。
我需要测试什么
- 为输入文本添加一个值:
xxxx。 - 按
backspace4 次。 - 断言
input的值为''。
但我知道input 的值为xx:
错误:Expected element <#inputElement> to have value equal: "" - expected "equal ''" but got: "xx"
"type 4 chars and use backspace to clear the input": browser => {
searchBox.waitForElementVisible("@input")
.click("@input")
.setValue("@input",'xxxx');
for (let i = 0; i < 4; i++) {
await browser.keys(browser.Keys.BACK_SPACE);
}
searchbox.expect.element("@input").value.to.equal("");
searchbox.click("@input");
searchbox.expect.element("@input").value.to.equal("");
browser.end();
},
由此得出的结论是,for 循环在 input 被清除之前执行,然后继续进行断言。我用async/await 尝试了同样的测试,但我又遇到了同样的错误。我错过了什么吗?
我像这样使用 async/await 测试它:
"type 4 chars and use backspace to clear the input": async browser => {
searchBox.waitForElementVisible("@input")
.click("@input")
.setValue("@input",'xxxx');
for (let i = 0; i < 4; i++) {
await browser.keys(browser.Keys.BACK_SPACE);
}
await searchbox.click("@input");
await searchbox.expect.element("@input").value.to.equal("");
await browser.end();
},
欢迎任何帮助。
【问题讨论】:
标签: javascript reactjs unit-testing testing nightwatch.js