private IEnumerable <Browser> GetBrowsers(List <Exception> asserts) { var response = new List <Browser>(); if (HasBrowserType(BrowserType.Chrome)) { try { var chrome = ChromeBrowser.AttachOrCreate(); chrome.AutoClose = AutoClose; chrome.SlowMotion = SlowMotion; response.Add(chrome); } catch (Exception ex) { asserts.Add(ex); } } if (HasBrowserType(BrowserType.Firefox)) { try { var firefox = FirefoxBrowser.AttachOrCreate(); firefox.AutoClose = AutoClose; firefox.SlowMotion = SlowMotion; response.Add(firefox); } catch (Exception ex) { asserts.Add(ex); } } if (HasBrowserType(BrowserType.InternetExplorer)) { try { var internetExplorer = InternetExplorerBrowser.AttachOrCreate(); internetExplorer.AutoClose = AutoClose; internetExplorer.SlowMotion = SlowMotion; response.Add(internetExplorer); } catch (Exception ex) { asserts.Add(ex); } } ArrangeBrowsers(response); return(response); }
public void Should_open_browser_then_close() { Process[] ieInstances = Process.GetProcessesByName("iexplore"); int numIeInstancesAtStart = ieInstances.Length; InternetExplorerBrowser browser = new InternetExplorerBrowser(); browser.OpenUrl(new Uri("http://google.com")); Thread.Sleep(5000); browser.Close(); ieInstances = Process.GetProcessesByName("iexplore"); Assert.AreEqual(numIeInstancesAtStart, ieInstances.Length, "We left an orphaned instance of IE running"); }
/// <summary> /// Create or attach a browser of the provided type. /// </summary> /// <typeparam name="T"></typeparam> /// <returns></returns> /// <exception cref="Exception"></exception> public static Browser AttachOrCreate <T>() { var type = typeof(T); if (type == typeof(ChromeBrowser)) { return(ChromeBrowser.AttachOrCreate()); } if (type == typeof(InternetExplorerBrowser)) { return(InternetExplorerBrowser.AttachOrCreate()); } throw new Exception("Invalid type provided."); }
protected override void ProcessRecord() { if (ClearCookies) { Browser.CloseBrowsers(BrowserType.InternetExplorer); InternetExplorerBrowser.ClearCookies(CookieUri ?? string.Empty); Thread.Sleep(250); WriteObject(new InternetExplorerBrowser()); return; } var browser = AttachExisting ? InternetExplorerBrowser.AttachOrCreate() : new InternetExplorerBrowser(); WriteObject(browser); base.ProcessRecord(); }
protected override void ProcessRecord() { Browser.CloseBrowsers(BrowserType.InternetExplorer); InternetExplorerBrowser.ClearCookies(Uri ?? string.Empty); base.ProcessRecord(); }