Пример #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name=""></param>
 /// <returns></returns>
 public static void LoadSafariDriver(int CurrentAttempt)
 {
     if (CurrentAttempt <= BrowserRetryMax)
     {
         try
         {
             if (CurrentAttempt == 0)
             {
                 KillSafariDriver();
             }
             SafariDriverService serv = SafariDriverService.CreateDefaultService("/Applications/Safari Technology Preview.app/Contents/MacOS/", "safaridriver");
             SafariOptions       opts = new SafariOptions();
             opts.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
             opts.AddAdditionalCapability(CapabilityType.AcceptInsecureCertificates, true);
             opts.AddAdditionalCapability("cleanSession", true);
             webDriver = new SafariDriver(serv, opts);
             Test.Log.Message("Safari " + browserVersion);
         }
         catch (Exception ex)
         {
             Test.Log.Message("Error Safari driver failed to load: " + ex.Message);
             LoadSafariDriver(CurrentAttempt++);
         }
     }
 }
Пример #2
0
        private void SetSafariService()
        {
            try
            {
                SafariDriverService service = SafariDriverService.CreateDefaultService(Directory.GetParent(BaseSettings.SafariDriverLocation).FullName);
                if (BaseSettings.SafariDriverLocation != null || Safari.Port > 0)
                {
                    SetDriverPort(service);
                    SafariDriverService = service;
                    Console.Out.WriteLine("Built Safari Driver Service");
                }
            }
            catch (Exception ex)
            {
                switch (BaseSettings.DebugLevel)
                {
                case EnumConsoleDebugLevel.Human:
                    Console.Out.WriteLine("Could not start the safari driver service.");
                    Console.Out.WriteLine("Please investigate the changes you have made to your config file.");
                    break;

                case EnumConsoleDebugLevel.NotSpecified:
                case EnumConsoleDebugLevel.Message:
                    Console.Out.WriteLine(ex.Message);
                    break;

                case EnumConsoleDebugLevel.StackTrace:
                    Console.Out.WriteLine(ex.Message);
                    Console.Out.WriteLine(ex.StackTrace);
                    break;
                }
            }
        }
        RemoteWebDriver CreateLocalDriver()
        {
            switch (this.config.BrowserType)
            {
            case BrowserType.Firefox:
                var firefoxOptions = CreateFirefoxOptions();
                var firefoxService = FirefoxDriverService.CreateDefaultService(this.config.SeleniumDriversPath);
                return(new FirefoxDriver(firefoxService, firefoxOptions, BrowserLoadTimeout));

            case BrowserType.FirefoxGecko:
                var firefoxGeckoOptions = CreateFirefoxGeckoOptions();
                var firefoxGeckoSerice  = FirefoxDriverService.CreateDefaultService(this.config.SeleniumDriversPath);
                return(new FirefoxDriver(firefoxGeckoSerice, firefoxGeckoOptions, BrowserLoadTimeout));

            case BrowserType.FirefoxGeckoHeadless:
                var firefoxGeckoHeadlessOptions = CreateFirefoxGeckoHeadlessOptions();
                var firefoxGeckoHeadlessSerice  = FirefoxDriverService.CreateDefaultService(this.config.SeleniumDriversPath);
                return(new FirefoxDriver(firefoxGeckoHeadlessSerice, firefoxGeckoHeadlessOptions, BrowserLoadTimeout));

            case BrowserType.Chrome:
                var chromeOptions = CreateChromeOptions();
                return(new ChromeDriver(this.config.SeleniumDriversPath, chromeOptions));

            case BrowserType.ChromeHeadless:
                var chromeHeadlessOptions = CreateChromeHeadlessOptions();
                return(new ChromeDriver(this.config.SeleniumDriversPath, chromeHeadlessOptions));

            case BrowserType.InternetExplorer:
                var internetExplorerOptions = CreateInternetExplorerOptions();
                return(new InternetExplorerDriver(this.config.SeleniumDriversPath, internetExplorerOptions));

            case BrowserType.Opera:
                var operaOptions = CreateOperaOptions();
                return(new OperaDriver(this.config.SeleniumDriversPath, operaOptions));

            case BrowserType.OperaHeadless:
                var operaHeadlessOptions = CreateOperaHeadlessOptions();
                return(new OperaDriver(this.config.SeleniumDriversPath, operaHeadlessOptions));

            case BrowserType.Safari:
                var safariOptions = CreateSafariOptions();
                var safariService = SafariDriverService.CreateDefaultService(this.config.SeleniumDriversPath);
                return(new SafariDriver(safariService, safariOptions));

            case BrowserType.Phantom:
                var phantomJsOptions = CreatePhantomJsOptions();
                return(new PhantomJSDriver(this.config.SeleniumDriversPath, phantomJsOptions));

            case BrowserType.Edge:
                var edgeOptions = CreateEdgeOptions();
                return(new EdgeDriver(this.config.SeleniumDriversPath, edgeOptions));

            default:
                throw new ArgumentOutOfRangeException(nameof(this.config.BrowserType), this.config.BrowserType, null);
            }
        }
        private (DriverService, IWebDriver) GetSafariDriver(ILogger logger)
        {
            var options = new SafariOptions();

            options.SetLoggingPreference(LogType.Browser, SeleniumLogLevel.All);

            logger.LogInformation("Starting Safari");

            var driverService = SafariDriverService.CreateDefaultService();

            return(driverService, new SafariDriver(driverService, options, _arguments.Timeout));
        }
Пример #5
0
        public static RemoteWebDriver CreateLocalDriver(BrowserType driverType, string driversPath)
        {
            switch (driverType)
            {
            case BrowserType.Firefox:
                var firefoxOptions = new FirefoxOptions
                {
                    Profile = new FirefoxProfile {
                        DeleteAfterUse = true
                    },
                    UseLegacyImplementation = true
                };
                var firefoxService = FirefoxDriverService.CreateDefaultService(driversPath);
                return(new FirefoxDriver(firefoxService, firefoxOptions, BrowserLoadTimeout));

            case BrowserType.FirefoxGecko:
                var firefoxGeckoOptions = new FirefoxOptions
                {
                    Profile = new FirefoxProfile {
                        DeleteAfterUse = true
                    }
                };
                var firefoxGeckoSerice = FirefoxDriverService.CreateDefaultService(driversPath);
                return(new FirefoxDriver(firefoxGeckoSerice, firefoxGeckoOptions, BrowserLoadTimeout));

            case BrowserType.Chrome:
                return(new ChromeDriver(driversPath));

            case BrowserType.ChromeExtended:
                return(new ChromeDriverExtended(driversPath));

            case BrowserType.InternetExplorer:
                return(new InternetExplorerDriver(driversPath));

            case BrowserType.Opera:
                return(new OperaDriver(driversPath));

            case BrowserType.Safari:
                var safariService = SafariDriverService.CreateDefaultService(driversPath);
                return(new SafariDriver(safariService));

            case BrowserType.Phantom:
                return(new PhantomJSDriver(driversPath));

            case BrowserType.Edge:
                return(new EdgeDriver(driversPath));

            default:
                throw new ArgumentOutOfRangeException(nameof(driverType), driverType, null);
            }
        }
Пример #6
0
        private static IWebDriver CreateSeleniumDriver(this SpecFlowContext specFlowContext, IConfiguration configuration)
        {
            System.Enum.TryParse(configuration[Constants.EnvironmentVariableKeys.Browser], true, out BrowserTypes browser);

            switch (browser)
            {
            case BrowserTypes.Edge:
                EdgeOptions egdeOptions = new EdgeOptions
                {
                    PageLoadStrategy = PageLoadStrategy.Normal,
                    UseChromium      = true
                };

                EdgeDriverService edgeDriverService = EdgeDriverService.CreateChromiumService(configuration[Constants.EnvironmentVariableKeys.EdgeWebDriver]);

                specFlowContext.Set((IWebDriver) new EdgeDriver(edgeDriverService, egdeOptions));
                break;

            case BrowserTypes.Firefox:
                specFlowContext.Set((IWebDriver) new FirefoxDriver());
                break;

            case BrowserTypes.InternetExplorer:

                InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions()
                {
                    BrowserVersion  = configuration[Constants.EnvironmentVariableKeys.InternetExplorerVersion],
                    IgnoreZoomLevel = true
                };

                specFlowContext.Set((IWebDriver) new InternetExplorerDriver(internetExplorerOptions));
                break;

            case BrowserTypes.Safari:
                SafariDriverService safariDriverService = SafariDriverService.CreateDefaultService();
                SafariOptions       safariOptions       = new SafariOptions();
                safariOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                specFlowContext.Set((IWebDriver) new SafariDriver(safariDriverService));
                break;

            default:
            {
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
                chromeDriverService.SuppressInitialDiagnosticInformation = true;
                specFlowContext.Set((IWebDriver) new ChromeDriver(chromeDriverService));
            }
            break;
            }

            return(specFlowContext.Get <IWebDriver>());
        }
Пример #7
0
 private void SetDriverPort(SafariDriverService service)
 {
     try
     {
         if (Safari.Port != null && Safari.Port > 0)
         {
             service.Port = Safari.Port.Value;
             Console.Out.WriteLine("\nAdded port {0} to the driver.", Safari.Port.ToString());
         }
         Console.Out.WriteLine();
     }
     catch (Exception)
     {
         Console.Out.WriteLine("\nCould not assign port to driver.");
     }
 }
Пример #8
0
        public RemoteWebDriver CreateDriver()
        {
            var options = optionsCreator?.Invoke() ?? new SafariOptions();

            foreach (var optionsInitializer in optionsInitializers)
            {
                optionsInitializer(options);
            }

            SafariDriverService driverService = driverServiceCreator?.Invoke()
                                                ?? (driverPath != null && driverExecutableFileName != null
                    ? SafariDriverService.CreateDefaultService(driverPath, driverExecutableFileName)
                    : driverPath != null
                        ? SafariDriverService.CreateDefaultService(driverPath)
                        : SafariDriverService.CreateDefaultService());

            return(new SafariDriver(driverService, options, commandTimeout ?? TimeSpan.FromSeconds(60)));
        }
        public override IWebDriver LocalDriver(object options)
        {
            SafariDriverService driverService = null;
            IWebDriver          driver;

            try
            {
                driverService = GetDefaultService <SafariDriverService>();
                var safariOptions = options == null?SafariOptions() : (SafariOptions)options;

                driver = new SafariDriver(driverService, safariOptions, Timeout);
            }
            catch
            {
                driverService?.Dispose();
                throw;
            }
            return(driver);
        }
Пример #10
0
        /// <summary>
        /// Start browser specific driver service
        /// </summary>
        /// <param name="parameters"><see cref="TestEnvironmentParameters"/></param>
        private static void StartBrowserService(TestEnvironmentParameters parameters)
        {
            OpenQA.Selenium.DriverService service;

            switch (parameters.RS_BrowserName.ToUpper())
            {
            case "CHROME":
                service          = ChromeDriverService.CreateDefaultService(parameters.RS_DriverServerExePath);
                service.HostName = parameters.RS_ServerHost;
                service.Port     = Convert.ToInt32(parameters.RS_ServerPort);

                Get(() => service.Start(), "Chrome");
                break;

            case "IE":
                service          = InternetExplorerDriverService.CreateDefaultService(parameters.RS_DriverServerExePath);
                service.HostName = parameters.RS_ServerHost;
                service.Port     = Convert.ToInt32(parameters.RS_ServerPort);
                Get(() => service.Start(), "ie");
                break;

            case "EDGE":
                service          = EdgeDriverService.CreateDefaultService(parameters.RS_DriverServerExePath);
                service.HostName = parameters.RS_ServerHost;
                service.Port     = Convert.ToInt32(parameters.RS_ServerPort);
                Get(() => service.Start(), "Edge");
                break;

            case "SAFARI":
                service          = SafariDriverService.CreateDefaultService(parameters.RS_DriverServerExePath);
                service.HostName = parameters.RS_ServerHost;
                service.Port     = Convert.ToInt32(parameters.RS_ServerPort);
                Get(() => service.Start(), "Safari");
                break;

            default:
                throw new DriverServiceException($"Driver for {parameters.RS_BrowserName} not supported.");
            }

            WebTestContext.Set(Constants.DriverServiceKey, service);
            parameters.ServerUri = service.ServiceUrl;
        }
Пример #11
0
        private RemoteWebDriver GetBrowserDriverToRunInBackground(BrowserEnum browser)
        {
            switch (browser)
            {
            case BrowserEnum.Firefox:
                var firefoxService = FirefoxDriverService.CreateDefaultService();
                firefoxService.HideCommandPromptWindow = true;
                var firefoxDriver = new FirefoxDriver(firefoxService);
                return(firefoxDriver);

            case BrowserEnum.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = true;
                var chromeDriver = new ChromeDriver(chromeService);
                return(chromeDriver);

            case BrowserEnum.InternetExplorer:
                var internetExplorerService = InternetExplorerDriverService.CreateDefaultService();
                internetExplorerService.HideCommandPromptWindow = true;
                var internetExplorerDriver = new InternetExplorerDriver(internetExplorerService);
                return(internetExplorerDriver);

            case BrowserEnum.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = true;
                var options    = new EdgeOptions();
                var edgeDriver = new EdgeDriver(edgeService, options);
                return(edgeDriver);

            case BrowserEnum.Safari:
                var safariService = SafariDriverService.CreateDefaultService();
                safariService.HideCommandPromptWindow = true;
                var safariDriver = new SafariDriver(safariService);
                return(safariDriver);

            default:
                throw new Exception("Browser not found for provided enum value.");
            }
        }
Пример #12
0
        private QA.IWebDriver InitWebDriver(string cache_dir, bool loadImage = true, string useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36")
        {
            if (!Directory.Exists(cache_dir))
            {
                Directory.CreateDirectory(cache_dir);
            }
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver  = new QA.IE.InternetExplorerDriver(driverService, _ieOptions);
                _ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.Chrome:
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.Port = new Random().Next(1000, 2000);
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                ChromeOptions options = new QA.Chrome.ChromeOptions();
                options.AddArgument("--window-size=" + Screen.PrimaryScreen.WorkingArea.Width + "x" + Screen.PrimaryScreen.WorkingArea.Height);
                options.AddArgument("--disable-gpu");
                options.AddArgument("--disable-extensions");
                options.AddArgument("--no-sandbox");
                options.AddArgument("--disable-dev-shm-usage");
                options.AddArgument("--disable-java");
                options.AddArgument("--user-agent=" + useragent);
                options.AddArgument(@"--user-data-dir=" + cache_dir);
                if (loadImage == false)
                {
                    options.AddUserProfilePreference("profile.managed_default_content_settings.images", 2);        //不加载图片
                }
                theDriver  = new QA.Chrome.ChromeDriver(driverService, options, TimeSpan.FromSeconds(240));
                _ProcessID = driverService.ProcessId;
            };
                break;

            case Browsers.Firefox:
            {
                var driverService = FirefoxDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                FirefoxProfile profile = new FirefoxProfile();
                if (loadImage == false)
                {
                    profile.SetPreference("permissions.default.image", 2);
                    // 关掉flash
                    profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
                }
                FirefoxOptions options = new FirefoxOptions();
                options.Profile = profile;
                theDriver       = new QA.Firefox.FirefoxDriver(driverService, options, TimeSpan.FromMinutes(240));
                _ProcessID      = driverService.ProcessId;
            };
                break;

            case Browsers.Safari:
            {
                SafariDriverService driverService = SafariDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds         = driverService;
                theDriver  = new QA.Safari.SafariDriver(driverService);
                _ProcessID = driverService.ProcessId;
            };
                break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            };
                break;
            }
            //theDriver.Manage().Window.Maximize();
            return(theDriver);
        }
Пример #13
0
        public static void Initialize(string baseUrl, int COD_BROWSER, string IE_DRIVER_PATH, string CHROME_DRIVER_PATH, string FIREFOX_DRIVER_PATH, string SAFARI_DRIVER_PATH, string EDGE_DRIVER_PATH, string OPERA_DRIVER_PATH)
        {
            //Overall Config
            isWebDriverOpen = true;
            TopDown_QA_FrameWork.Driver.baseUrl = baseUrl;
            PRINT_CONT = 0;

            switch (COD_BROWSER)
            {
            case IE_BROWSER:
                //IE Configurações
                opcoesIE = new InternetExplorerOptions();
                //new
                //opcoesIE.RequireWindowFocus = true;
                //opcoesIE.PageLoadStrategy = InternetExplorerPageLoadStrategy.Eager;
                //opcoesIE.EnablePersistentHover = true;
                //opcoesIE.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Top;
                //
                //opcoesIE.ForceCreateProcessApi = true;
                opcoesIE.EnableNativeEvents = true;
                opcoesIE.EnsureCleanSession = true;
                //opcoesIE.RequireWindowFocus = true;
                opcoesIE.PageLoadStrategy = InternetExplorerPageLoadStrategy.Normal;
                opcoesIE.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                ieService = InternetExplorerDriverService.CreateDefaultService(IE_DRIVER_PATH);
                //ieService = InternetExplorerDriverService.CreateDefaultService(@"D:\Peterson\Projetos\QADynamicFramework\UI_test_player_TD\bin\Debug\WebDriver\IEDriverServer_Win32_2.53.1");
                //ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.HideCommandPromptWindow = true;
                webDriver = new InternetExplorerDriver(ieService, opcoesIE);
                break;

            case CHROME_BROWSER:
                //// Chrome
                opcoesChrome = new ChromeOptions();
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(CHROME_DRIVER_PATH);
                chromeDriverService.HideCommandPromptWindow = true;
                webDriver = new ChromeDriver(chromeDriverService, opcoesChrome);
                break;

            case FIREFOX_BROWSER:
                //Firefox Configurações
                opcoesFirefox = new FirefoxOptions();
                FirefoxDriverService firefoxDriverService = FirefoxDriverService.CreateDefaultService(FIREFOX_DRIVER_PATH);
                firefoxDriverService.HideCommandPromptWindow = true;
                FirefoxProfile ffProfile = new FirefoxProfile();
                ffProfile.EnableNativeEvents = true;
                webDriver = new FirefoxDriver(firefoxDriverService);
                break;

            case SAFARI_BROWSER:
                opcoesSafari = new SafariOptions();
                SafariDriverService safariDriverservice = SafariDriverService.CreateDefaultService();
                webDriver = new SafariDriver();
                //Logger.abrir();
                //DesiredCapabilities caps = new DesiredCapabilities();
                //caps.SetCapability("browserName", "safari");
                //caps.SetCapability("plataform", "WINDOWS");
                //webDriver = new RemoteWebDriver(new Uri("http://google.com"), caps);
                break;

            case EDGE_BROWSER:
                opcoesEdge = new EdgeOptions();
                EdgeDriverService edgeDriverService = EdgeDriverService.CreateDefaultService(EDGE_DRIVER_PATH);
                opcoesEdge.AddAdditionalCapability("nativeEvents", true);
                edgeDriverService.HideCommandPromptWindow = true;
                webDriver = new EdgeDriver(edgeDriverService, opcoesEdge);
                break;

            case OPERA_BROWSER:
                opcoesOpera = new OperaOptions();
                OperaDriverService operaDriverService = OperaDriverService.CreateDefaultService(OPERA_DRIVER_PATH);
                opcoesOpera.AddAdditionalCapability("nativeEvents", true);
                operaDriverService.HideCommandPromptWindow = true;
                webDriver = new OperaDriver(operaDriverService, opcoesOpera);
                break;
            }

            //Post Configuration
            wait  = new WebDriverWait(webDriver, new TimeSpan(0, 0, 30));
            acoes = new Actions(webDriver);
            webDriver.Navigate().GoToUrl(baseUrl);
            webDriver.Manage().Window.Maximize();
            //webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(30));
        }
Пример #14
0
 public SafariTechnologyPreviewDriver(SafariDriverService service, SafariOptions options)
     : base(service, options)
 {
 }
Пример #15
0
 public DefaultSafariDriver(SafariDriverService service, SafariOptions options)
     : base(service, options)
 {
 }
Пример #16
0
        private QA.IWebDriver InitWebDriver()
        {
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(driverService, _ieOptions);
                ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.PhantomJS:
            {
                PhantomJSDriverService driverService = PhantomJSDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                theDriver = new QA.PhantomJS.PhantomJSDriver(driverService);
            }; break;

            case Browsers.Chrome:
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                ChromeOptions options = new QA.Chrome.ChromeOptions();
                options.AddUserProfilePreference("profile.managed_default_content_settings.images", _IsLoadPicture ? 1 : 2);
                options.AddUserProfilePreference("profile.managed_default_content_settings.javascript", _IsLoadJS ? 1 : 2);

                //options.AddArgument(@"--user-data-dir=" + cache_dir);
                //string dir = string.Format(@"user-data-dir={0}", ConfigManager.GetInstance().UserDataDir);
                //options.AddArguments(dir);

                //options.AddArgument("--no-sandbox");
                //options.AddArgument("--disable-dev-shm-usage");
                //options.AddArguments("--disable-extensions"); // to disable extension
                //options.AddArguments("--disable-notifications"); // to disable notification
                //options.AddArguments("--disable-application-cache"); // to disable cache
                try
                {
                    if (_timeout == 60)
                    {
                        theDriver = new QA.Chrome.ChromeDriver(driverService, options, new TimeSpan(0, 0, 40));
                    }
                    else
                    {
                        theDriver = new QA.Chrome.ChromeDriver(driverService, options, new TimeSpan(0, 0, _timeout));
                    }
                }
                catch (Exception ex)
                {
                }
                ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.Firefox:
            {
                var driverService = FirefoxDriverService.CreateDefaultService(Application.StartupPath + "\\drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;

                FirefoxProfile profile = new FirefoxProfile();
                try
                {
                    if (_doproxy == "1")
                    {
                        string proxy = "";
                        try
                        {
                            if (_IsUseNewProxy == false)
                            {
                                proxy = GetProxyA();
                            }
                            else
                            {
                                //TO DO 获取芝麻代理
                                hi.URL = "http:......?你的代理地址";        // ConfigManager.GetInstance().ProxyUrl;
                                hr     = hh.GetContent(hi);
                                if (hr.StatusCode == System.Net.HttpStatusCode.OK)
                                {
                                    if (hr.Content.Contains("您的套餐余量为0"))
                                    {
                                        proxy = "";
                                    }
                                    if (hr.Content.Contains("success") == false)
                                    {
                                        proxy = "";
                                    }

                                    JObject j = JObject.Parse(hr.Content);
                                    foreach (var item in j)
                                    {
                                        foreach (var itemA in item.Value)
                                        {
                                            if (itemA.ToString().Contains("expire_time"))
                                            {
                                                if (DateTime.Now.AddHours(2) < DateTime.Parse(itemA["expire_time"].ToString()))
                                                {
                                                    proxy = itemA["ip"].ToString() + ":" + itemA["port"].ToString();
                                                    break;
                                                }
                                            }
                                        }
                                        if (proxy != "")
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }

                        if (proxy != "" && proxy.Contains(":"))
                        {
                            OpenQA.Selenium.Proxy proxyF = new OpenQA.Selenium.Proxy();
                            proxyF.HttpProxy = proxy;
                            proxyF.FtpProxy  = proxy;
                            proxyF.SslProxy  = proxy;
                            profile.SetProxyPreferences(proxyF);
                            // 使用代理
                            profile.SetPreference("network.proxy.type", 1);
                            //ProxyUser-通行证书 ProxyPass-通行密钥
                            profile.SetPreference("username", "你的账号");
                            profile.SetPreference("password", "你的密码");

                            // 所有协议公用一种代理配置,如果单独配置,这项设置为false
                            profile.SetPreference("network.proxy.share_proxy_settings", true);

                            // 对于localhost的不用代理,这里必须要配置,否则无法和webdriver通讯
                            profile.SetPreference("network.proxy.no_proxies_on", "localhost");
                        }
                    }
                }
                catch (Exception ex)
                {
                }

                //profile.SetPreference("permissions.default.image", 2);
                // 关掉flash
                profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
                FirefoxOptions options = new FirefoxOptions();
                options.Profile = profile;
                theDriver       = new QA.Firefox.FirefoxDriver(driverService, options, TimeSpan.FromMinutes(1));
                ProcessID       = driverService.ProcessId;
            }; break;

            case Browsers.Safari:
            {
                SafariDriverService driverService = SafariDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds        = driverService;
                theDriver = new QA.Safari.SafariDriver(driverService);
                ProcessID = driverService.ProcessId;
            }; break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;
            }
            return(theDriver);
        }