I am implementing a mocha test script to login and logout a specific webpage and my purpose is to make this test script modular.
Actually my main test script like the following;
describe('Test is being started for user : ' +
currentUserInfo.email , function () {
it('Login Test', async function () {
await loginTest(page, currentUserInfo.email,
currentUserInfo.password);
});
it('Logout Test', async function () {
await logoutTest(page);
});
});
And the logintest.js like the following;
module.exports = function(page, userName, userPass){
before (async function () {
});
after (async function () {
console.log("Login test is finished");
})
describe('Login Test is being started for user : ' +
userName , function () {
it('Enter Email', async function () {
await page.focus('#username_box')
await page.keyboard.type(userName)
});
it('Enter Password', async function () {
await page.focus('#password_box')
await page.keyboard.type(userPass)
});
it('Click "Login in Here" button', async
function () {
await page.click('input[value="Log in
Here"]'); // With type
await page.waitForNavigation();
});
};
In the main test runtime the logoutTest function doesn't wait to finish the loginTest. Also, I have tried to use Promise object but in this case, my scripts don't run that under the LoginTest.
module.exports = async function(page, userName, userPass){
return new Promise(resolve => {
before (async function () {
});
after (async function () {
console.log("Login test is finished");
resolve(10);
})
describe('Login Test is being started for user : ' +
userName , function () {
it('Enter Email', async function () {
await page.focus('#username_box')
await page.keyboard.type(userName)
});
it('Enter Password', async function () {
await page.focus('#password_box')
await page.keyboard.type(userPass)
});
it('Click "Login in Here" button', async function () {
await page.click('input[value="Log in Here"]'); // With type
await page.waitForNavigation();
});
});
});
};
thanks