1

我刚开始尝试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)
4

1 回答 1

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;
      }

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

于 2018-06-20T20:52:10.783 回答