2024-04-11 | 使用指南 | UNLOCK | 更新时间:2024-4-11 9:22

Playwright的测试及遇到的问题

安装

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()=>{})
})

简单示例

问题集合