I've hooked up some automated tests for my Vuejs project by adding this plugin to my project.
The Vuejs app was created using the vue-cli.
It all works fine and Playwright seems to be a very powerful automation library.
So I'm trying to write a Mocha root hook plugin which runs once before all of the tests. That looks something like this:
hooks.js
const playwright = require("playwright");
export const mochaHooks = {
beforeAll() {
const browser = await playwright["chromium"].launch({
headless: false
});
const context = await browser.newContext();
await page.goto("https://localhost:44392/");
await page.fill("#Username", "demokitchenadmin");
await page.fill("#Password", "Test1234)");
await page.click("button.btn-primary");
await context.storageState({ path: 'state.json' });
await page.close();
await context.close();
await browser.close();
}
};
I'm not sure how to integrate this with my Vuejs project.
I have tried to add the --require
flag (doco) so that the test command looks like this (in package.json
):
"scripts": {
...
"test:e2e": "vue-cli-service test:e2e --require './tests/e2e/hooks.js",
},
Unfortunately, this does not successfully run the code in that hooks.js
file.
Can anybody nudge me in the right direction. Cheers