小编Mur*_*can的帖子

在 Cypress 测试中,如果预期的 XHR 请求未发出,如何重试按钮单击:带有单击 XHR 条件的 waitUntil()?

在非常高的级别上,我们单击一个命令建筑物控制点的按钮;打开或关闭灯。单击应该向服务器发送 POST 请求。问题是有时单击按钮但 POST 请求不会发出。该按钮没有指示它是否已被单击的功能(小幅增强)。

目前,我想使用 Cypress 插件waitUntil()来解决这个问题。

    // define routes
    cy.server();
    cy.route('POST', '\*\*/pointcommands').as('sendCommand');

    // setup checkFunction for cy.waitUntil()
    const waitForPost200 = () => cy.wait('@sendCommand', {timeout: 10000}).then(xhr => cy.wrap(xhr).its('status').should('eq', 200));

    // setup jQuery for cy.pipe()
    const click = $el => $el.click();

    // click the button
    cy.get('.marengo-ok')
      .should('be.visible')
      .pipe(click);
      // need to pass in a synchronous should() check so that the click is retried. How can we achieve this with waitUntil ?

    // wait until checkFunction waitForPost200() returns truthy …
Run Code Online (Sandbox Code Playgroud)

javascript xmlhttprequest wait cypress

2
推荐指数
1
解决办法
9182
查看次数

标签 统计

cypress ×1

javascript ×1

wait ×1

xmlhttprequest ×1