当前位置: 首页>>代码示例>>C#>>正文


C# Selenium.Cookie类代码示例

本文整理汇总了C#中OpenQA.Selenium.Cookie的典型用法代码示例。如果您正苦于以下问题:C# Cookie类的具体用法?C# Cookie怎么用?C# Cookie使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Cookie类属于OpenQA.Selenium命名空间,在下文中一共展示了Cookie类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GivenIAmLoggedIn

 public void GivenIAmLoggedIn()
 {
     var ticket = new FormsAuthenticationTicket(1, "[email protected]", DateTime.Now, DateTime.Now.AddDays(4), false, String.Empty);
     string encrypted = FormsAuthentication.Encrypt(ticket);
     var cookie = new Cookie(FormsAuthentication.FormsCookieName, encrypted);
     Driver.Manage().Cookies.AddCookie(cookie);
 }
开发者ID:r41lblast,项目名称:ndriven-cli,代码行数:7,代码来源:WebContext.cs

示例2: GetAllCookies

        public void GetAllCookies()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            string key1 = GenerateUniqueKey();
            string key2 = GenerateUniqueKey();

            AssertCookieIsNotPresentWithName(key1);
            AssertCookieIsNotPresentWithName(key2);
            
            ReadOnlyCollection<Cookie> cookies = driver.Manage().Cookies.AllCookies;
            int count = cookies.Count;

            Cookie one = new Cookie(key1, "value");
            Cookie two = new Cookie(key2, "value");

            driver.Manage().Cookies.AddCookie(one);
            driver.Manage().Cookies.AddCookie(two);

            driver.Url = simpleTestPage;
            cookies = driver.Manage().Cookies.AllCookies;
            Assert.AreEqual(count + 2, cookies.Count);

            Assert.IsTrue(cookies.Contains(one));
            Assert.IsTrue(cookies.Contains(two));
        }
开发者ID:BogdanLivadariu,项目名称:selenium,代码行数:29,代码来源:CookieImplementationTest.cs

示例3: AddCookiesWithDifferentPathsThatAreRelatedToOurs

        public void AddCookiesWithDifferentPathsThatAreRelatedToOurs()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            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.Cookies.AddCookie(cookie1);
            options.Cookies.AddCookie(cookie2);

            UrlBuilder builder = EnvironmentManager.Instance.UrlBuilder;
            driver.Url = builder.WhereIs("animals");

            ReadOnlyCollection<Cookie> cookies = options.Cookies.AllCookies;
            AssertCookieIsPresentWithName(cookie1.Name);
            AssertCookieIsPresentWithName(cookie2.Name);

            driver.Url = builder.WhereIs("simpleTest.html");
            AssertCookieIsNotPresentWithName(cookie1.Name);
        }
开发者ID:tommywo,项目名称:selenium,代码行数:25,代码来源:CookieImplementationTest.cs

示例4: CookieIntegrity

        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);
        }
开发者ID:v4viveksharma90,项目名称:selenium,代码行数:27,代码来源:CookieImplementationTest.cs

示例5: CanSetCookiesOnADifferentPathOfTheSameHost

        public void CanSetCookiesOnADifferentPathOfTheSameHost()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            string basePath = EnvironmentManager.Instance.UrlBuilder.Path;
            Cookie cookie1 = new Cookie("fish", "cod", "/" + basePath + "/animals");
            Cookie cookie2 = new Cookie("planet", "earth", "/" + basePath + "/galaxy");

            IOptions options = driver.Manage();
            ReadOnlyCollection<Cookie> count = options.Cookies.AllCookies;

            options.Cookies.AddCookie(cookie1);
            options.Cookies.AddCookie(cookie2);

            string url = EnvironmentManager.Instance.UrlBuilder.WhereIs("animals");
            driver.Url = url;
            ReadOnlyCollection<Cookie> cookies = options.Cookies.AllCookies;

            Assert.IsTrue(cookies.Contains(cookie1));
            Assert.IsFalse(cookies.Contains(cookie2));

            driver.Url = EnvironmentManager.Instance.UrlBuilder.WhereIs("galaxy");
            cookies = options.Cookies.AllCookies;
            Assert.IsFalse(cookies.Contains(cookie1));
            Assert.IsTrue(cookies.Contains(cookie2));
        }
开发者ID:tommywo,项目名称:selenium,代码行数:29,代码来源:CookieImplementationTest.cs

示例6: ShouldThrowExceptionWhenAddingCookieToAPageThatIsNotHtml

        public void ShouldThrowExceptionWhenAddingCookieToAPageThatIsNotHtml()
        {
            driver.Url = textPage;

            Cookie cookie = new Cookie("hello", "goodbye");
            driver.Manage().Cookies.AddCookie(cookie);
        }
开发者ID:Hemkumar,项目名称:selenium,代码行数:7,代码来源:TextPagesTest.cs

示例7: AddCookieTest

 public void AddCookieTest()
 {
     HomePage.WebDriver.Manage().Cookies.DeleteAllCookies();
     new Check().IsTrue(HomePage.WebDriver.Manage().Cookies.AllCookies.Count == 0);                                 
     Cookie cookie = new Cookie("key", "value");
     ContactFormPage.AddCookie(cookie);
     new Check().AreEquals(HomePage.WebDriver.Manage().Cookies.GetCookieNamed(cookie.Name).Value, cookie.Value);            
 }
开发者ID:epam,项目名称:JDI,代码行数:8,代码来源:PageTests.cs

示例8: ClearCacheTest

 public void ClearCacheTest()
 {
     Cookie cookie = new Cookie("key", "value");
     HomePage.WebDriver.Manage().Cookies.AddCookie(cookie);
     new Check().IsFalse(HomePage.WebDriver.Manage().Cookies.AllCookies.Count == 0);            
     ContactFormPage.ClearCache();
     new Check().IsTrue(HomePage.WebDriver.Manage().Cookies.AllCookies.Count == 0);                                 
 }
开发者ID:epam,项目名称:JDI,代码行数:8,代码来源:PageTests.cs

示例9: ShouldBeAbleToAddCookie

        public void ShouldBeAbleToAddCookie()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            string key = GenerateUniqueKey();
            string value = "foo";
            Cookie cookie = new Cookie(key, value);
            AssertCookieIsNotPresentWithName(key);

            driver.Manage().Cookies.AddCookie(cookie);

            AssertCookieHasValue(key, value);
            Assert.That(driver.Manage().Cookies.AllCookies.Contains(cookie), "Cookie was not added successfully");
        }
开发者ID:BogdanLivadariu,项目名称:selenium,代码行数:17,代码来源:CookieImplementationTest.cs

示例10: HandleSeleneseCommand

        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="driver">The driver used to execute the command.</param>
        /// <param name="locator">The first parameter to the command.</param>
        /// <param name="value">The second parameter to the command.</param>
        /// <returns>The result of the command.</returns>
        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            if (!this.NameValuePairRegex.IsMatch(locator))
            {
                throw new SeleniumException("Invalid parameter: " + locator);
            }

            Match nameValueMatch = this.NameValuePairRegex.Match(locator);
            string cookieName = nameValueMatch.Groups[1].Value;
            string cookieValue = nameValueMatch.Groups[2].Value;

            DateTime? maxAge = null;
            if (this.MaxAgeRegex.IsMatch(value))
            {
                Match maxAgeMatch = this.MaxAgeRegex.Match(value);
                maxAge = DateTime.Now.AddSeconds(int.Parse(maxAgeMatch.Groups[1].Value, CultureInfo.InvariantCulture));
            }

            string path = string.Empty;
            if (this.PathRegex.IsMatch(value))
            {
                Match pathMatch = this.PathRegex.Match(value);
                path = pathMatch.Groups[1].Value;
                try
                {
                    if (path.StartsWith("http", StringComparison.Ordinal))
                    {
                        path = new Uri(path).AbsolutePath;
                    }
                }
                catch (UriFormatException)
                {
                    // Fine.
                }
            }
            else
            {
                path = new Uri(driver.Url).AbsolutePath;
            }

            Cookie cookie = new Cookie(cookieName, cookieValue, path, maxAge);
            driver.Manage().Cookies.AddCookie(cookie);

            return null;
        }
开发者ID:Goldcap,项目名称:Constellation,代码行数:52,代码来源:CreateCookie.cs

示例11: AddCookiesWithDifferentPathsThatAreRelatedToOurs

        public void AddCookiesWithDifferentPathsThatAreRelatedToOurs()
        {
            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));
        }
开发者ID:v4viveksharma90,项目名称:selenium,代码行数:22,代码来源:CookieImplementationTest.cs

示例12: ShouldNotShowCookieAddedToDifferentPath

        public void ShouldNotShowCookieAddedToDifferentPath()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            // 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("Lisa", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName, "/" + EnvironmentManager.Instance.UrlBuilder.Path + "IDoNotExist", null);
            options.Cookies.AddCookie(cookie);
            ReadOnlyCollection<Cookie> cookies = options.Cookies.AllCookies;
            Assert.IsFalse(cookies.Contains(cookie), "Invalid cookie was returned");
        }
开发者ID:tommywo,项目名称:selenium,代码行数:23,代码来源:CookieImplementationTest.cs

示例13: ShouldRetainCookieExpiry

        public void ShouldRetainCookieExpiry()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            string url = EnvironmentManager.Instance.UrlBuilder.WhereElseIs("animals");

            driver.Url = url;
            driver.Manage().Cookies.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.Cookies.AddCookie(addCookie);

            Cookie retrieved = options.Cookies.GetCookieNamed("fish");
            Assert.IsNotNull(retrieved);
            Assert.AreEqual(addCookie.Expiry, retrieved.Expiry, "Cookies are not equal");
        }
开发者ID:tommywo,项目名称:selenium,代码行数:25,代码来源:CookieImplementationTest.cs

示例14: ShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod

        public void ShouldNotGetCookiesRelatedToCurrentDomainWithoutLeadingPeriod()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                return;
            }

            string cookieName = "name";
            AssertCookieIsNotPresentWithName(cookieName);

            Regex replaceRegex = new Regex(".*?\\.");
            string shorter = replaceRegex.Replace(this.hostname, ".", 1);
            Cookie cookie = new Cookie(cookieName, "value", shorter, "/", GetTimeInTheFuture());
            driver.Manage().Cookies.AddCookie(cookie);
            AssertCookieIsNotPresentWithName(cookieName);
        }
开发者ID:tommywo,项目名称:selenium,代码行数:16,代码来源:CookieImplementationTest.cs

示例15: ShouldNotShowCookieAddedToDifferentDomain

        public void ShouldNotShowCookieAddedToDifferentDomain()
        {
            if (!CheckIsOnValidHostNameForCookieTests())
            {
                Assert.Ignore("Not on a standard domain for cookies (localhost doesn't count).");
            }

            driver.Url = macbethPage;
            IOptions options = driver.Manage();
            Cookie cookie = new Cookie("Bart", "Simpson", EnvironmentManager.Instance.UrlBuilder.HostName + ".com", EnvironmentManager.Instance.UrlBuilder.Path, null);
            Assert.Throws<WebDriverException>(() => options.Cookies.AddCookie(cookie));
            ReadOnlyCollection<Cookie> cookies = options.Cookies.AllCookies;
            Assert.IsFalse(cookies.Contains(cookie), "Invalid cookie was returned");
        }
开发者ID:tommywo,项目名称:selenium,代码行数:14,代码来源:CookieImplementationTest.cs


注:本文中的OpenQA.Selenium.Cookie类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。