本文整理汇总了C#中IE.SetCookie方法的典型用法代码示例。如果您正苦于以下问题:C# IE.SetCookie方法的具体用法?C# IE.SetCookie怎么用?C# IE.SetCookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IE
的用法示例。
在下文中一共展示了IE.SetCookie方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Should_set_and_get_cookies
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");
}
}
示例2: Should_clear_cookies
public void Should_clear_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"), "Expected no cookies for 1.watin.com");
Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected no cookies for 2.watin.com");
// 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");
ie.SetCookie("http://2.watin.com/", "test-cookie=def; expires=Wed, 01-Jan-2020 00:00:00 GMT");
// Clear cookies under one subdomain.
ie.ClearCookies("http://1.watin.com/");
// Ensure just the cookie of the first subdomain was deleted.
Assert.IsNull(ie.GetCookie("http://1.watin.com/", "test-cookie"), "Expected no cookies for 1.watin.com after clear");
Assert.AreEqual("test-cookie=def", ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected cookie for 2.watin.com");
// Clear cookies under master domain.
ie.ClearCookies("http://watin.com/");
// Ensure the second subdomain's cookie was deleted this time.
Assert.IsNull(ie.GetCookie("http://2.watin.com/", "test-cookie"), "Expected no cookies for 2.watin.com after ClearCookies");
}
}