Try to understand what the code does:
const {
Before
} = require('cucumber');
const {AfterAll} = require('cucumber');
module.exports = function () {
Before(function () {
browser.manage().window().maximize();
/// await browser.manage().deleteAllCookies();
});
AfterAll(async function () {
return driver.quit();
});
}
Here you creates a function but never calls the function.
you can make it work in three ways:
First Approach: Call the function and pass the object to module.exports
const {
Before
} = require('cucumber');
const {AfterAll} = require('cucumber');
//store function to a variable
let hooks = function () {
Before(function () {
browser.manage().window().maximize();
/// await browser.manage().deleteAllCookies();
});
AfterAll(async function () {
return driver.quit();
});
}
//call the function and pass it to module.exports
module.exports = hooks();
Second Approach: Create self-invoking function
const {
Before
} = require('cucumber');
const {AfterAll} = require('cucumber');
module.exports = (function () {
Before(function () {
browser.manage().window().maximize();
/// await browser.manage().deleteAllCookies();
});
AfterAll(async function () {
return driver.quit();
});
})();
Third Approach: create an object using object literal instead of creating a function and calling it ( This what you have done as the fix )
const {
Before
} = require('cucumber');
const {AfterAll} = require('cucumber');
module.exports = {
Before(function () {
browser.manage().window().maximize();
/// await browser.manage().deleteAllCookies();
});
AfterAll(async function () {
return driver.quit();
});
};