安装
yarn create playwright || pnpm create playwright
//package.json
"scripts": {
"playwright": "playwright test",
"playwright:UI": "playwright test --ui"
//...
}
之后新建立一个测试文件 index.spec.ts
放入默认测试文件夹 test
。
API
test
test('title', async()=>{ //测试用例
//...
})
test(title, details, body) //宣布进行测试
test.after('测试回调', async()=>{ //在测试之后运行的钩子
//...
})
test.afterEach('测试回调', async()=>{}) //在文件中的每个测试之后运行
test.afterAll('测试回调', async()=>{}) //在所有测试之后运行的钩子
test.before('测试回调', async()=>{}) //在测试之前运行的钩子
test.beforeEach('测试回调', async()=>{}) //文件中的每个测试之前运行
test.beforeAll('测试回调', async()=>{}) //在所有测试之前运行的钩子
test.describe('测试用例集', async()=>{ //声明一组测试
test('测试用例', async()=>{})
})