Chrome cookie couldn't be set success in version Testing_Framework_2022_1_0601_1_Free, but Testing_Framework_2021_1_0309_1_Free could set success

1 Answer 195 Views
Chrome
Jun
Top achievements
Rank 1
Iron
Iron
Jun asked on 19 Jul 2022, 10:23 AM

The code we use is

manager.ActiveBrowser.Cookies.SetCookie(cookie);

But when we getcookie, we found nothing.

Jun
Top achievements
Rank 1
Iron
Iron
commented on 19 Jul 2022, 10:28 AM

Testing_Framework_2022_1_0601_1_Free  set cookie fine for edge, but not work for chrome.

Testing_Framework_2021_1_0309_1_Free set cookie fine for chome.

I am not sure if Testing_Framework_2022_1_0601_1_Free got any update on set cookie funciton.

1 Answer, 1 is accepted

Sort by
0
Plamen Mitrev
Telerik team
answered on 20 Jul 2022, 07:58 AM

Hello Jun,

I tested the code to set and get a cookie in Chrome and Edge with the latest official version 2022.1.601 on my end. The sample code in our documentation and what looks to be your code, should work without issues, unless there is a problem with the cookie or browser.

I tested against Edge Chromium 103.0.1264.62 and Chrome 103.0.5060.134 and it worked as expected. You can find the code snippet from two different approaches below and compare that to your code and behavior.

Cookie Support

            // Let's create a new cookie for a url.
            Manager.ActiveBrowser.Cookies.SetCookie(new System.Net.Cookie("WebAii", "Rocks", "/", "http://www.telerik.com"));
            
            // Query the cookie
            System.Net.CookieCollection siteCookies = ActiveBrowser.Cookies.GetCookies("http://www.telerik.com");
            Log.WriteLine(siteCookies.Count.ToString());
            foreach (System.Net.Cookie cookie in ActiveBrowser.Cookies.GetCookies("http://www.telerik.com"))
            {
                Log.WriteLine(cookie.Name);
                Log.WriteLine(cookie.Value);
            }

Get/Set Cookies in Code

            Manager.LaunchNewBrowser();

            const string url = "http://www.google.com";
            {
                var cookie = new System.Net.Cookie("foo", "bar", "/", url);
                //var cookie = new System.Net.Cookie();
                cookie.Expires = DateTime.MaxValue;
                var ok = ActiveBrowser.Cookies.SetCookie(cookie);
            }

            var c = ActiveBrowser.Cookies.GetCookies("http://www.google.com");
            var count = c.Count;

            Log.WriteLine(count.ToString());
            foreach (System.Net.Cookie cookie in ActiveBrowser.Cookies.GetCookies("http://www.google.com"))
            {
                Log.WriteLine(cookie.Name);
                Log.WriteLine(cookie.Value);
            }

I hope the information and code samples will be helpful to you. Otherwise, let me know what is the state of thee issue and we can continue our discussion.

Regards,
Plamen Mitrev
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Jun
Top achievements
Rank 1
Iron
Iron
commented on 21 Jul 2022, 02:18 AM

Thanks very much for response, I will try again, and will send you feedback later.
Plamen Mitrev
Telerik team
commented on 21 Jul 2022, 06:44 AM

Sounds great! Let me know if there are any issues with the cookies.
Jun
Top achievements
Rank 1
Iron
Iron
commented on 11 Apr 2024, 01:51 PM

Sorry for later response, what we finally find out is we missing http in the url which we use to get cookie, after adding it, which could work well.
Tags
Chrome
Asked by
Jun
Top achievements
Rank 1
Iron
Iron
Answers by
Plamen Mitrev
Telerik team
Share this question
or