Cypress Sessions Experimental Feedback #17887
Replies: 19 comments 43 replies
-
It's excellent, the api is very intuitive by describing the users actions and not the technical end result. So far the functionality has worked for me flawlessly as well. However I'm not keen on the presentation. The sessions part describes clearly what session was used and you have the ability to clear sessions 👍. But when a test kicks off, it runs through the session first and it's often at odds with what you're expecting the test to do. I would like to see a clearer visual indication that cypress is building a session first, perhaps by:
In addition when the test is finished, the session detail is recorded under the "Test body", whilst that is technically correct I consider sessions to be somewhat of a "setup to the test". I feel like it should be recorded under the "Session tab", it just needlessly clutters the test body to me. Really, a big thank you for the work on this though. It's greatly simplified some of the boilerplate user actions that couldn't be articulated well. |
Beta Was this translation helpful? Give feedback.
-
All easy-peasy using cypress-data-session
…Sent from my iPhone
On Sep 30, 2021, at 13:05, Roman Khomitskyi ***@***.***> wrote:
To visit /user/12/contract/12/display=true
You will have to grab user id and contract id from database and only then build up url
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
I was very happy to find an use cy.session(), because my user creation and login process involves sending an email with a magic link and creating and using a two-factor authenticator. It's not a simple set of API commands to create a user and login with a password. Unfortunately, I quickly hit #17710, finding out that session data is not cached across specs. Is there a reason for that, or is it a bug? Based on some of the discussion leading up to the creation of cy.session (e.g. #686 and #2951 (comment)) that this new session api would be a way to speed up tests by storing session data across tests. |
Beta Was this translation helpful? Give feedback.
-
Hi all, I've been trying to get some kind of cookie storage working for the better part of this evening. I finally stumbled upon all those tickets saying This is a very condensed example (I tried it with the official https://docs.cypress.io/api/commands/session#Updating-an-existing-login-helper-function version first). And yes the whole login procedure itself works just fine. it("successful login", () => {
cy.session("login", () => {
cy.visit("/");
cy.get("#id_login").type("loginname");
cy.get("#id_password").type("loginpassword");
cy.get(`input[type="submit"]`).click();
cy.url().should("eq", "http://localhost:8000/");
cy.hash().should("eq", "");
})
cy.visit("/")
}); Am I understanding it correctly and should i expect the final And I tried any possible way I could think of but it feels like no matter what I do, When I watch the cookies in the browser I see them being consistent until the new Please help ❤️ PS: newest Cypress 8.6.0 and Chrome 94. |
Beta Was this translation helpful? Give feedback.
-
Hello @jennifer-shehane , thank you for getting back to me, this is the result. as you can see, the thank you |
Beta Was this translation helpful? Give feedback.
-
First of all sessions are awesome, I played with them a little more yesterday and I’m super impressed 👍 I have a question though. Is it possible to load information from cached session and use it elsewhere in test? Let’s say I have a test like this: cy.session([username, password], () => {
cy.request({
method: 'POST',
url: '/login',
body: { username, password },
}).then(({ body }) => {
window.localStorage.setItem('authToken', body.token)
})
}) But I want to use that local storage item in another place in test, for example in a request command, like this: cy.session('mySession')
cy.request({
method: 'POST'
url: '/example',
headers: {
authorization: // here I’d like to use the cached session dataa
}
}) |
Beta Was this translation helpful? Give feedback.
-
You know I save the best for you
…Sent from my iPhone
On Oct 15, 2021, at 07:15, Filip Hric ***@***.***> wrote:
Wow this plugin took the session API to a whole another level. Is there any reason to keep this plugin separate from codebase? I find this to be a great addition to the overall Session API experience
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
-
In the future do know if there is going to more flexibility around I currently achieve this by using |
Beta Was this translation helpful? Give feedback.
-
Posted from a ticket I had added to the issues board. What would you like?With Cypress The mandatory page clearing, in my humble opinion, is a straight up no-go. This should be toggleable (default to true/false... whatever). Similar to how a validate option is passed... so like Why is this needed?Mandatory page clearing everytime you move to a new
but now we basically are forced to, because of the new
This is a very contrived example, and if I were to copy/paste the actual code, the resulting For what it's worth, I too agree that cypress tests should NOT be written akin to some integration/unit test (with the whole assemble, act, assert paradigm). But, also I don't think one should jam 1000 lines of code inside a single EDIT: Also forgot to mention that potential metric ton of refactoring one might need to do when suddenly switching to |
Beta Was this translation helpful? Give feedback.
-
Cypress.Cookies.defaults Work much better and faster than cy.session() Even without cy.session my tests are independent and reliable |
Beta Was this translation helpful? Give feedback.
-
Hi! The But I have one problem with it - it doesn't work for headless mode, which is more important for me! Here is the reproduce (open with gitpod). You can see that every test took 3sec, but this delay should not be executed for each test except first, because it in the session, is it correct? What I was missing in my code? |
Beta Was this translation helpful? Give feedback.
-
@jennifer-shehane We have Cypress 10.4 available and call for feedback here, but no one from the team has replied to the raised problems for many months. Can something be done please? Personally, I'm stuck on v9 as I have no clue how to go with the new session API without squashing all my tests into in big |
Beta Was this translation helpful? Give feedback.
-
Consider this example, we have simple crawler test suite, I just wanna go over sidebar and navigate to a bunch of pages and just check page title To have this more readable I split it into several it's() to have nice report and know exactly where the page title was changed Cypress.addCommand('login', () => {
cy.session('authenticatedUser', () => {
cy.visit('/login')
cy.get('username').type('user', { log: false })
cy.get('password').type('password', { log: false })
cy.get('submit').click()
}, {
validate: () => {
cy.visit('/home')
cy.contains('Welcome User')
cy.window().then((win) => {
expect(win.localStorage.length).to.eq(2)
})
}),
})
before(() => {
cy.login()
})
it('test page 1', () => {
sidebar.goToPage(1)
cy.contains(Page 1)
})
it('test page 2', () => {
sidebar.goToPage(2)
cy.contains(Page 2)
}) but this won't work since each sidebar click changes the url before(() => {
cy.login()
})
it('Check pages', () => {
sidebar.goToPage(1)
cy.contains(Page 1)
sidebar.goToPage(2)
cy.contains(Page 2)
}) which is less readable How about to add an option to not clear localStorage and cookies at all? That is default behaviour in all others frameworks |
Beta Was this translation helpful? Give feedback.
-
I ran into a problem, POST request changes the session. Cypress.addCommand('login', (email: string) => {
cy.session(email, () => {
cy.visit('/login')
cy.get('username').type(email)
cy.get('password').type('password')
cy.get('submit').click()
}
Cypress.Commands.add('deleteUser', (email: string) => {
cy.login(ADMIN_USER.email)
cy.visit('/admin/users')
cy.get('username').type(email)
cy.get('button[type="submit"]').click()
})
Cypress.Commands.add('createUser', (user: SignUpFormUser) => {
const data = {
email: user.email,
password: user.password
}
cy.request({
method: 'POST',
url: '/api/reg/',
body: data,
})
})
Cypress.Commands.add('reCreateUser', (user: SignUpFormUser) => {
cy.deleteUser(user.email)
cy.createUser(user)
}) |
Beta Was this translation helpful? Give feedback.
-
I think this feature makes it worse with regards to cookie state management. First it was very clear what cookies we allowed to keep during a suite. But now for some clients this will become a nightmare (many added visits and more complexity in code) when we want to keep CY latest. For example one client is using keycloak, where the whole util is in I can only hope you will think about integrations as well. And not the simple ones where login is part of the application. |
Beta Was this translation helpful? Give feedback.
-
It would be really really great if we got an option to not clear local storage and cookies at all Or at least, clear local storage only once before spec starts executing |
Beta Was this translation helpful? Give feedback.
-
From 10.11, there is |
Beta Was this translation helpful? Give feedback.
-
I've used cy.origin and cy.session and the majority of scenarios behave as expected. For this application users authenticate on one domain and then are redirected to the main site. There're two particular scenarios I haven't managed to solve; signing out of the application or updating a user display name. When a user clicks the relevant buttons for these scenarios nothing happens. (These scenarios work fine if origin is not used). I believe the reason it could be causing an issue is that the requests are doing a call-back to the first domain to fetch/update the user token, but without navigating outside the second domain. Is there something I've missed on how to handle this? |
Beta Was this translation helpful? Give feedback.
-
Any plans on including IndexedDB in the mix? Using the session API in combination with Firebase Auth presents some challenges, since Firebase saves data in IndexedDB and the session API does not handle that. Would love to help! Is there anything I can do? Also, can anyone recommend a workaround? |
Beta Was this translation helpful? Give feedback.
-
Hey everyone, thanks for testing out the experimental
cy.session()
!We appreciate any and all feedback that you have to provide. Please use this thread to provide feedback, request features, or just comment on
cy.session()
in general.If you have a larger bug to report, please file a dedicated issue.
Docs: https://docs.cypress.io/api/commands/session
Beta Was this translation helpful? Give feedback.
All reactions