lundi 25 février 2019

Mocha test does not execute `before()` & `after()` hooks

in this mocha test the describe function itself gets executed, however the before & after hooks do not work for some reason. I have tried numerous of things however nothing works. ( managed to make the it() hook work only by executing it's parameter 'done' as a function)

const { Builder, By, until, promise } = require('selenium-webdriver');
const { describe, it, before, after, beforeEach } = require('mocha');
const { assert } = require('chai');
const URL =
  'SOMEURLHERE';

(function runTests() {
  let driver;

  describe(`Selenium Mocha test`, function() {
    before(function(done) {
      console.log('Before works :)');
      done();
    });

    before(function() {
      console.log('before');
      driver = await new Builder().forBrowser('chrome').build();
    });

    it(`Logo is present in the page`, async done => {
      console.log('in it');
      await driver.get(URL);
      await driver
        .findElement(By.className('logo'))
        .isDisplayed()
        .then(res =>
          assert.equal(res, true, 'Logo is not present in the page !')
        );

      done();
    });

    afterEach('Close existing instances of web drivers', () => {
      driver.quit();
    });
  });
})();

Aucun commentaire:

Enregistrer un commentaire