This is a migrated thread and some comments may be shown as answers.

set & get cookies

1 Answer 125 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 20 Feb 2012, 05:38 PM
Hello, 

i am trying to set & get a cookie, without success.
my code:

const string domain = "http://localhost";          
var cookie = new Cookie("foo", "bar", "/", domain);
var ok = telerik.ActiveBrowser.Cookies.SetCookie(cookie);
var c = telerik.ActiveBrowser.Cookies.GetCookies(domain);          
var count = c.Count;

count is always == 0!

I am on the latest release of the (free) testing framework.
ActiveBrowser is Chrome.

If I set ActiveBrowser to IE, it works!

Am I doing anything wrong?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 25 Feb 2012, 01:33 AM
Hi Stefan,

I apologize for the delay responding to you (we're slightly overloaded in support at the moment).

This is one of those very subtle browser differences. I admit we could do better at making that API call more browser agnostic.

Here is code that works in both Chrome and IE. Now how the URL must be different for the SetCookie versus the GetCookies:

const string url = "www.google.com";
{
    var cookie = new Cookie("FOO2", "bar", "/", url);
    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 (Cookie cookie in ActiveBrowser.Cookies.GetCookies("http://www.google.com"))
{
    Log.WriteLine(cookie.Name);
}

All the best,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Stefan
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or