typescript - 测试报告 - 忽略 auth.setup.ts 测试
有没有一个注解可以在报告中忽略 'authenticate' 测试。
如果需要更多信息,请告诉我。我正在通过 playwright.config 文件调用 'authenticate' 测试,即作为 'setup' 的依赖,并将认证信息保存在 'storageState' 的 user.json 文件中。
示例:
import { test as setup } from '@playwright/test';
const authFile = 'playwright/.auth/user.json';
setup('authenticate', async ({ request }) => {
// Send authentication request. Replace with your own.
await request.post('https://github.com/login', {
form: {
'user': 'user',
'password': 'password'
}
});
await request.storageState({ path: authFile });
});
报告的图像显示有 2 个测试而不是 1 个
我创建了一个函数调用(而不是“测试作为设置”)来在导出默认的 defineConfig 之前打开浏览器,以将用户的浏览器认证信息初始化到 user.json 中。但我不断遇到文件未找到的问题,因为 defineConfig 文件在“storageState: ...”中引用了 user.json。
我已经阅读了与注解、状态配置、全局设置和清理相关的 Playwright 文档,但我似乎找不到任何方法可以从报告页面中移除这个测试报告。
我在考虑解析报告并移除那个测试,但我不太确定这种方法是否可行。
感谢您查看此事,如需更多信息请告诉我。
答案#1
你之所以把它作为测试,是因为你把它当作测试来用。测试结果会出现在报告中。
import { test as setup } from '@playwright/test';
setup('authenticate', async ({ request }) => {
尝试使用钩子 - beforeAll、beforeEach 或在全局设置中实现 Auth
