https://cypress.io logo
Join DiscordCommunities
Powered by
# e2e-testing
  • p

    proud-breakfast-29892

    09/15/2022, 3:10 PM
    What you should see is a page with a login form.
  • g

    gentle-accountant-4760

    09/15/2022, 3:31 PM
    Hello people, in my e2e.ts (inside /support) I have added a
    Copy code
    ts
    beforeEach(() => {
      localStorage.setItem('featureToggleOverrides', JSON.stringify({
        'feature-simple-identity-provider': true,
      }));
    });
    however when I run my test the first time when doing cypress open, it works but then when I restart the test again, it doesn't apply the beforeEach anymore, what is the reason of that?
  • p

    polite-painting-51763

    09/15/2022, 4:22 PM
    I see a weird behavior in cypress working with environment variable. In one Cypress command I added a variable using Cypress.env(‘custID’,’123’) on the same command if log Cypress.env(‘custID’) I see correct value ‘123’. But On another Cypress command I tried to get value of using Cypress.env(‘custID’) it returns BLANK. Fun part is when I am logging Cypress.env() in the same command I could see the key and value in json object.
  • m

    melodic-ocean-83158

    09/15/2022, 5:52 PM
    why you put this code on your e2e.ts file? This is a configuration file. Your code must be in your test file (cypress/e2e/testFile.cy.ts)
  • g

    gentle-accountant-4760

    09/15/2022, 5:53 PM
    https://docs.cypress.io/guides/core-concepts/writing-and-organizing-tests#Support-file according to this file, you are supposed to put it inside
    cypress/support/e2e.ts
  • m

    melodic-ocean-83158

    09/15/2022, 5:55 PM
    the local storage is cleared with every test, so it is a requirement that this is in the .cy file
  • g

    gentle-accountant-4760

    09/15/2022, 5:59 PM
    so it needs to be into each test file?
  • m

    melodic-ocean-83158

    09/15/2022, 6:02 PM
    @gentle-accountant-4760 Yes. The code you are implementing is part of a test and will have to be repeated with each test (because the localstorage is cleared with each test). If you put your code in e2e.ts it will only run once when you run cypress, not when you run every test
  • g

    gentle-accountant-4760

    09/15/2022, 6:04 PM
    ahhhhhhhhhhhhh......... but whatsa the point of having it there then?
  • g

    gentle-accountant-4760

    09/15/2022, 6:04 PM
    in support?
  • m

    melodic-ocean-83158

    09/15/2022, 6:17 PM
    The e2e.ts file is for configuration data, where you do some imports, environment preparations, things you need to prepare before(only once) the test files are run.
  • m

    melodic-ocean-83158

    09/15/2022, 6:21 PM
    In your case, LocalStorage.setItem must be executed multiple times during the execution of the project. If you have 10 tests, need to run 10 times. In the e2e file it will be executed only once.
  • m

    melodic-ocean-83158

    09/15/2022, 6:22 PM
    @gentle-accountant-4760 Sorry, I was a bit wordy but I hope you understand 😆
  • g

    gentle-accountant-4760

    09/15/2022, 6:22 PM
    ahhhhhhh
  • g

    gentle-accountant-4760

    09/15/2022, 6:22 PM
    So for every describe, it needs to re-run the locamstorage setItem?
  • m

    melodic-ocean-83158

    09/15/2022, 6:25 PM
    For each it('my test', () => { })
  • m

    melodic-ocean-83158

    09/15/2022, 6:26 PM
    @gentle-accountant-4760 because each test is as if a new browser was opened
  • g

    gentle-accountant-4760

    09/15/2022, 6:27 PM
    Ah but if I have e.g. Describe... before it it it Will I need to set the localstorage for each it or is the before enough?
  • g

    gentle-accountant-4760

    09/15/2022, 6:28 PM
    I assume the before would set the localstorage and then it would follow through all it afterwards?
  • m

    melodic-ocean-83158

    09/15/2022, 6:32 PM
    Only once, but in one beforeEach
  • m

    melodic-ocean-83158

    09/15/2022, 6:34 PM
    the order of execution will be: beforeEach > test01 > beforeEach > test02 > beforeEach > test03
  • g

    gentle-accountant-4760

    09/15/2022, 6:35 PM
    Ahhh I see I see, thank you for that! 😁 For some reason before worked for me apperently
  • g

    gentle-accountant-4760

    09/15/2022, 6:36 PM
    Which is kinda weird.. maybe the localstorage somehow gets stored?
  • m

    melodic-ocean-83158

    09/15/2022, 6:38 PM
    @gentle-accountant-4760 Do you have more than one test? If so, it shouldn't be stored. Unless you are using cy.session at some point.
  • g

    gentle-accountant-4760

    09/15/2022, 6:50 PM
    Nope, I mean what I have is that I have everything like
    Copy code
    ts
    describe('....', () => {
      before(() => {
        setFeatureToggle();
      });
    
      describe('...', () => {
        it('..', () => {
        });
    
        it('..', () => {
        });
    
        it('..', () => {
        });
    
        it('..', () => {
        });
      });
    });
  • m

    melodic-ocean-83158

    09/15/2022, 7:06 PM
    Interesting, will he only clean up after he finishes all tests from second describe? learning one more thing...😆
  • m

    melodic-ocean-83158

    09/15/2022, 7:06 PM
    Another approach for you to separate tests is use context('',()=>{}).
  • g

    gentle-accountant-4760

    09/15/2022, 7:06 PM
    What would that look like based on my example?
  • g

    gentle-accountant-4760

    09/15/2022, 7:12 PM
    Ah instead of describe?
  • g

    gentle-accountant-4760

    09/15/2022, 7:12 PM
    I wonder if that cleans the localstorage then...
1...102103104...192Latest