代码之家  ›  专栏  ›  技术社区  ›  Samuel Jenks

wait()找不到以前触发的别名路由

  •  0
  • Samuel Jenks  · 技术社区  · 6 年前

    使用CypressJS,我已经为一个网站创建了端到端的测试,并在PowerShell中启动了这些测试。对于某些缺乏知识的情况,当使用 wait()时,别名路由并不像我预期的那样。

    core of cypress test issue:

    cy.route(“http://localhost:8000/admin/portfolio/putstegy”)。
    .as(“更新策略”)
    
    cy.get(“按钮”)
    .包含(“上传”)
    。单击()。
    
    cy.wait(“@updatestategy”)。
    

    日志:

    我期待通过按钮单击启动的请求匹配wait()to match on the request initiated by the button click.我现在得到的是一个成功的请求响应,似乎是在测试能够赶上之前的所有响应。

    from the docs:

    每次我们使用cy.wait()作为别名时,cypress都会等待下一个nth匹配请求。

    我对这句话的理解是,wait()will match on the request,who's execution order number matches the waities execution order number,relative to the same address.

    请求可能超时,响应可能超时。在这种情况下,找不到与等待号码匹配的请求。

    如何使用Cypress等待以编程方式调用的请求?wait()功能。

    柏树测试核心问题:

    cy.route("http://localhost:8000/admin/portfolio/putstrategy")
        .as("updatestrategy")
    
    cy.get("button")
        .contains("Upload")
        .click()
    
    cy.wait("@updatestrategy")
    

    enter image description here

    From the docs:

    Each time we use cy.wait() for an alias, Cypress waits for the next nth matching request.

    2 回复  |  直到 5 年前
        1
  •  1
  •   Brendan    6 年前

    cy.route("/admin/portfolio/putstrategy").as("updatetrategy")

    cy.server() cy.route()

        2
  •  1
  •   Marcellino Ornelas    5 年前

    cy.route("POST", "/admin/portfolio/putstrategy").as("updatetrategy")