Ejemplo n.º 1
0
        public static IDriverManager CreateDriverManager()
        {
            var browser    = SettingManager.GetAppSetting(SettingName.BROWSER);
            var driverPath = SettingManager.GetAppSetting(SettingName.DRIVERPATH);

            if (string.IsNullOrEmpty(browser))
            {
                throw new Exception(string.Format("Can not get config '{0}'", SettingName.BROWSER));
            }

            IWebDriver driver;

            switch (browser.ToLower())
            {
            case "*iexplore":
            case "*ie":
                driver = new InternetExplorerDriver(driverPath);
                break;

            case "*firefox":
                var service = FirefoxDriverService.CreateDefaultService(driverPath);
                service.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                driver = new FirefoxDriver(service);
                break;

            case "*chrome":
                driver = new ChromeDriver(driverPath);
                break;

            //case "*remote":
            //    break;
            default:
                throw new Exception("Create driver failed!");
            }

            var manager = new WebDriverManager(driver);

            manager.BuildDefaultSetting();
            return(manager);
        }