I use ActiveBrowser.Cookies.GetCookies(BaseUri); to get browser cookie, cookie is got, but all expired cookie. The same code if I set chrome not headless, which could get un-expired cookie. Is it not supported yet?
Chrome headless:
Chrome:
Elena
Telerik team
commented on 25 Apr 2024, 02:00 PM
Hi Jun,
As far as I understand you are running the tests in Chrome in its mode using extension. Please, change the test settings so that the test runs in Chrome without the extension. Then let me know if getting the cookies sets these with expired dates again.
If so, please, prepare a sample test/code to share which runs against a public accessible page - this will allow me to reproduce the misbehavior and continue working on it.
var url = "https://www.telerik.com/forums/chrome-headless-not-support-get-browser-cookie"; ActiveBrowser.ClearCache(BrowserCacheType.Cookies); ActiveBrowser.NavigateTo(url); var cookies = ActiveBrowser.Cookies.GetCookies(url);
for chrome:
for chromeheadless:
1 Answer, 1 is accepted
0
Elena
Telerik team
answered on 14 May 2024, 01:22 PM
Hello Jun,
Thank you for sharing an example of the issue you experienced - this helped me a lot.
So, it turns out that getting the cookies is too soon after the navigate action and this is the reason why the cookie object remains empty. To fix this insert a short delay after the NavigateTo() method:
System.Threading.Thread.Sleep(5000);
All in all the snipped should look like this:
var url = "https://www.telerik.com/forums/chrome-headless-not-support-get-browser-cookie";
ActiveBrowser.ClearCache(BrowserCacheType.Cookies);
ActiveBrowser.NavigateTo(url);
System.Threading.Thread.Sleep(5000);
var cookies = ActiveBrowser.Cookies.GetCookies(url);
Hi Jun,
As far as I understand you are running the tests in Chrome in its mode using extension. Please, change the test settings so that the test runs in Chrome without the extension. Then let me know if getting the cookies sets these with expired dates again.
If so, please, prepare a sample test/code to share which runs against a public accessible page - this will allow me to reproduce the misbehavior and continue working on it.
Regards,
Elena
Hi Elena,
Thanks for update. I tried again, still the same issue~_~
settings.Web.DefaultBrowser = BrowserType.ChromeHeadless;
settings.Web.UseBrowserExtension = false;
var url = "https://www.telerik.com/forums/chrome-headless-not-support-get-browser-cookie";
ActiveBrowser.ClearCache(BrowserCacheType.Cookies);
ActiveBrowser.NavigateTo(url);
var cookies = ActiveBrowser.Cookies.GetCookies(url);
for chrome:
for chromeheadless: