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

How to set cookie with domain like ".ctrip.com"

5 Answers 65 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jet
Top achievements
Rank 1
Jet asked on 15 Nov 2012, 11:06 AM

Hi
I can set the cookie with domain "ctrip.com" when testing in FireFox, but couldn't set the value with domain which likes ".ctrip.com".

//the following codes works well

Cookie cookie = new Cookie();
cookie.Domain = "ctrip.com";
cookie.Name = cookieName;
cookie.Value = cookieValue;
 cookie.Path = "/";
cookie.Expires = DateTime.Now.AddHours(2);
 
Manager.ActiveBrowser.Cookies.SetCookie(cookie);

//the following codes doesn't work, after executing the codes, I couln't find the cooke.

Cookie cookie = new Cookie();
cookie.Domain = ".ctrip.com";
cookie.Name = cookieName;
cookie.Value = cookieValue;
 cookie.Path = "/";
cookie.Expires = DateTime.Now.AddHours(2);
 
Manager.ActiveBrowser.Cookies.SetCookie(cookie);

Thanks in advance.

5 Answers, 1 is accepted

Sort by
0
Accepted
Boyan Boev
Telerik team
answered on 16 Nov 2012, 03:21 PM
Hi Jet,

Thank you for the question. 
I'm sorry to hear you're hitting this problem. The reason is in our implementation of the SetCookie method. We will discuss how to improve the implementation of the method in the shortest time.

However I found a workaround. You can add this coded step in order to set cookies for every domain or subdomain you want. Note that this is for the current page.

string setCookieFunc = string.Format("var c_name ='{0}';var value = '{1}';var exdays = {2};var exdate=new Date();exdate.setDate(exdate.getDate() + exdays);var c_value=escape(value) + ((exdays==null) ? '' : '; expires='+exdate.toUTCString());document.cookie=c_name + '=' + c_value;", "Name", "Value", 1);
 
this.ActiveBrowser.Actions.InvokeScript(setCookieFunc);


Hope this will help you. Greetings,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jet
Top achievements
Rank 1
answered on 22 Nov 2012, 06:06 AM
Thanks Boyan Boev, I will test and verify if it works later. 
0
Boyan Boev
Telerik team
answered on 22 Nov 2012, 10:03 AM
Hello Jet,

Let me know whether it helps.

If you have any further questions feel free to contact us.

Greetings,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Jet
Top achievements
Rank 1
answered on 27 Nov 2012, 08:31 AM
Thanks Boyan Boev for giving the workaround.
It works well.
0
Boyan Boev
Telerik team
answered on 27 Nov 2012, 09:53 AM
Hello,

Glad I could help. Let me know if I can assist further.

Kind regards,
Boyan Boev
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Jet
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Jet
Top achievements
Rank 1
Share this question
or