public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService();
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.PhantomJs:
                driver = new PhantomJSDriver(options.DriversPath);

                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));

                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
示例#2
0
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            var driver = options.RemoteServerUrl != null?CreateRemoteDriver(options) : CreateLocalDriver(options);

            driver.Manage().Timeouts().PageLoad = options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
示例#3
0
        private static DriverOptions GetDriverOptions(BrowserOptions options)
        {
            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                return(options.ToChrome());

            case BrowserType.IE:
                return(options.ToInternetExplorer());

            case BrowserType.Firefox:
                return(options.ToFireFox());

            case BrowserType.Edge:
                return(options.ToEdge());

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }
        }
示例#4
0
        private static IWebDriver CreateLocalDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService();
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService, options.ToFireFox(), TimeSpan.FromMinutes(20));
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));
                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            return(driver);
        }
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService(options.DriversPath);
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome(), options.CommandTimeout);
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService(options.DriversPath);
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), options.CommandTimeout);
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService(options.DriversPath);
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService(options.DriversPath);
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), options.CommandTimeout);
                break;

            case BrowserType.Remote:
                ICapabilities capabilities = null;
                switch (options.RemoteBrowserType)
                {
                case BrowserType.Chrome:
                    capabilities = options.ToChrome().ToCapabilities();
                    break;

                case BrowserType.Firefox:
                    capabilities = options.ToFireFox().ToCapabilities();
                    break;
                }
                driver = new RemoteWebDriver(options.RemoteHubServer, capabilities, options.CommandTimeout);
                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = options.PageLoadTimeout;

            // StartMaximized overrides a set width & height
            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }
            else if (!options.StartMaximized && options.Width.HasValue && options.Height.HasValue)
            {
                driver.Manage().Window.Size = new System.Drawing.Size(options.Width.Value, options.Height.Value);
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
示例#6
0
 private static IWebDriver CreateRemoteDriver(BrowserOptions browserOptions)
 {
     return(new RemoteWebDriver(browserOptions.RemoteServerUrl, GetDriverOptions(browserOptions)));
 }
示例#7
0
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());

                /*
                 * // chrome headless driver
                 * ChromeOptions cOption = new ChromeOptions();
                 * cOption.AddArgument("--headless");
                 * driver = new ChromeDriver(cOption);
                 */
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService();
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.PhantomJs:
                var pOptions = new PhantomJSOptions();

                pOptions.AddAdditionalCapability(
                    "phantomjs.page.settings.userAgent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
                pOptions.AddAdditionalCapability("phantomjs.page.settings.resourceTimeout", "5000");

                var pService = PhantomJSDriverService.CreateDefaultService(options.DriversPath);
                pService.AddArgument("--ignore-ssl-errors=true");

                driver = new PhantomJSDriver(pService, pOptions, TimeSpan.FromMinutes(5));
                driver.Manage().Window.Size = new System.Drawing.Size(1280, 1024);
                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Remote:
                // make sure selenium standalone server is running
                DesiredCapabilities capabilities = DesiredCapabilities.HtmlUnit();
                driver = new RemoteWebDriver(capabilities);
                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 5, 0);             //options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
示例#8
0
        public InteractiveBrowser(BrowserOptions options)
        {
            this.Options = options;

            Trace = new TraceSource(this.Options.TraceSource);
        }