public void Should_set_and_get_cookies() { using (var ie = new IE()) { // Clear all cookies. ie.ClearCookies(); // Ensure our test cookies don't exist from a previous run. Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie")); Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie")); // Create cookies for a pair of domains. ie.SetCookie("http://1.watin.com/", "test-cookie=abc; expires=Wed, 01-Jan-2020 00:00:00 GMT"); Assert.AreEqual("test-cookie=abc", ie.GetCookie("http://1.watin.com/", "test-cookie")); ie.SetCookie("http://2.watin.com/", "test-cookie=def; expires=Wed, 01-Jan-2020 00:00:00 GMT"); Assert.AreEqual("test-cookie=def", ie.GetCookie("http://2.watin.com/", "test-cookie")); CookieCollection collection = ie.GetCookiesForUrl(new Uri("http://2.watin.com/")); Assert.AreEqual(1, collection.Count); Assert.AreEqual(collection[0].Name, "test-cookie"); Assert.AreEqual(collection[0].Value, "def"); } }
public void Should_set_and_get_cookies() { using (var ie = new IE()) { // Clear all cookies. ie.ClearCookies(); // Ensure our test cookies don't exist from a previous run. Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie")); Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie")); // Create cookies for a pair of domains. ie.SetCookie("http://1.watin.com/", "test-cookie=abc; expires=Wed, 01-Jan-2020 00:00:00 GMT"); Assert.AreEqual("test-cookie=abc", ie.GetCookie("http://1.watin.com/", "test-cookie")); ie.SetCookie("http://2.watin.com/", "test-cookie=def; expires=Wed, 01-Jan-2020 00:00:00 GMT"); Assert.AreEqual("test-cookie=def", ie.GetCookie("http://2.watin.com/", "test-cookie")); CookieCollection collection = ie.GetCookiesForUrl(new Uri("http://2.watin.com/")); Assert.AreEqual(1, collection.Count); Assert.AreEqual(collection[0].Name, "test-cookie"); Assert.AreEqual(collection[0].Value, "def"); } }
private IEnumerable <Cookie> GetPersistentCookies(IE ieBrowser) { return(ieBrowser.GetCookiesForUrl(Watin.Uri).Cast <Cookie>()); }