cypress icon indicating copy to clipboard operation
cypress copied to clipboard

setCookie() not working on webkit - 11.2.0

Open obajaddi opened this issue 2 years ago • 11 comments

Current behavior

I'm trying to set cookies in order to avoid a welcome popin but it's not working on the webkit :( => OK on other browsers.

Context :

  • Running in docker container
  • I had to install theses dependencies in the Dockerfile : "libgstreamer1.0-0 libevent-2.1-7 libxslt1.1 libopengl0 libwoff1 libharfbuzz-icu0 libgstreamer-plugins-base1.0-0 libgstreamer-gl1.0-0 libwebpdemux2 libenchant-2-2 libhyphen0 libmanette-0.2-0 libgles2" and next run "npx playwright install webkit" in the entrypoint to make it works
  • HOST : ubuntu 22

image image

Desired behavior

setCookie() working on webkit

Test code to reproduce

cy.setCookie('alltricks-newsletterPopin', '1');

Cypress Version

11.2.0

Node version

16.16.0

Operating System

ubuntu 22

Debug Logs

No response

Other

No response

obajaddi avatar Dec 21 '22 11:12 obajaddi

@obajaddi Thank you for opening an issue with a snippet on how to reproduce. I verified the the following example with Cypress 11.2.0 and 12.2.0 with [email protected] and was able to successfully set the cookie in the webkit browser:

it('t1', () => {
    cy.setCookie('alltricks-newsletterPopin', '1');
    cy.getCookie('alltricks-newsletterPopin')
    .its('value')
    .should('eq', '1');
})

Image

I noticed in your screenshots, the tests seem to indicate the cookie(s) were successfully set and you had asserting one had the correct values. When you are inspecting the cookies in the devtools, is this after the test has completed and another test has executed?

Could you share some more details on the test setup and the configuration used in your setup?

emilyrohrbough avatar Dec 23 '22 20:12 emilyrohrbough

I am also having this issue when trying to bypass a cookie consent. The format to reproduce it is this in my case: cy.setCookie( "APP_COOKIE_SETTINGS", {"preferences":[{"label":"analytics","value":true,"channelID":1045,"statementID":1052},{"label":"marketing","value":true,"channelID":1046,"statementID":1053},{"label":"thirdparty","value":true,"channelID":1047,"statementID":1054}],"reconsentDate":"2021-02-25T16:09:39"} );

The rest of the browsers handle it just fine, only using webkit I don't have this cookie set.

danut-dumitru avatar Jan 04 '23 13:01 danut-dumitru

@danut-dumitru Can you provide a reproducible example of the issue you're encountering? I'm afraid just the setCookie command won't be enough to verify the issue is happening or validate a fix for it.

chrisbreiding avatar Jan 04 '23 15:01 chrisbreiding

@chrisbreiding , you can try the following:

      cy.visit("https://www.lego.com/en-gb/family");
      cy.setCookie(
        "LEGO_COOKIE_SETTINGS",
        `{"preferences":[{"label":"analytics","value":true,"channelID":1045,"statementID":1052},{"label":"legomarketing","value":true,"channelID":1046,"statementID":1053},{"label":"thirdparty","value":true,"channelID":1047,"statementID":1054}],"reconsentDate":"2021-02-25T16:09:39"}`
      );

If you check the cookies that are set, the one above will not be present. If you check the same scenario above on Chrome for example, you will see that the cookie is set. Does this help?

danut-dumitru avatar Jan 04 '23 16:01 danut-dumitru

@danut-dumitru I believe that's an issue with webkit not live-updating the cookies shown in the DevTools rather than an indication that the cookie is not being set. When I run that test code, the cookie will not initially display in DevTools, but if I hit the Refresh button for the Storage tab, the cookie will display.

So unfortunately we still don't have a reproduction we can investigate. Ideally it would be one where the test fails because the cookie is not present.

chrisbreiding avatar Jan 09 '23 16:01 chrisbreiding

Thank you for taking the time to look into the scenario, @chrisbreiding . You are right about the presence of that specific cookie if you reload the page. Let me try to add a much more complete scenario here in order to help figuring out the problem. On the site specified above (lego.com) in order to access a specific area you need to login in: Screenshot 2023-01-10 at 11 53 11 The site uses a login cookie to authenticate and should look like this if that cookie is present: Screenshot 2023-01-10 at 11 54 47 I have created a dummy account for this test in order to check the scenario. Please try out the test below that has the login cookie as well:

cy.setCookie("npsSurveyInvited", "1");
     cy.setCookie("AGE_GATE", "grown_up");
     cy.setCookie(
       "LEGO_COOKIE_SETTINGS",
       `{"preferences":[{"label":"analytics","value":true,"channelID":1045,"statementID":1052},{"label":"legomarketing","value":true,"channelID":1046,"statementID":1053},{"label":"thirdparty","value":true,"channelID":1047,"statementID":1054}],"reconsentDate":"2021-02-25T16:09:39"}`
     );
//The cookie below is the login cookie
     cy.setCookie(
       "__FamilyHubFE",
       "CfDJ8NbCQR7vCa5ImZdruLudzEvJNfa7RF0TH4bbdqqC4wdVqjOpPpcwOBZHqu35Y_TyyG-ao6IJq6pw8ejK5uEjCHzwrY7N3uCAfWWuLlK8h9EenYcP5k1_VrObRfyyV9zE8QyXABxqxeveELMtqUS3QUFYqKJnzxEP6xrsrdJEozyGHU_is_WmHe3ldSsEEWms5GBEqd0FCGowaovDzDmza2Gxn3WXI_vvvHmrCXuwtX_f5yvM7izBSs6w_DzkV0pMj2S9ajVFlYQC1LqDzIIJnYN-rfg3x2Hu--s0DkLUH6x7Phn4VBU-twg5N2Fx9u3NkQF5SOo-tzdh-EehbHX24Lk"
     );
     cy.visit("https://www.lego.com/en-gb/family/activities");
     cy.reload();

Even if I include a cy.reload() in there, the login cookie is not set and I am still not signed in. If you check this scenario on Chrome you will notice that that specific area in the page is accessible because the login cookie has been set. Please let me know if the scenario above is enough in order to investigate further!

danut-dumitru avatar Jan 10 '23 10:01 danut-dumitru

Thanks for the reproduction. I was able to verify the issue happening. I'll route this to my team for investigation.

chrisbreiding avatar Jan 17 '23 16:01 chrisbreiding

@chrisbreiding , sorry to bother you with this issue but unfortunately my company really wants to use the webkit for testing on multiple projects and we are stuck with no workaround possible. Is there any chance somebody will have time to have a look at it? I'm affraid it will get lost in the backlog. Thank you again for your time!

danut-dumitru avatar May 16 '23 10:05 danut-dumitru

Hi @danut-dumitru , we have not forgotten about this ticket. 😺 I am going to bring this up internally for more discussion about possible ways forward.

nagash77 avatar May 17 '23 13:05 nagash77

Hi @danut-dumitru , we have not forgotten about this ticket. 😺 I am going to bring this up internally for more discussion about possible ways forward.

Hey @nagash77, thank you very much for taking the time to reply. It would be fantastic if you guys take the time to discuss about it and would make my life easier trying to convince the stakeholders not to switch to something else since I enjoy working with Cypress :D.

danut-dumitru avatar May 17 '23 13:05 danut-dumitru

@danut-dumitru can you please send me an email with your name, company, team and any other relevant information about the impact of this issue on your usage of Cypress? My email is

nagash77 avatar May 17 '23 17:05 nagash77

@danut-dumitru I took some time recently to look further into this. I know it's been awhile since there's been any activity on this issue, so thank you for your patience.

Now that I've revisited this though, unfortunately (or perhaps fortunately) I can't reproduce the issue. Since the __FamilyHubFE value you provided is likely expired at this point, I logged into my own lego.com account, took the cookie value that was stored, used it in the test, and it showed the 'Saved activities' like it would for a logged-in user. So it seems the cookie is being correctly set.

I also tried doing a fully automated log-in flow instead of using cy.setCookie() and it seemed to work in that manner as well.

At this point, I can't determine anything wrong with cy.setCookie() in webkit, but if your tests are still failing and you can perhaps provide further test code to help me reproduce it, I can do some more investigation.

chrisbreiding avatar Aug 25 '23 17:08 chrisbreiding

@chrisbreiding , thank you very much for looking into this again. I had given up at some point on this issue but it seems you are right, it is no longer reproducible and I can add tests with the cookie correctly set. I no longer see this as an issue for what I need.

danut-dumitru avatar Aug 28 '23 08:08 danut-dumitru

Glad to hear it's working in your tests. I'm going to close this as it seems to no longer be an issue.

chrisbreiding avatar Aug 28 '23 12:08 chrisbreiding