【问题标题】:Closing toastr in webdriver在 webdriver 中关闭 toastr
【发布时间】:2018-08-02 06:23:31
【问题描述】:

UI 自动化测试 我的应用程序周围都有 toast 消息,有时我会收到多个 toasts,这会阻止单击应用程序的其他部分。这意味着我必须先关闭它们才能与其他按钮交互。 我写了一个 if else 语句来关闭它们。当只有一个时它起作用。当吐司超过 2 次时,它会失败。

谁能告诉我我错过了什么?

closeToastMessage() {
  let close_toast = $$('.toast-close-button');
  const closeToasts = $$('.toast-close-button');
  let toast_exist = browser.waitForExist('.toast', 5000);

  if (close_toast.value) {
    close_toast.click();
    browser.waitUntil(function() {
      return close_toast.waitForExist(5000, true);
    }, 5000, 'expecte toast to disappear');
  } else if (closeToasts.length) {
    for (let i = 0; i < closeToasts.length; i++) {
      closeToasts[i].click();
      browser.waitUntil(() => {
        return !closeToasts[i].isVisible();
      }, 5000, `Close toast ${i} still visible after 5 s`, 1000);
    } else {
      throw new Error('Oops! toast did NOT disappear');
    }
  }
}

【问题讨论】:

  • 有一个preventDuplicates 选项。尝试将其设置为true

标签: javascript automation webdriver webdriver-io toastr


【解决方案1】:

有一个preventDuplicates 选项。尝试将其设置为true

结帐的其他选项。

toastr.options = {
  "closeButton": true,       // Allow force-closing 
  "newestOnTop": false,      // Keep the oldest one up-front
  "preventDuplicates": true, // Do not allow duplicates to appear
  "showDuration": 300,      // Time it take to show up, 0.3 sec default
  "hideDuration": 1000,     // Time it take to hide, 1 sec default
  "timeOut": 5000,          // Duration it is displayed, 5 sec default
  "extendedTimeOut": 1000   // Time it takes to hide if hovered, 1 sec default
}

查看他们的demo

【讨论】:

  • 谢谢,但这是针对前端开发人员的。我在询问使用 webdriver io 进行 UI 测试。我没有能力更改代码以防止重复。此外,它不一定是重复的,因为在每个操作上你都会得到一个 toast
猜你喜欢
  • 2015-06-11
  • 1970-01-01
  • 2016-02-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多