我的剧作家UI测试(使用page,而不是request)工作得很好。只有API测试失败。例如,const response = await request.get('https://reqres.in/api/users/3')
我发现它一定是公司的代理,离开了公司的wifi,加入了我手机的热点,看到测试通过了。我玩过VSCode代理设置,但还没有找到修复超时的设置。当我使用npx playwright test --config=api.config.ts直接从根目录运行测试脚本时,它也会失败,所以我不认为它是VSCode。
错误消息(包含我的代码)如下,问题来自get方法。脚本超时,之后的代码从未尝试过。所有的API方法,例如get、post delete time都是类似的。
1) [chromium] › api.spec.ts:6:10 › API Testing › Simple API Test - Assert Response Status ========
apiRequestContext.get: read ETIMEDOUT
=========================== logs ===========================
→ GET https://reqres.in/api/users/3
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.5195.19 Safari/537.36
accept: */*
accept-encoding: gzip,deflate,br
============================================================
5 |
6 | test.only('Simple API Test - Assert Response Status', async ({ request }) => {
> 7 | const response = await request.get('https://reqres.in/api/users/3')
| ^
8 | console.log(response)
9 | //expect(response.status()).toBe(200)
10 |
at /Users/USERNAME/playwright-framework/tests/api/api.spec.ts:7:40发布于 2022-09-30 14:10:44
解决了。代理是在剧作家配置文件中设置的,以及其他更常见的配置项。如果需要,用户名和密码也可以在这里设置。
例如:
use: {
headless: false,
viewport: { width: 1280, height: 720 },
actionTimeout: 10000,
screenshot: 'only-on-failure',
ignoreHTTPSErrors: true,
proxy: { server: 'http://yourproxy.com:8080/' },
trace: 'off',
video: 'off'
},https://stackoverflow.com/questions/73870958
复制相似问题