Forum Discussion

chicks's avatar
chicks
Regular Contributor
11 years ago

Cookie access?



Does testcomplete provide any mechanism for accessing cookies on web pages?



I searched and found a link /topic forum for Managing Cookies (http://www.automatedqa.com/support/viewarticle/12629 but I got a support portal error when I clicked on it.



Has anybody accessed the cookies succesfully through TestComplete?



Thanks.

6 Replies

  • You can get the cookies using the ServerXMLHTTP object to create an XHR, e.g.:




    function getCookie(URL) {


        var response;


        var XmlHttpRequest = Sys["OleObject"]("MSXML2.ServerXMLHTTP.3.0");


        XmlHttpRequest.open("GET", URL, false); 


        XmlHttpRequest.send();


        try {


            response = XmlHttpRequest.getAllResponseHeaders(); 


        } catch (e) {


            response = "Error";


        }


        XmlHttpRequest = null;


        return response;


    }


     


    function TESTCookie() {


        Log.Message(getCookie("http://smartbear.com/forums/"));


    }



    This actually shows you all the headers, I'll leave it to you to parse the cookies from the response:




    Cache-Control: private, no-store, must-revalidate


    Date: Wed, 07 Aug 2013 14:34:39 GMT


    Content-Length: 107612


    Content-Type: text/html; charset=utf-8


    Server: SuperBear Server


    Set-Cookie: ASP.NET_SessionId=kwh4do4zajcrzrwcct2xu; path=/; HttpOnly


    Set-Cookie: VisitorStatus=110584414; expires=Sun, 07-Aug-2033 14:34:39 GMT; path=/; HttpOnly


    Set-Cookie: ASP.NET_SessionId=kwh4do4zajcrzrwcct2xu; path=/; HttpOnly


    Set-Cookie: VisitorStatus=110584414; expires=Sun, 07-Aug-2033 14:34:39 GMT; path=/; HttpOnly


    Set-Cookie: CurrentTheme=Forums1; expires=Thu, 08-Aug-2013 14:34:39 GMT; path=/; HttpOnly


     




    • wt0vremr's avatar
      wt0vremr
      Occasional Contributor

      In firefox, you can open about:preferences#privacy, click on View Cookies and select cookie you want.

      After this. create a property test, and scroll down to value.

      • wt0vremr's avatar
        wt0vremr
        Occasional Contributor

        Alternalively, you can start recording, open a page, press F12, switch to browser console, write "alert(document.cookie);", hit enter and add test to read text from alert.

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    You can access a web page's cookies like this:

     

    Sys.Browser().Page("https://yoursite.com").contentDocument.cookie
  • chicks's avatar
    chicks
    Regular Contributor
    Thanks Tanya,



    However I am not trying to clear the cache or the cookies but see whether the cookie is created when I initiallly visit a page and see if the cookie values are being reset when I navigate to other pages....



    Regards,  Curt