在Cypress.io中使用await结合promisify遇超时错误求助
Cypress中使用cypress-promise的promisify搭配await在cy.each中触发超时错误
我在Cypress测试代码中尝试结合await与cypress-promise库的promisify方法,代码如下:
import promisify from 'cypress-promise'; describe('My First Test', () => { it('Does not do much!', async() => { const url = "https://rahulshettyacademy.com/seleniumPractise/#/"; cy.visit(url); cy.get(".search-keyword").type("ca"); cy.wait(2000); cy.get(".products").find(".product").should("have.length", 4); cy.get(".products").find(".product").each(async($el, index, list) => { const element = cy.wrap($el); const txtElement = await promisify(element.find(".product-name")); }); }) })
执行到const txtElement = await promisify(element.find(".product-name"));这一行时,出现如下错误:
CypressError: cy.each() timed out after waiting 4000ms. Your callback function returned a promise that never resolved. The callback function was: () => { const ret = fn.call(ctx, el, index, subject); // if the return value is false then return early if (ret === false) { endEarly = true; } return ret; } at <unknown> (https://rahulshettyacademy.com/__cypress/runner/cypress_runner.js:139277:83) From previous event: at thenFn (https://rahulshettyacademy.com/__cypress/runner/cypress_runner.js:139276:13) at yieldItem (https://rahulshettyacademy.com/__cypress/runner/cypress_runner.js:139662:16) From previous event: at Context.each (https://rahulshettyacademy.com/__cypress/runner/cypress_runner.js:139667:62) at wrapped (https://rahulshettyacademy.com/__cypress/runner/cypress_runner.js:157859:19) From Your Spec Code: at eval (webpack:///./cypress/integration/examples/Test1.spec.ts:14:41) at step (https://rahulshettyacademy.com/__cypress/tests?p=cypress\integration\examples\Test1.spec.ts:129:23) at Object.eval [as next] (https://rahulshettyacademy.com/__cypress/tests?p=cypress\integration\examples\Test1.spec.ts:110:53) at eval (https://rahulshettyacademy.com/__cypress/tests?p=cypress\integration\examples\Test1.spec.ts:104:71) at new Promise (<anonymous>) at ./cypress/integration/examples/Test1.spec.ts.__awaiter (https://rahulshettyacademy.com/__cypress/tests?p=cypress\integration\examples\Test1.spec.ts:100:12) at Context.eval (webpack:///./cypress/integration/examples/Test1.spec.ts:4:26)
使用环境版本信息:
- Cypress版本:11.2.0
- cypress-promise版本:^1.1.0
- Node版本:18.12.1
- 操作系统:Windows 10 Pro - 21H2 - OS Build 19044.2311
内容的提问来源于stack exchange,提问作者AMendis
相关产品推荐
相关产品推荐

