public void CanSetCookiesOnADifferentPathOfTheSameHost() { IOptions options = driver.Manage(); driver.Url = simpleTestPage; options.DeleteAllCookies(); string basePath = EnvironmentManager.Instance.UrlBuilder.Path; ReadOnlyCollection <Cookie> count = options.GetCookies(); Cookie cookie1 = new Cookie("fish", "cod", "/" + basePath + "/animals"); Cookie cookie2 = new Cookie("planet", "earth", "/" + basePath + "/galaxy"); options.AddCookie(cookie1); options.AddCookie(cookie2); string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("animals"); driver.Url = url; ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsTrue(cookies.Contains(cookie1)); Assert.IsFalse(cookies.Contains(cookie2)); driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("galaxy"); cookies = options.GetCookies(); Assert.IsFalse(cookies.Contains(cookie1)); Assert.IsTrue(cookies.Contains(cookie2)); }
public void AddCookiesWithDifferentPathsThatAreRelatedToOurs() { driver.Url = simpleTestPage; driver.Manage().DeleteAllCookies(); string basePath = EnvironmentManager.Instance.UrlBuilder.Path; Cookie cookie1 = new Cookie("fish", "cod", "/" + basePath + "/animals"); Cookie cookie2 = new Cookie("planet", "earth", "/" + basePath + "/"); IOptions options = driver.Manage(); options.AddCookie(cookie1); options.AddCookie(cookie2); UrlBuilder builder = EnvironmentManager.Instance.UrlBuilder; driver.Url = builder.WhereIs("animals"); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsTrue(cookies.Contains(cookie1)); Assert.IsTrue(cookies.Contains(cookie2)); driver.Url = builder.WhereIs(""); cookies = options.GetCookies(); Assert.IsFalse(cookies.Contains(cookie1)); Assert.IsTrue(cookies.Contains(cookie2)); }
public void CookieIntegrity() { string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals"); driver.Url = url; driver.Manage().DeleteAllCookies(); DateTime time = DateTime.Now.AddDays(1); Cookie cookie1 = new Cookie("fish", "cod", null, "/common/animals", time); IOptions options = driver.Manage(); options.AddCookie(cookie1); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Cookie retrievedCookie = null; foreach (Cookie tempCookie in cookies) { if (cookie1.Equals(tempCookie)) { retrievedCookie = tempCookie; break; } } Assert.IsNotNull(retrievedCookie); //Cookie.equals only compares name, domain and path Assert.AreEqual(cookie1, retrievedCookie); }
public void ShouldNotDeleteCookiesWithASimilarName() { string cookieOneName = "fish"; Cookie cookie1 = new Cookie(cookieOneName, "cod"); Cookie cookie2 = new Cookie(cookieOneName + "x", "earth"); IOptions options = driver.Manage(); options.AddCookie(cookie1); options.AddCookie(cookie2); options.DeleteCookieNamed(cookieOneName); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsFalse(driver.Manage().GetCookies().Contains(cookie1)); Assert.IsTrue(driver.Manage().GetCookies().Contains(cookie2)); }
public void ShouldDeleteCookie() { driver.Url = macbethPage; IOptions options = driver.Manage(); Cookie cookieToDelete = new Cookie("answer", "42"); Cookie cookieToKeep = new Cookie("canIHaz", "Cheeseburguer"); options.AddCookie(cookieToDelete); options.AddCookie(cookieToKeep); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); options.DeleteCookie(cookieToDelete); ReadOnlyCollection <Cookie> cookies2 = options.GetCookies(); Assert.IsFalse(cookies2.Contains(cookieToDelete), "Cookie was not deleted successfully"); Assert.That(cookies2.Contains(cookieToKeep), "Valid cookie was not returned"); }
// TODO(JimEvans): Disabling this test for now. If your network is using // something like OpenDNS or Google DNS which you may be automatically // redirected to a search page, which will be a valid page and will allow a // cookie to be created. Need to investigate further. // [Test] // [ExpectedException(typeof(InvalidOperationException))] public void ShouldThrowExceptionWhenAddingCookieToNonExistingDomain() { driver.Url = macbethPage; driver.Url = "doesnot.noireallyreallyreallydontexist.com"; IOptions options = driver.Manage(); Cookie cookie = new Cookie("question", "dunno"); options.AddCookie(cookie); }
public void ShouldNotShowCookieAddedToDifferentPath() { driver.Url = macbethPage; IOptions options = driver.Manage(); Cookie cookie = new Cookie("Lisa", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName, "/" + EnvironmentManager.Instance.UrlBuilder.Path + "IDoNotExist", null); options.AddCookie(cookie); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsFalse(cookies.Contains(cookie), "Invalid cookie was returned"); }
public void ShouldAddCookieToCurrentDomain() { driver.Url = macbethPage; IOptions options = driver.Manage(); Cookie cookie = new Cookie("Marge", "Simpson", "/"); options.AddCookie(cookie); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.That(cookies.Contains(cookie), "Valid cookie was not returned"); }
public void ShouldNotBeAbleToSetDomainToSomethingThatIsUnrelatedToTheCurrentDomain() { Cookie cookie1 = new Cookie("fish", "cod"); IOptions options = driver.Manage(); options.AddCookie(cookie1); string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("simpleTest.html"); driver.Url = url; Assert.IsNull(options.GetCookieNamed("fish")); }
public void ShouldBeAbleToSetDomainToTheCurrentDomain() { Uri url = new Uri(driver.Url); String host = url.Host + ":" + url.Port.ToString(); Cookie cookie1 = new Cookie("fish", "cod", host, "/", null); IOptions options = driver.Manage(); options.AddCookie(cookie1); driver.Url = javascriptPage; ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsTrue(cookies.Contains(cookie1)); }
public void GetCookieDoesNotRetriveBeyondCurrentDomain() { Cookie cookie1 = new Cookie("fish", "cod"); IOptions options = driver.Manage(); options.AddCookie(cookie1); String url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs(""); driver.Url = url; ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.IsFalse(cookies.Contains(cookie1)); }
public void SettingACookieThatExpiredInThePast() { string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals"); driver.Url = url; driver.Manage().DeleteAllCookies(); DateTime expires = DateTime.Now.AddSeconds(-1000); Cookie cookie = new Cookie("expired", "yes", "/common/animals", expires); IOptions options = driver.Manage(); options.AddCookie(cookie); cookie = options.GetCookieNamed("fish"); Assert.IsNull(cookie, "Cookie expired before it was set, so nothing should be returned: " + cookie); }
public void ShouldReturnNullBecauseCookieRetainsExpiry() { string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals"); driver.Url = url; driver.Manage().DeleteAllCookies(); Cookie addCookie = new Cookie("fish", "cod", "/common/animals", DateTime.Now.AddHours(-1)); IOptions options = driver.Manage(); options.AddCookie(addCookie); Cookie retrieved = options.GetCookieNamed("fish"); Assert.IsNull(retrieved); }
public void ShouldBeAbleToAddCookie() { driver.Url = simpleTestPage; IOptions options = driver.Manage(); options.DeleteAllCookies(); string key = string.Format("key_{0}", new Random().Next()); Cookie cookie = new Cookie(key, "foo"); ((IJavaScriptExecutor)driver).ExecuteScript("return document.cookie"); options.AddCookie(cookie); string current = (string)((IJavaScriptExecutor)driver).ExecuteScript("return document.cookie"); Assert.IsTrue(current.Contains(key)); Assert.That(options.GetCookies().Contains(cookie), "Cookie was not added successfully"); }
public void ShouldAddCookieToCurrentDomainAndPath() { // Cookies cannot be set on domain names with less than 2 dots, so // localhost is out. If we are in that boat, bail the test. string hostName = EnvironmentManager.Instance.UrlBuilder.HostName; string[] hostNameParts = hostName.Split(new char[] { '.' }); if (hostNameParts.Length < 3) { Assert.Ignore("Skipping test: Cookies can only be set on fully-qualified domain names."); } driver.Url = macbethPage; IOptions options = driver.Manage(); Cookie cookie = new Cookie("Homer", "Simpson", hostName, "/" + EnvironmentManager.Instance.UrlBuilder.Path, null); options.AddCookie(cookie); ReadOnlyCollection <Cookie> cookies = options.GetCookies(); Assert.That(cookies.Contains(cookie), "Valid cookie was not returned"); }
public void ShouldRetainCookieExpiry() { string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals"); driver.Url = url; driver.Manage().DeleteAllCookies(); // DateTime.Now contains milliseconds; the returned cookie expire date // will not. So we need to truncate the milliseconds. DateTime current = DateTime.Now; DateTime expireDate = new DateTime(current.Year, current.Month, current.Day, current.Hour, current.Minute, current.Second, DateTimeKind.Local).AddDays(1); Cookie addCookie = new Cookie("fish", "cod", "/common/animals", expireDate); IOptions options = driver.Manage(); options.AddCookie(addCookie); Cookie retrieved = options.GetCookieNamed("fish"); Assert.IsNotNull(retrieved); Assert.AreEqual(addCookie.Expiry, retrieved.Expiry, "Cookies are not equal"); }