【问题标题】:How can i use nightwatch with async/await functionality?如何使用具有异步/等待功能的守夜人?
【发布时间】:2019-04-24 15:47:52
【问题描述】:

我正在使用 nightwatch 测试框架来测试 <input /> 的某些功能,但它在比赛问题上失败了。

我需要测试什么

  1. 为输入文本添加一个值:xxxx
  2. backspace 4 次。
  3. 断言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


    【解决方案1】:

    第一行代码不需要await吗?

    await searchBox.waitForElementVisible("@input")
    .click("@input")
    .setValue("@input",'xxxx');
    

    我认为它与正在输入的字符并行退格四次,其中两个是在发送最后一个退格后输入的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-15
      • 1970-01-01
      • 2023-04-08
      • 1970-01-01
      • 1970-01-01
      • 2019-04-22
      相关资源
      最近更新 更多