单击提交按钮时,我使用下一个代码检查请求和响应:
const postRequestInfo = await Promise.all([
page.waitForRequest(
request =>
request.url() === 'https://httpbin.org/status/200' && request.method() === 'POST'
),
page.waitForResponse(
response =>
response.url() === 'https://httpbin.org/status/200' && response.status() === 200
),
page.click('[data-hook="async-button__post-submit-btn"]')
]);
在请求待处理时是否可以测试元素的属性?
因此,我想在发送请求后执行这段代码,但尚未收到响应:
expect(
await page.$eval('[data-hook="async-button__post-submit-btn"]', el =>
el.disabled)
).toEqual(true)
答案 0 :(得分:0)
我发现了这个!我应该使用page.on
page.on('request', async interceptedRequest => {
if (
interceptedRequest.url() === 'https://httpbin.org/status/200' &&
interceptedRequest.method() === 'POST'
) {
expect(
await page.$eval('[data-hook="async-button__post-submit-btn"]', el => el.disabled)
).toEqual(true);
}
interceptedRequest.continue();
});