|
2#
楼主 |
发表于 2018-4-12 15:21:39
|
只看该作者
- case Browsers.Safari:
- {
- var allCookies = ((QA.Safari.SafariDriver)wd).Manage().Cookies.AllCookies;
- foreach (QA.Cookie cookie in allCookies)
- {
- cookies[cookie.Name] = cookie.Value;
- }
- }; break;
- case Browsers.PhantomJS:
- {
- var allCookies = ((QA.PhantomJS.PhantomJSDriver)wd).Manage().Cookies.AllCookies;
- foreach (QA.Cookie cookie in allCookies)
- {
- cookies[cookie.Name] = cookie.Value;
- }
- }; break;
- default:
- {
- var allCookies = ((QA.IE.InternetExplorerDriver)wd).Manage().Cookies.AllCookies;
- foreach (QA.Cookie cookie in allCookies)
- {
- cookies[cookie.Name] = cookie.Value;
- }
- }; break;
- }
- return cookies;
- }
- /// <summary>
- /// Delete all cookies from the page
- /// </summary>
- public void DeleteAllCookies()
- {
- switch (this.browser)
- {
- case Browsers.IE:
- {
- ((QA.IE.InternetExplorerDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- case Browsers.Chrome:
- {
- ((QA.Chrome.ChromeDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- case Browsers.Firefox:
- {
- ((QA.Firefox.FirefoxDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- case Browsers.Safari:
- {
- ((QA.Safari.SafariDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- case Browsers.PhantomJS:
- {
- ((QA.PhantomJS.PhantomJSDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- default:
- {
- ((QA.IE.InternetExplorerDriver)wd).Manage().Cookies.DeleteAllCookies();
- }; break;
- }
- }
- /// <summary>
- /// Set focus to a browser window with a specified title
- /// </summary>
- /// <param name="title"></param>
- /// <param name="exactMatch"></param>
- public void GoToWindow(string title, bool exactMatch)
- {
- string theCurrent = wd.CurrentWindowHandle;
- IList<string> windows = wd.WindowHandles;
- if (exactMatch)
- {
- foreach (var window in windows)
- {
- wd.SwitchTo().Window(window);
- if (wd.Title.ToLower() == title.ToLower())
- {
- return;
- }
- }
- }
- else
- {
- foreach (var window in windows)
- {
- wd.SwitchTo().Window(window);
- if (wd.Title.ToLower().Contains(title.ToLower()))
- {
- return;
- }
- }
- }
- wd.SwitchTo().Window(theCurrent);
- }
- /// <summary>
- /// Set focus to a frame with a specified name
- /// </summary>
- /// <param name="name"></param>
- public void GoToFrame(string name)
- {
- QA.IWebElement theFrame = null;
- var frames = wd.FindElements(QA.By.TagName("iframe"));
- foreach (var frame in frames)
- {
- if (frame.GetAttribute("name").ToLower() == name.ToLower())
- {
- theFrame = (QA.IWebElement)frame;
- break;
- }
- }
- if (theFrame != null)
- {
- wd.SwitchTo().Frame(theFrame);
- }
- }
- public void GoToFrame(QA.IWebElement frame)
- {
- wd.SwitchTo().Frame(frame);
- }
- /// <summary>
- /// Switch to default after going to a frame
- /// </summary>
- public void GoToDefault()
- {
- wd.SwitchTo().DefaultContent();
- }
- /// <summary>
- /// Get the alert text
- /// </summary>
- /// <returns></returns>
- public string GetAlertString()
- {
- string theString = string.Empty;
- QA.IAlert alert = null;
- alert = wd.SwitchTo().Alert();
- if (alert != null)
- {
- theString = alert.Text;
- }
- return theString;
- }
- /// <summary>
- /// Accepts the alert
- /// </summary>
- public void AlertAccept()
- {
- QA.IAlert alert = null;
- alert = wd.SwitchTo().Alert();
- if (alert != null)
- {
- alert.Accept();
- }
- }
- /// <summary>
- /// Dismisses the alert
- /// </summary>
- public void AlertDismiss()
- {
- QA.IAlert alert = null;
- alert = wd.SwitchTo().Alert();
- if (alert != null)
- {
- alert.Dismiss();
- }
- }
- /// <summary>
- /// Move vertical scroll bar to bottom for the page
- /// </summary>
- public void PageScrollToBottom()
- {
- var js = "document.documentElement.scrollTop=10000";
- switch (this.browser)
- {
- case Browsers.IE:
- {
- ((QA.IE.InternetExplorerDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Chrome:
- {
- ((QA.Chrome.ChromeDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Firefox:
- {
- ((QA.Firefox.FirefoxDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Safari:
- {
- ((QA.Safari.SafariDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.PhantomJS:
- {
- ((QA.PhantomJS.PhantomJSDriver)wd).ExecuteScript(js, null);
- }; break;
- default:
- {
- ((QA.IE.InternetExplorerDriver)wd).ExecuteScript(js, null);
- }; break;
- }
- }
- /// <summary>
- /// Move horizontal scroll bar to right for the page
- /// </summary>
- public void PageScrollToRight()
- {
- var js = "document.documentElement.scrollLeft=10000";
- switch (this.browser)
- {
- case Browsers.IE:
- {
- ((QA.IE.InternetExplorerDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Chrome:
- {
- ((QA.Chrome.ChromeDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Firefox:
- {
- ((QA.Firefox.FirefoxDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.Safari:
- {
- ((QA.Safari.SafariDriver)wd).ExecuteScript(js, null);
- }; break;
- case Browsers.PhantomJS:
- {
- ((QA.PhantomJS.PhantomJSDriver)wd).ExecuteScript(js, null);
- }; break;
- default:
- {
- ((QA.IE.InternetExplorerDriver)wd).ExecuteScript(js, null);
- }; break;
- }
- }
复制代码 |
|