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

6 posts, 1 answers
  1. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 15 Nov 2012 Link to this post

    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.

  2. Answer
    Boyan Boev
    Admin
    Boyan Boev avatar
    1043 posts

    Posted 16 Nov 2012 Link to this post

    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
  3. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 22 Nov 2012 Link to this post

    Thanks Boyan Boev, I will test and verify if it works later. 
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1043 posts

    Posted 22 Nov 2012 Link to this post

    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
  5. Jet
    Jet avatar
    10 posts
    Member since:
    Oct 2012

    Posted 27 Nov 2012 Link to this post

    Thanks Boyan Boev for giving the workaround.
    It works well.
  6. Boyan Boev
    Admin
    Boyan Boev avatar
    1043 posts

    Posted 27 Nov 2012 Link to this post

    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
Back to Top