New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Staying logged, not log out after every test #603
Comments
You're likely just need to change the way you're thinking about this. For instance, if your have 30 links in the nav, you likely have 30 different pages to test for. You should likely have 30 different spec files, each starting out in a It doesn't make sense to have a single test to cover all 30 links if they're all being tested independently. You also likely don't need to click into each link. You should just test that the HTTP request is successful. A test for this could be as simple as this: cy.get("nav a").each(($a) => {
// pluck out the href for each anchor link
const href = $a.prop("href")
// make a programatic request to it
// which will fail if not 2xx response code
cy.request(href)
}) Doing this kind of thing starts to get close to being anti-patterns in Cypress because we don't really suggest using it as a tool for link spidering. There are much better alternative tools optimized specifically for this task. That's why I originally suggested you likely don't need a single test that does this - instead write feature specs for each individual feature you're trying to test for and just visit them each in a Last note - don't use your UI to login, you should create a programatic custom command to login to your app which will drastically reduce the time it takes to reach the page you're trying to test. https://docs.cypress.io/guides/getting-started/testing-your-app.html#Logging-In |
Thanks for the really extensive and fast response ! |
@brian-mann I have created login command for my usecase which essentially sets cookie and logs the test user in. I run that command in before hook but it asks to login every time. How can I fix it? Also, I have before and beforeEach hooks in the same test. sorry, instead of opening up an issue i am reusing this thread. |
@samyakshah this doc talks about how to use beforeEach(function () {
// before each test, we can automatically preserve the
// 'session_id' and 'remember_token' cookies. this means they
// will not be cleared before the NEXT test starts.
//
// the name of your cookies will likely be different
// this is just a simple example
Cypress.Cookies.preserveOnce('session_id', 'remember_token')
}) |
I am not using cookies, but using localStorage to set token. How to preserve local Storage? |
@praneetha-ck-robo There's an issue open for this #461 |
@JohnnyFun That was the solution to my issue. Thanks for posting! |
@JohnnyFun |
Heya,
currently after each tests I have writen the cycle refreshes and it goes back to root.
I need to log in the site I am testing and navigate to the page that should be tested every single time, instead of simply staying logged and just start from there.
For an example: I am testing if all the links in the navbar are working properly, I find the link, click it and check if the url is the right one. Then script needs to log in again in order to test the next link (currently they are 30, so you get the point)
I assume there is a way, I just cannot find/think of it.
If anyone has an expirience or an idea, please share it. Thanks !
The text was updated successfully, but these errors were encountered: