0 javascript automation cypress playwright
我希望将我的测试套件从 Cypress 迁移到 Playwright。当我处理 API 请求时遇到了障碍。
在我的测试套件中,我想等待网络请求完成并返回 200 响应,然后再进行下一个操作。
我的问题是网络请求 url 包含动态值,之前在 Cypress 中我将“*”作为通配符,Playwright 中的替代方案是什么?
我的代码中有以下 cy.intercept:
cy.intercept('GET',`${apiUrl}/employee/*/information`).as('GETemployeeInformation');
Run Code Online (Sandbox Code Playgroud)
在继续测试步骤之前,我在测试套件中使用 cy.wait 调用此拦截,我尝试使用以下内容在 Playwright 中复制此内容:
async isSignedIn() {
await this.page.waitForResponse(response => response.url().includes("/employee/*/information") && response.status() === 200);
}
Run Code Online (Sandbox Code Playgroud)
小智 8
这里给出的例子网络事件似乎非常接近 Cypress 模式。Playwright 中可能有更好的模式,但如果您要从 Cypress 转换为 Playwright,我会尝试这个。
// Use a glob URL pattern. Note no await.
const responsePromise = page.waitForResponse('**/api/fetch_data');
await page.getByText('Update').click();
const response = await responsePromise;
Run Code Online (Sandbox Code Playgroud)
由于 Playwright 中允许使用 glob 模式,我想知道您的问题是否来自于使用response.url()
进行匹配。在赛普拉斯,比赛是对阵request.url
not response.url
。
归档时间: |
|
查看次数: |
278 次 |
最近记录: |