skip to Main Content

I am writing a cypress test case where I need to get the value of requirement id under results using either JS/TS/Cypress but I can’t find any way.
enter image description here

I found these posts and articles but they are not relevant to what I am trying to get.

2

Answers


  1. I’m a bit unclear about your specific intent, but if I’ve grasped it correctly, there are multiple approaches outlined in the Cypress documentation to achieve this. It involves utilizing the intercept command to spy on the request URL then get and print or test the response as you want by giving it a callback function or also define is with as() then use it when ever you want.
    you can check this link its much detailed there
    https://docs.cypress.io/api/commands/intercept

    Login or Signup to reply.
  2. As mentioned, you can read the documentation about cypress intercept. To give an example of how you can grab a value from the network response, here’s some snippet:

    cy.intercept("GET", "*/tableformat*").as("getTable");
    cy.get("<insert your locator here>").click() // whatever action that triggers the tableformat response
    cy.wait("@getTable").its("body").then( res => { 
      const requirementId = res.results[0].requirementId
      // then do whatever you want with the variable
    })
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search