mardi 25 février 2020

Can I switch on cy.wait() timeout instead of it asserting a fail?

I have a cypress test which is highlighting an issue with a cold start lambda. However, having proven the issue, I want the test to pass, handling the cold-start and retrying, until the cold-start issue is resolved.

If I could make cy.wait() not throw a failure assertion (therefore not stopping the test) I could switch on the status of the xhr response to try in x amount of time. e.g.;

context("upload trades", () => {
    specify("handling cold-start delay", () => {
      // attempt system action which will "warm up" cold lambdas
      cy.uploadTradeForTomorrow("validTrade_CME_to_KochCE");

      // implicitly wait for timeout to occur when posting trade list
      cy.wait("@postTradeLists").then(request => {
        // handle cold start
        if (request.status !== 200) {
          cy.log(
            "non-200 response; assuming cold start, adding delay and trying again"
          );
          cy.wait(30000);

          // refresh page to re-load Trade Uploads page
          // given lambda's now hot
          cy.visit("/");

          cy.uploadTradeForTomorrow("validTrade_CME_to_KochCE");

          // wait for second post, anticipating 200 response (hot-start)
          cy.wait("@postTradeLists");
        }
      });

      // check file uploaded successfully
      cy.contains("File uploaded successfully").should("be.visible");
      cy.get("button")
        .contains("OK")
        .should("be.enabled");
    });
  });

However, this currently fails on the line cy.wait("@postTradeLists") when 504 response (or more likely, the 30000ms timeout) resolves from the server.

Is there a way to do this that I am not aware of? Excessive googling is yielding no results. Thank you.

Aucun commentaire:

Enregistrer un commentaire