public static System.Net.Cookie ToNetCookie(this OpenQA.Selenium.Cookie seleniumCookie) { return(new System.Net.Cookie() { Name = seleniumCookie.Name, Value = seleniumCookie.Value, Path = seleniumCookie.Path, Domain = seleniumCookie.Domain, Expires = seleniumCookie.Expiry.HasValue ? seleniumCookie.Expiry.Value : DateTime.Now.AddYears(1)//没有过期时间,默认1年 }); }
public static System.Net.Cookie CookieConvert(OpenQA.Selenium.Cookie cookie) { System.Net.Cookie tempCookie = new System.Net.Cookie(); tempCookie.Domain = cookie.Domain; tempCookie.Expires = cookie.Expiry ?? DateTime.Today; tempCookie.HttpOnly = cookie.IsHttpOnly; tempCookie.Name = cookie.Name; tempCookie.Path = cookie.Path; tempCookie.Secure = cookie.Secure; tempCookie.Value = cookie.Value; return(tempCookie); }
public void LoadCookies(string filepath) { using (var file = new System.IO.StreamReader(filepath)) { var cookies = ((OpenQA.Selenium.Remote.RemoteWebDriver)Native).Manage().Cookies; string s; while ((s = file.ReadLine()) != null) { var data = s.Split(';'); var cookie = new OpenQA.Selenium.Cookie(data[0], data[1], data[2], data[3], null); cookies.AddCookie(cookie); } } }
// If we're proxied, then we'll do that here. protected void SetProxy(TestContext context, string locale = "en-us") { if (_sitecoreUrl == null) { return; } if (_environment != "test" && _environment == "dev") { throw new Exception("Can only set Sitecore proxy if we're in dev or test"); } var uri = new Uri(_sitecoreUrl); Console.WriteLine($"Proxying {_environment} to {_sitecoreUrl}"); var host = GetMonolithHost(locale); context.Driver.GoToUrl(host); var cookie = new OpenQA.Selenium.Cookie("SETTINGS", $"RemoteContentServer_Sitecore={_sitecoreUrl}"); context.Driver.Manage().Cookies.AddCookie(cookie); }
internal CookieProxy(OpenQA.Selenium.Cookie cookie) { _cookie = cookie; }