【问题标题】:WDIO. How to make expect compare result between two options?WDIO。如何使两个选项之间的期望比较结果?
【发布时间】:2021-12-15 13:29:59
【问题描述】:

我有网站 - https://the-internet.herokuapp.com/notification_message_rendered 点击按钮,在网站上方随机出现“操作成功/n×”或“操作失败,请重试\n×”的通知。 如果通知文本是“操作成功/n×”或“操作不成功,请重试\n×”,我如何让 wdio 期望比较此通知的文本并通过测试? 这是我的代码,我还将 Chai 期望导入为“expectChai”以方便自己:

it("test comparing", async function() {
  await browser.url("https://the-internet.herokuapp.com/notification_message_rendered")

  const but = await $("p > a")
  await but.click()
  const t = await $("#flash-messages > div")
  await t.waitForDisplayed()
  const tx = await t.getText()


   await expectChai(tx).to.be.equal("Action successful\n×" || "Action unsuccesful, please try again\n×")})

【问题讨论】:

    标签: node.js webdriver-io


    【解决方案1】:

    不严格回答您的问题,但这样做可能会有所帮助: 你得到t.getText() 并检查它是否与你的元素匹配文本。

    expect("Action successful\n×, Action unsuccesful, please try again\n×").to.contains(tx)

    【讨论】:

      【解决方案2】:

      这是测试随机值的坏习惯。 不过好吧,对我来说最好的选择是:

      const messages = ["Action successful\n×", "Action unsuccesful, please try again\n×"]
      expectChai(tx).to.be.oneOf(messages)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-01-16
        • 2012-05-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-10-04
        相关资源
        最近更新 更多