Example #1
0
        /// <summary>
        /// Method for getting a Collection of Cookies that are present in the browser
        /// </summary>
        /// <returns>ReadOnlyCollection of Cookies in the browser</returns>
        private ReadOnlyCollection <Cookie> GetAllCookies()
        {
            List <Cookie> toReturn = new List <Cookie>();
            object        returned = this.driver.InternalExecute(DriverCommand.GetAllCookies, new Dictionary <string, object>()).Value;

            try
            {
                object[] cookies = returned as object[];
                if (cookies != null)
                {
                    foreach (object rawCookie in cookies)
                    {
                        Dictionary <string, object> cookieDictionary = rawCookie as Dictionary <string, object>;
                        if (rawCookie != null)
                        {
                            toReturn.Add(Cookie.FromDictionary(cookieDictionary));
                        }
                    }
                }

                return(new ReadOnlyCollection <Cookie>(toReturn));
            }
            catch (Exception e)
            {
                throw new WebDriverException("Unexpected problem getting cookies", e);
            }
        }
Example #2
0
        private static Cookie convertRestSharpToSeleniumCookie(RestResponseCookie c)
        {
            //Cookie.FromDictionary allows us to set all cookie properties using a dictionary.
            //We create the raw cookie dictionary using the properties from the RestResponseCookie

            Dictionary <string, object> rawCookie = new Dictionary <string, object> {
            };

            if (c.Name != null)
            {
                rawCookie["name"] = c.Name;
            }
            if (c.Domain != null)
            {
                rawCookie["domain"] = c.Domain;
            }
            ;
            if (c.Value != null)
            {
                rawCookie["value"] = c.Value;
            }
            ;
            if (c.Path != null)
            {
                rawCookie["path"] = c.Path;
            }
            ;
            rawCookie["httpOnly"] = c.HttpOnly ? "true" : "false";
            rawCookie["secure"]   = c.Secure ? "true" : "false";
            if (c.Expires != null)
            {
                rawCookie["expiry"] = c.Expires;
            }
            ;

            Cookie cookie = Cookie.FromDictionary(rawCookie);


            return(cookie);
        }