Ronald Pieterse
Ronald Pieterse

Reputation: 11

CodeceptJS Error after running first scenario (after each hook)

I just started trying out codeceptjs to see if we can use it in our project. It looks extremely useful, however I keep running into one nasty error which I can not pinpoint :-(

Who knows what I have to do to get rid of the error below? I run codeceptjs with the protractor helper, on my MBP.

The error:

"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)

Upvotes: 1

Views: 1918

Answers (1)

Czerald
Czerald

Reputation: 11

I'm new to CodeceptJS as well and found this same error. You can add a --verbose switch to your command to see the error stacktrace.

The problem may depend on your helper but in my case, it seems that Protractor automatically anticipates any alert popups for every test case executed and tries to close it automatically. If there are no alerts found, it just catches the exception thrown to it if the exception string contains no alert open. The problem lies with the checking of the error message. It appears to have been mismatched and therefore the exception was raised and has not been skipped.

My error message:

...
   [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])

I looked at the source codes where the error went off and saw that there is a mismatch between the anticipated error message and the actual error message.

Actual Exception: NoSuchAlertError: no such alert

Anticipated Exception message: 'no alert open'

Got it from this line in the stack trace:

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

Code:

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

Temporary workaround: I just added no such alert in the error message checking part until they fix this bug.

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

Hope this quick workaround helps.

Upvotes: 1

Related Questions