运行第一个方案后(在每个挂接之后)CodeceptJS错误

时间:2018-06-20 12:56:16

标签: codeceptjs

我刚刚开始尝试 codeceptjs ,看看我们是否可以在项目中使用它。它看起来非常有用,但是我一直遇到一个讨厌的错误,我无法指出:-(

谁知道我该怎么做才能摆脱下面的错误? 我在MBP上使用量角器助手运行codeceptjs。

错误:

"after each" hook: finalize codeceptjs for "test something | {"page":"Test pagina CARDS-CC"}":
     no such alert
  (Session info: chrome=67.0.3396.87)
  (Driver info: chromedriver=2.40.565386 (45a059dc425e08165f9a10324bd1380cc13ca363),platform=Mac OS X 10.13.5 x86_64)

1 个答案:

答案 0 :(得分:1)

我也是CodeceptJS的新手,也发现了相同的错误。您可以在命令中添加--verbose开关以查看错误堆栈跟踪。

问题可能取决于您的帮助者,但就我而言,似乎Protractor会自动为每个执行的测试用例预测任何警报弹出窗口,并尝试自动将其关闭。如果未找到警报,则在异常字符串包含no alert open的情况下,它仅捕获引发的异常。问题在于检查错误消息。它似乎不匹配,因此引发了异常并且没有被跳过。

我的错误消息:

...
   [1] Error | NoSuchAlertError: no such alert
  (Session info: chrome=67.0.3396.87)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
   Emitted | test.failed ([object Object])
 × "after each" hook: finalize codeceptjs for "Sample test case 1" in 28ms
   [1] Error | NoSuchAlertError: no such alert
  (Session info: chrome=67.0.3396.87)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
NoSuchAlertError: no such alert
  (Session info: chrome=67.0.3396.87)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
   Emitted | suite.after ([object Object])

-- FAILURES:

  1) SampleTest1
       "after each" hook: finalize codeceptjs for "Sample test case 1":
     no such alert
  (Session info: chrome=67.0.3396.87)
  (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
  oSuchAlertError: no such alert
    (Session info: chrome=67.0.3396.87)
    (Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.17134 x86_64)
      at Object.checkLegacyResponse (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\selenium-webdriver\lib\error.js:546:15)
      at parseHttpResponse (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\selenium-webdriver\lib\http.js:509:13)
      at doSend.then.response (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\selenium-webdriver\lib\http.js:441:30)
      at process._tickCallback (internal/process/next_tick.js:68:7)
  From: Task: WebDriver.switchTo().alert()
      at thenableWebDriverProxy.schedule (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\selenium-webdriver\lib\webdriver.js:807:17)
      at TargetLocator.alert (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\selenium-webdriver\lib\webdriver.js:1862:29)
      at Protractor.grabPopupText (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\codeceptjs\lib\helper\Protractor.js:1066:52)
      at Protractor._after (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\codeceptjs\lib\helper\Protractor.js:247:31)
      at recorder.add (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\codeceptjs\lib\listener\helpers.js:21:69)


  FAIL  | 1 passed, 1 failed   // 8s
   Emitted | global.result ([object Object])
   Emitted | global.after ([object Object])

我查看了错误发生的源代码,发现预期的错误消息与实际的错误消息之间不匹配。

实际例外: NoSuchAlertError: no such alert

预期的异常消息: 'no alert open'

从堆栈跟踪的这一行获得它:

at Protractor.grabPopupText (C:\Users\user\AppData\Roaming\npm\node_modules\codeceptjs-protractor\node_modules\codeceptjs\lib\helper\Protractor.js:1066:52)`

代码:

async grabPopupText() {
    try {
      const dialog = await this.browser.switchTo().alert();

      if (dialog) {
        return dialog.getText();
      }
    } catch (e) {
      if (e.message.indexOf('no alert open') > -1) {
        // Don't throw an error
        return null;
      }
      throw e;
    }
  }

临时解决方法: 我只是在错误消息检查部分添加了no such alert,直到他们修复了该错误。

if (e.message.indexOf('no alert open') > -1 || e.message.indexOf('no such alert') > -1) {
        // Don't throw an error
        return null;
      }

希望这种快速的解决方法有所帮助。