Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Maximum call stack size exceeded – Cypress

I am trying to run a test, from first, it will get x-auth-token and I am storing that token within txt file, and then getting that token and storing in my commands.js file, like this:

Cypress.Commands.add("getAllNoteIDs", () => {
  let notes_ids = [];
  cy.readFile("cypress/user_data/token.txt").then((token) => {
    cy.log("Token is "+token)
  }) // Here I am getting correct token
  cy.request({
    method: "GET",
    url: "https://practice.expandtesting.com/notes/api/notes",
    form: true,
    failOnStatusCode: false,
    timeout: 30000,
    headers: {
      accept: "application/json",
      "x-auth-token":
      cy.readFile("cypress/user_data/token.txt").then((token) => {
        cy.log(token)
      }),
    },
  }).then((response) => {
    cy.log(response)
    const responseBodyKeys = Cypress._.keys(response.body);
    cy.log(responseBodyKeys)
    cy.log(response.body['message'])
    let results = response.body.data;
    for (let i of results) {
      notes_ids.push(i.id);
    }
    cy.wrap(notes_ids);
  });
});

Whenever I ran this command, I am getting following error:
enter image description here
enter image description here

But, if I directly add token there, it runs fine. I don’t want to follow that practice.
What’s the solution for this.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

x-auth-token type is promise

"x-auth-token": 
  cy.readFile("cypress/user_data/token.txt").then((token) => {
    cy.log(token)
  })

change code

cy.readFile("cypress/user_data/token.txt").then((token) => {
  cy.request({
    method: "GET",
    url: "https://practice.expandtesting.com/notes/api/notes",
    form: true,
    failOnStatusCode: false,
    timeout: 30000,
    headers: {
      accept: "application/json",
      "x-auth-token": token // use token
    },
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading