WebdriverJs & Mocha in Selenium 3

In upgrading to Selenium 3 we realized that the test hooks that WebdriverJs provides into Mocha are no longer compatible.

We used to do this:

test.before( 'Clear cookies (log out)', function() {
  driverManager.clearCookiesAndDeleteLocalStorage( driver );
  driver.navigate().refresh();
} );

which fails with a generic error message:

TypeError: Cannot read property 'call' of undefined

It turns out you can no longer pass a description to the WebdriverJs/Mocha hooks (test.before, test.after etc.)

So, you’ll need to just do this:

test.before( function() {
  driverManager.clearCookiesAndDeleteLocalStorage( driver );
  driver.navigate().refresh();
} );

which provides less meaningful output when things fail unfortunately.

You can add a comment to the code to describe what the hook is doing:

// Clear cookies (log out)
test.before( function() {
  driverManager.clearCookiesAndDeleteLocalStorage( driver );
  driver.navigate().refresh();
} );

Do you use these WebdriverJs/Mocha hooks? What did you do?

Author: Alister Scott

Alister is an Excellence Wrangler for Automattic.