Пример #1
0
        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);
        }
Пример #2
0
        /// <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.");
        }
Пример #3
0
        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();
        }