Skip to content
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

LocalStorage missing across spec files #401

Closed
aasimali opened this issue Apr 5, 2022 · 13 comments · Fixed by #453
Closed

LocalStorage missing across spec files #401

aasimali opened this issue Apr 5, 2022 · 13 comments · Fixed by #453
Assignees
Labels
bug Something isn't working

Comments

@aasimali
Copy link

aasimali commented Apr 5, 2022

. I installed this plugin using npm i --save-dev cypress-localstorage-commands

. And I added this line: import "cypress-localstorage-commands" into cypress/support/commands.js

. In my testcase.ts file, I added

image

And when I execute, it does not store cookies

image

@javierbrea
Copy link
Owner

Hi @aasimali,

Could you please provide more information about how is the localStorage saved when the page performs the login action? Or even better, could you provide a fully reproducible example of the case in which the plugin is not working? To ensure that it is the plugin which is not working, maybe you can try to test the plugin simply setting one item in the localStorage, and then check that it is still present after restoring it.

Thanks in advance

@javierbrea javierbrea added the stage: needs information Not enough info to reproduce the issue label Apr 12, 2022
@javierbrea javierbrea self-assigned this Apr 12, 2022
@aasimali
Copy link
Author

Hi @javierbrea

Thanks for your response, the issue is from Instagram login.

To reproduce it, please log into Instagram and once you're successfully logged in one test, then see you still have cookies from Instagram or not.

In my test, I'm logging into Instagram first as I needed to logged in Instagram to perform the next test, but as cookies is flushing, I'm not able to perform the test.

@javierbrea
Copy link
Owner

Could you please be more specific and provide some code with a reproducible failing example, please? A link to a repository containing a failing test would be great, for example. On the contrary, please give more clues about what can be failing. Are you sure that the login is stored in the local storage? It is stored in the same domain or in another? Traces? Screenshots of developer tools?
Note that I can't set up a complete project with the unique clue being that it is failing in "Instagram". First I would like to have enough context and information in order to discard other possible causes.

@DiederikvandenB
Copy link

I am also having this issue. Don't have time to setup a demo repo right now unfortunately.

@alex-clear
Copy link

@javierbrea Just used your plugin and faced with this issue
Cypress version 10.2.0

Here my local storage view:
Screen Shot 2022-06-22 at 10 24 22

As you can see I have 2 keys in local storage

However, after my tests go to next test the local storage was disappeared
I set the debugger inside you plugin and found that local storage inside you code is empty:
Screen Shot 2022-06-22 at 10 30 10
Here are my cypress configurations:
Screen Shot 2022-06-22 at 10 38 44
Screen Shot 2022-06-22 at 10 38 20
Screen Shot 2022-06-22 at 10 37 15

And here is my test code:
Screen Shot 2022-06-22 at 10 40 16

I hope this will help you to investigate the issue and provide me what I am doing wrong or fix the issue from you side.
Thanks for help

@javierbrea
Copy link
Owner

Hi @DiederikvandenB , are tests in the same specs file or in different files?

@javierbrea javierbrea added the awaiting response Awaiting response label Jul 4, 2022
@vdineva
Copy link

vdineva commented Jul 5, 2022

@javierbrea I am also having issues with this plugin since upgrading to Cypress 10. In my case tests are in different files

@peeyushohri04
Copy link

@javierbrea i am also facing issues post upgrading to cypress 10 . Local storages are not being retained across specs . Is there any fix in pipeline to resolve this issue ?

@javierbrea
Copy link
Owner

Hi @peeyushohri04 @vdineva ,
I will investigate further, but I suspect that there is no any easy or fast fix related to this issue. Maybe now Cypress is cleaning the Javascript context between the execution of different spec files. If that is the case, then I'll have to refactor the plugin to keep the localStorage state in NodeJs. And this will require to change even the plugin installation method. I'll let you know when I have more details.

Thanks for the notice, by the way!

@javierbrea javierbrea added stage: needs investigating Needs further investigation and removed stage: needs information Not enough info to reproduce the issue awaiting response Awaiting response labels Jul 20, 2022
@javierbrea javierbrea changed the title Unable to use this plugin LocalStorage missing across spec files Jul 22, 2022
@javierbrea
Copy link
Owner

javierbrea commented Jul 22, 2022

Hi @vdineva @peeyushohri04
I'm adding some tests to the package, and, after executing them with previous versions I have discovered that the issue was also happening on Cypress v9.7.0. The localStorage was not retained between spec files. Could you please tell me the exact version in which it was still working for you? Thank you!

@javierbrea
Copy link
Owner

Update: It doesn't work either with version 9.0.0

@vdineva
Copy link

vdineva commented Jul 22, 2022

Our current version of Cypress is 9.7.0 and things work fine. We've had every other 9.x.x version installed and things were working fine. In our case localStorage is not retained between soec files once we upgrade to v10 of Cypress

@javierbrea
Copy link
Owner

javierbrea commented Jul 22, 2022

@vdineva Could it be related to the new configuration files on Cypress 10 instead of the plugin itself? I mean, maybe the commands were not being installed properly. But I suppose that this would produce an error when trying to use them, it wouldn't produce such a specific bug. In order to understand it better, was the localStorage retained between tests in the same spec file properly in Cypress 10 in your case?

Anyway, I have already found a solution. But I'd like to understand why was this happening. I suspect that in this issue there are problems related to the localStorage not being maintained between specs (which I have checked that was happening in previous versions already), and problems related to not installing the plugin properly in Cypress 10.

I will publish the new version soon, and I will also update the installation docs. Apart from this, I will add also E2E tests using Cypress 9, and I'll keep a branch with the Cypress 9 failing tests before applying the fix, just in case it may be useful for further investigation.

Thanks for a quick answer, by the way! 😃

@javierbrea javierbrea added bug Something isn't working and removed stage: needs investigating Needs further investigation labels Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants