【发布时间】:2021-07-04 07:00:44
【问题描述】:
我通过将this plugin 添加到我的项目中,为我的 Vuejs 项目连接了一些自动化测试。
Vuejs 应用是使用 vue-cli 创建的。
一切正常,Playwright 似乎是一个非常强大的自动化库。
所以我正在尝试编写一个 Mocha 根挂钩插件,该插件在所有测试之前运行一次。看起来像这样:
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();
}
};
我不确定如何将它与我的 Vuejs 项目集成。
我试图添加--require 标志(doco),以便测试命令看起来像这样(在package.json 中):
"scripts": {
...
"test:e2e": "vue-cli-service test:e2e --require './tests/e2e/hooks.js",
},
很遗憾,这并没有成功运行 hooks.js 文件中的代码。
谁能把我推向正确的方向。 干杯
【问题讨论】:
标签: vue.js automated-tests vue-test-utils playwright