https://cypress.io logo
cy.session to make a login into a backend system
# i-need-help
r
the problem I am facing is when I save my credentials for login using sessions as the image below: enter image description here everything looks good but the issue is on the IT brackets with the endpoint url: enter image description here result that this endpont url is the url once you are logged into the backend system but as you see this url changes everytime you make a new logging causing cypress cannot access. So dont know how to solve this problem: enter image description here /(S(xxxxxxxxxxx))/ in the URL this part is the one that changes
e
You probably need to work with your engineering team to understand how that id is generated. If it's available from an API call then you can intercept that call and store the id in a
Cypress.env
variable. Then you can use the stored variable in your visit string making the call always dynamic for each session.
Copy code
// Understand how the id is generated and if it's availabe through an API call after authentication
// Intercept call and store it in an env var
login.getLogin.click()
cy.wait("@someEndpoint").then(((body) => {
    Cypress.env('myId', body.rsp.id)
})
Then in your test
Copy code
// Use the same env var in your test, as an example
cy.visit(`http://yourwebsite${Cypress.env('myId')}/loader`)
Start with your engineering team first and then I'd look into documentation if you have further questions https://docs.cypress.io/api/commands/intercept https://docs.cypress.io/api/cypress-api/env