https://cypress.io logo
And as we speak about environment variables... I'v...
# e2e-testing
e
And as we speak about environment variables... I've found some documentation about storing hardcoded environment variables (the one I've linked above to juanrepo), but I would like to do something similar, yet not with a variable I've hardcoded before but with a variable that will be set based on response from intercepted api request (I want to save one parameter from the response and reuse later). Please, just, bear in mind I'm new to Cypress, javascript, typescript (which I'm obliged to use instead of classic js) and even coding in general, so I might be missing basic concepts So, after hours of struggling I've managed to intercept a value from one parameter (applicationId) in order to use it later in cypress request event (cy.request function) but only with .then function
Copy code
cy.intercept("POST", "**/application").as("startApplication");
  cy.get("@startApplication")
    .its("response")
    .then((response) => {
      const applicationId = response.body.applicationId;
      cy.request({
        method: "POST",
        url: `${apiBaseUrl}/e2e/application/${applicationId}`,
      });
    });
However, I need to use this applicationId few more times during my e2e tests in order to call other api endpoints later... I don't want to redo the same thing each time, meaning cy.get + .then (cy.request). I would like to do cy.request right off the bat with this applicationId I already managed to get... btw, for what I care it doesn't have to be an environmental variable, it might be alias, const or whatever that would let me nicely reuse that applciationId later 🙂