Cypress maintain context - cypress

We have a platform with a lots of workflows and a lots of tests. Right now for each test we have to complete a long workflow. In order to speed up this, I want to share the context or the browser, with all the cookies, the url, and all the data between all the it inside each describe.
I could also crete just one it and put everything inside but i'll prefer to maintain all the it functions to have all more organizated.
I know that i'm dealing with anti patterns.. but this will improve significantly the speed of the tests.
So.. is there a way to acomplish this? I can't find anything.
Thank you!

cy.session() should get you most of the way there. It allows you create a session, from which Cypress will cache most of the browser context. The next time Cypress encounters the session command, it will check to see if it has created a session with the same id, and if it has, it will use those cached values. Otherwise, it executes the contents of the cy.session() command.
From the docs:
Cache and restore cookies, localStorage, and sessionStorage (i.e. session data) in order to recreate a consistent browser context between tests.
Once created, a session for a given id is cached for the duration of the spec file. You can't modify a stored session after it has been cached, but you can always create a new session with a different id.
In order to reduce development time, when running Cypress in "open" mode, sessions will be cached for spec file reruns. To persist a session across multiple specs, use the option cacheAcrossSpecs=true
And their example using cy.session inside of a login command.
Cypress.Commands.add('login', (username, password) => {
cy.session([username, password], () => {
cy.visit('/login')
cy.get('[data-test=name]').type(username)
cy.get('[data-test=password]').type(password)
cy.get('form').contains('Log In').click()
cy.url().should('contain', '/login-successful')
})
})

Related

How to test with cookied user?

I want to test the site with 2 types of users.
First time user
Returning user
I am not sure how to test the returning user. Should I use cookie manager for this and use HTTP request twice with the same request to make the user cookied user?
It is more related to CACHE than COOKIE to define your scenario.
First Users: Download All Resources and Save Them Locally.
Returning Users: Use the Downloaded Resources instead of downloading them from the server again.
Here, Resources are referred to static web elements like images, .js, .css files which won't change much.
To implement both users, use HTTP Cache Manager. Use the default settings. Mark iterations in Thread Group -> Loop Count more than 1. Here, in first iteration, you are simulating First User. Remaining iterations are treated as Returning Users as JMeter uses Cache.
Note: If you check the option Clear cache each iteration, you are simulating all iterations as First Comers/Users as they always request/download resources from the server.

Run the recorded testplan in Jmeter and verify the the entry in the Database

Im using Jmeter and do performance testing for my web application. I record my actions in jmeter and play back the same. The testplan got run but when i verify the database manually, the new row is not created. The value got added in the existing line.Please help me out of this. I am struck in this step for 2 days
Verify if your requests includes hardcoded session's data. If your app manages sessions and you just "recorded" the actions, probably you are re-using the same session's data. Assuming there is a login page -> the requests after the login would use a session, usually returned for the login action.
As comments are not enough descriptive; posting a new answer. You can do this by using regular expression extractors, because -probably- the session info comes in the response (so extract it into a variable, by parsing the response with a regex extractor)
and then use the variable in further request/s.
This is a tricky way and need lot of work... even more if the session keep changing in subsequent responses (it usually change while moving worward through the page/app workflow), if that is the case you will need to extract the data after each request.
Please reffer to the jmeter manual for more info about regex extractors.

Sessions in Meteor

After a research it seems that Meteor Sessions are reset after refreshing page or opening the website in new tab, i.e. they are not usual server-side sessions but something like global javascript variables on client-side. Some people advice to use AmplifyJS, but I'm not sure that it will work like usual session in other frameworks/languages and also it is a third party library, so is there any normal way to use sessions in Meteor, i.e. keep user-specific data on server?
At this moment I'm handling that by using custom Collections, but it is not an ideal way of doing that because it is needed to remove expired values from Collection manually, which makes additional troubles.
Yes this is correct. Despite the name Session is nothing like a cookie, but just a reactive form of a variable stored in a hashmap
To keep data persistent across tabs you need to use a Collections (as this is the only way to reactively share data across tabs) - Cookies can't work because they can't be made reactive as data needs to be sent to the server to notify the client when there is a change. There really wouldn't be another way at the moment as the publish/subscribe methods can only send down data from collections at the moment.
You can use your setup you have now with your custom collection. You can use a server side cron job to remove expired data (either with Meteor.setInterval or Tom Coleman's cron.
There is a package developed just for that: https://atmospherejs.com/u2622/persistent-session
After installation you can use the following functions to set sessions which are persistent:
//store a persistent session variable which is stored across templates
Session.setPersistent(key, value);
//same as above, but automatically deletes session data when user logs out
Session.setAuth(key, value);
I've tried the package and it works like charm.

When copy the url from one browser to another browser my session data are not coming in asp.net MVC3

When i copy the URL from one browser to paste it in another browser my session data not retrieved it shows "Object reference not set to an instance of an object".
(Please note - this answer assumes you are not already using cookieless sessions)
The way sessions work in ASP.NET is that when you first access a site, a cookie-file is placed in your browsers cookie-store. The cookie contains a session ID, so the next time you access that site from that browser the ID is passed to the web-application and it knows which session-state to load.
However, each browser implements it's own cookie-store, so switching browsers means the site cannot determine your session ID.
One way to get around this is to use cookieless sessions. However, these have a number of issues relating to usability and security, so think long and hard before deciding they are for you.
Another option is to tie together your authorization and session systems. However, this is not generally recommended either.
You will not be able to access session values across multiple browsers.
Also, you should check if the value exists in Session to avoid Server Error.
if(Session["Key"] != null)
{
//Write your code here
}
else
{
//Alternative code (redirection code)
}

In CakePHP 1.3 is there any advantage of using $this->Controller->Session over $this->Session in a component?

I'm using a modified version of Felix Geisendörfer's SimpleAuth/SimpleAcl components that I've combined into a single Component, Simple_Authable.
I changed his startup() function to initialize() to not clutter the beforeFilter function in my app_controller.
One of the things that this component does is check who the active user is and if that user can't be found it either looks him up based on the primary User.id or uses 'guest'. Either way, the component uses $this->Controller->Session->write() to save the active user or guest information.
I'm also using Felix's Authsome plugin instead of the default CakePHP Auth component.
When I'm logging in, the active user is guest, obviously.
After I've submitted the form, the active user is still guest because the component's initialize() function is firing before everything else. Then, the Authsome plugin comes into play and validates my user as "root" and also calls $this->SimpleAuthable->setActiveUser($id, true); to force SimpleAuthable to update the active user information it is storing via $this->Controller->Session; Then I am redirected and my simple Session information and DebugKit's Session tab reflect that I am indeed the root user.
However, when I try to navigate to an 'admin' page, let's say /admin/users/index, lo and behold SimpleAuthable thinks I'm still a 'guest' user because when it performs a $this->Controller->Session->read() call to the key holding my user id, it is getting an empty response, i.e., the data stored on the previous page didn't persist.
Maybe there is something funky happening between Authsome & SimpleAuthable, but things look pretty straightforward and to my mind, $this->Controller->Session should be saving and persisting the data written to it.
So, I'm looking at refactoring all the calls to $this->Controller->Session and replacing them with $this->Session but first I wanted to throw this out to the community and see if anybody has seen anything similar and if so how did they resolve it.
Sincerely,
Christopher.
I found the problem... I'm also using Joshua McNeese's Permissionable plugin and I needed to disable it for the $this->Controller->{$this->userModel}->findById($id); in my SimpleAuthable component when I try to lookup the current active user.
Note to self: I would have caught this faster if I had some unit testing in place :(.

Resources