Пример #1
0
        internal static IWebDriver LaunchBrowser(Type browser)
        {
            switch (browser)
            {
            case Type.CHROME:
                Driver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;

            case Type.FIREFOX:
                Driver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                break;

            case Type.IE:
                Driver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                break;

            case Type.SAFARI:
                Driver = new OpenQA.Selenium.Safari.SafariDriver();
                break;

            default:
                throw new ApplicationException("No appropriate browser driver was provided.");
            }
            return(Driver);
        }
        /// <summary>
        /// construct an ActionManager
        /// </summary>
        /// <param name="parent">the Automation object</param>
        public SeleniumActionManager(IAutomation parent, Browser browser)
            : base(parent)
        {
            switch (browser)
            {
                case Browser.Chrome:
                    {
                        OpenQA.Selenium.Chrome.ChromeDriverService service = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                        service.HideCommandPromptWindow = true;
                        WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(service, new OpenQA.Selenium.Chrome.ChromeOptions());
                        break;
                    }
                case Browser.FireFox:
                    WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                    break;
                case Browser.Safari:
                    WebDriver = new OpenQA.Selenium.Safari.SafariDriver();
                    break;
                default:
                    WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                    break;
            };
            WebDriver.Manage().Timeouts().ImplicitlyWait(WaitTime);

            RegisterAction(new ActionClick(WebDriver));
            RegisterAction(new ActionOpenURL(WebDriver));
            RegisterAction(new ActionRefresh(WebDriver));
            RegisterAction(new ActionGoBack(WebDriver));
            RegisterAction(new ActionEnter(WebDriver));

            RegisterAction(new ActionCheckControlProperty(WebDriver));
            RegisterAction(new ActionSet(WebDriver));
        }
        /// <summary>
        /// construct a Selenium Action Manager with an Automation Engine
        /// </summary>
        /// <param name="automation">the Automation Engine</param>
        public SeleniumActionManager(abt.Automation automation, Browser browser)
            : base(automation)
        {
            switch (browser)
            {
                case Browser.Chrome:
                    {
                        OpenQA.Selenium.Chrome.ChromeDriverService service = OpenQA.Selenium.Chrome.ChromeDriverService.CreateDefaultService();
                        service.HideCommandPromptWindow = true;
                        WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(service, new OpenQA.Selenium.Chrome.ChromeOptions());
                        break;
                    }
                case Browser.FireFox:
                    WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver();
                    break;
                case Browser.Safari:
                    WebDriver = new OpenQA.Selenium.Safari.SafariDriver();
                    break;
                default:
                    WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver();
                    break;
            };
            WebDriver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));

            RegisterAction(new ActionClick(WebDriver));
            RegisterAction(new ActionOpenURL(WebDriver));
            RegisterAction(new ActionRefresh(WebDriver));
            RegisterAction(new ActionGoBack(WebDriver));
        }
Пример #4
0
        private IWebDriver CreateDriver()
        {
            IWebDriver webDriver;

            switch (_driverConfiguration.TargetDriver)
            {
            case DriverNames.IE:
                webDriver = new InternetExplorerDriver(new InternetExplorerOptions()
                {
                    IgnoreZoomLevel = true,
                    IntroduceInstabilityByIgnoringProtectedModeSettings = true
                });
                break;

            case DriverNames.Firefox:
                var firefoxProfile = new FirefoxProfile();
                firefoxProfile.AddExtension(@"JSErrorCollector.xpi");
                if (!String.IsNullOrEmpty(DriverConfiguration.GetConfiguration().DownloadDir))
                {
                    firefoxProfile.SetPreference("browser.download.dir", DriverConfiguration.GetConfiguration().DownloadDir);
                    firefoxProfile.SetPreference("browser.helperApps.alwaysAsk.force", false);
                    firefoxProfile.SetPreference("browser.download.folderList", 2);
                    firefoxProfile.SetPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
                    firefoxProfile.SetPreference("browser.download.useDownloadDir", true);
                    firefoxProfile.SetPreference("browser.helperApps.neverAsk.saveToDisk", "image/png, application/vnd.ms-excel");
                }
                webDriver = new FirefoxDriver(firefoxProfile);
                break;

            case DriverNames.Chrome:
                webDriver = new OpenQA.Selenium.Chrome.ChromeDriver();
                break;

            case DriverNames.PhantomJS:
                var options = new PhantomJSOptions();
                options.AddAdditionalCapability("user-agent", PhantomUserAgent);
                webDriver = new PhantomJSDriver(options);
                break;

            case DriverNames.Safari:
                webDriver = new OpenQA.Selenium.Safari.SafariDriver();
                break;

            default:
                throw new NotImplementedException();
            }

            return(webDriver);
        }
Пример #5
0
        private QA.IWebDriver InitWebDriver()
        {
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;

            case Browsers.Chrome:
            {
                theDriver = new QA.Chrome.ChromeDriver();
            }; break;

            case Browsers.Firefox:
            {
                theDriver = new QA.Firefox.FirefoxDriver();
            }; break;

            case Browsers.Safari:
            {
                theDriver = new QA.Safari.SafariDriver();
            }; break;

            case Browsers.PhantomJS:
            {
                theDriver = new QA.PhantomJS.PhantomJSDriver();
            }; break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            }; break;
            }
            return(theDriver);
        }
Пример #6
0
 /// <summary>Starts a new Selenium testing session</summary>
 /// <param name="browser">Name of the browser : firefox, ie, chrome, phantomjs</param>
 /// <param name="baseUrl">The base URL</param>
 /// <param name="useLastSession">Optional - Try to use the previous session if the browser is still openned (Excel only)</param>
 /// <example>
 /// <code lang="vbs">	
 ///     WebDriver driver = New WebDriver()
 ///     driver.start "firefox", "http://www.google.com"
 ///     driver.open "/"
 /// </code>
 /// </example>
 public void start(string browser, String baseUrl = null, bool useLastSession = false) {
     if (useLastSession && CopyStaticDriver(baseUrl)) return;
     _isStartedRemotely = false;
     var dir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
     DesiredCapabilities capa = new DesiredCapabilities(_capabilities);
     switch (browser.ToLower().Replace("*", "")) {
         case "firefox": case "ff":
             WebDriver = new OpenQA.Selenium.Firefox.FirefoxDriver(getFirefoxOptions());
             break;
         case "cr": case "chrome":
             ChromeDriverService crService = ChromeDriverService.CreateDefaultService(dir);
             crService.EnableVerboseLogging = false;
             crService.SuppressInitialDiagnosticInformation = true;
             crService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             WebDriver = new OpenQA.Selenium.Chrome.ChromeDriver(crService, getChromeOptions());
             break;
         case "phantomjs": case "pjs":
             var pjsService = PhantomJSDriverService.CreateDefaultService(dir);
             pjsService.SuppressInitialDiagnosticInformation = true;
             pjsService.IgnoreSslErrors = true;
             pjsService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             if(base._proxy != null)
                 pjsService.Proxy = base._proxy.HttpProxy;
             if(base._arguments != null)
                 pjsService.AddArguments(base._arguments);
             WebDriver = new OpenQA.Selenium.PhantomJS.PhantomJSDriver(pjsService, getPhantomJSOptions());
             break;
         case "internetexplorer": case "iexplore": case "ie":
         case "internetexplorer64": case "iexplore64": case "ie64":
             var ieService = OpenQA.Selenium.IE.InternetExplorerDriverService.CreateDefaultService(dir);
             ieService.SuppressInitialDiagnosticInformation = true;
             ieService.LoggingLevel = OpenQA.Selenium.IE.InternetExplorerDriverLogLevel.Error;
             ieService.HideCommandPromptWindow = this._hideCommandPromptWindow;
             WebDriver = new OpenQA.Selenium.IE.InternetExplorerDriver(ieService, getInternetExplorerOptions());
             break;
         case "safari": case "sa":
             WebDriver = new OpenQA.Selenium.Safari.SafariDriver(getSafariOptions());
             break;
         default:
             throw new ApplicationException("Browser <" + browser + "> is not available !  \nAvailable are Firefox, IE, Chrome, Safari and PhantomJS");
     }
     this.setTimeout(_timeout);
     if (!string.IsNullOrEmpty(baseUrl))
         _baseUrl = baseUrl.TrimEnd('/');
     _timerhotkey.Start();
 }