Example #1
0
 /// <summary>
 /// The set up internet explorer web driver.
 /// </summary>
 public static void SetUpInternetExplorerWebDriver()
 {
     WebDriver = new InternetExplorerDriver(InternetExplorerDriverService.CreateDefaultService(WebDriverPath), new InternetExplorerOptions(), TimeSpan.FromSeconds(10));
     WebDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
     WebDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(5));
     WebDriver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(5));
 }
        /// <summary>
        /// Gets the capabilities for IE
        /// </summary>
        /// <param name="acceptSlefSignedSSL"></param>
        /// <param name="_ignoreZoomLevel"></param>
        /// <param name="_enableNativeEvents"></param>
        /// <param name="_ensureCleanSession"></param>
        /// <param name="browserTimeoutMilloseconds"></param>
        /// <param name="_scrollBehaviour"></param>
        /// <param name="_promtBehaviour"></param>
        /// <param name="_loadStrategy"></param>
        /// <returns></returns>
        private InternetExplorerOptions GetIEBrowserOptions(
            bool acceptSlefSignedSSL       = false,
            bool _ignoreZoomLevel          = true,
            bool _enableNativeEvents       = false,
            bool _ensureCleanSession       = false,
            int browserTimeoutMilloseconds = 300000,
            InternetExplorerElementScrollBehavior _scrollBehaviour = InternetExplorerElementScrollBehavior.Default,
            UnhandledPromptBehavior _promtBehaviour = UnhandledPromptBehavior.Default,
            PageLoadStrategy _loadStrategy          = PageLoadStrategy.Eager)
        {
            IEService = InternetExplorerDriverService.CreateDefaultService(Directory.GetCurrentDirectory(), @"IEDriverServer.exe");
            IEService.LoggingLevel            = InternetExplorerDriverLogLevel.Trace;
            IEService.HideCommandPromptWindow = false;
            IEService.Start();

            return(new InternetExplorerOptions()
            {
                ElementScrollBehavior = _scrollBehaviour,
                EnableNativeEvents = _enableNativeEvents,
                IgnoreZoomLevel = _ignoreZoomLevel,
                ForceCreateProcessApi = false,
                ForceShellWindowsApi = true,
                EnablePersistentHover = true,
                FileUploadDialogTimeout = new TimeSpan(0, 0, 0, browserTimeoutMilloseconds),
                RequireWindowFocus = true,
                UnhandledPromptBehavior = _promtBehaviour,
                BrowserAttachTimeout = new TimeSpan(0, 0, 0, browserTimeoutMilloseconds),
                EnsureCleanSession = _ensureCleanSession,
                PageLoadStrategy = _loadStrategy,
                AcceptInsecureCertificates = acceptSlefSignedSSL
            });
        }
Example #3
0
        public static IWebDriver CreateWindow(BrowserType browserType = BrowserType.Chrome, bool isAutoLogin = false)
        {
            IWebDriver driver = null;

            switch (browserType)
            {
            case BrowserType.Chrome:
            {
                var driverService = ChromeDriverService.CreateDefaultService(DriverPathOfChrome);

                var chromeOptions = new ChromeOptions();
                driverService.Port = 8777;
                driver             = new ChromeDriver(driverService, chromeOptions, TimeSpan.FromMinutes(5));
            }
            break;

            case BrowserType.IE:
            {
                var driverService = InternetExplorerDriverService.CreateDefaultService(DriverPathOfIE_32Bit);

                //DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
                //capabilities.set(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,
                //true);
                //WebDriver driver = new InternetExplorerDriver(capabilities);

                var ieOptions = new InternetExplorerOptions();
                ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                driver = new InternetExplorerDriver(driverService, ieOptions);
            }
            break;
            }


            return(driver);
        }
Example #4
0
        /*public void executandoThread() {
         *
         *  ThreadStart ts = new ThreadStart(InicializaValores);
         *  CrossThreadTestRunner runner = new CrossThreadTestRunner(ts);
         *  runner.Run();
         * } */

        /* public TestBase_Vendas() {
         *   driver = ObtemDriver();
         * }*/

        protected virtual IWebDriver ObtemDriver(TipoDriver tipoDriver)
        {
            switch (tipoDriver)
            {
            case TipoDriver.Chrome: {
                var chromeDriverService = ChromeDriverService.CreateDefaultService();
                chromeDriverService.HideCommandPromptWindow = true;
                ChromeOptions chromeOptions = new ChromeOptions();
                //chromeOptions.AddArguments("headless");
                chromeOptions.AddArguments("--incognito");
                chromeOptions.AddArgument("--window-size=1300,1000");
                driver = new ChromeDriver(chromeDriverService, chromeOptions, TimeSpan.FromSeconds(60));
                break;
            }

            case TipoDriver.Firefox: {
                driver = new FirefoxDriver();
                break;
            }

            case TipoDriver.InternetExplorer: {
                var IEservice = InternetExplorerDriverService.CreateDefaultService();
                IEservice.HideCommandPromptWindow = true;
                IEservice.SuppressInitialDiagnosticInformation = true;
                InternetExplorerOptions IEoptions = new InternetExplorerOptions();
                IEoptions.EnsureCleanSession          = true;
                IEoptions.BrowserCommandLineArguments = "-private";
                driver = new InternetExplorerDriver(IEoptions);
                break;
            }
            }

            return(driver);
        }
Example #5
0
        public override IWebDriver CreateLocalDriver()
        {
            InternetExplorerDriverService service;

            if (IEDriverServer != null)
            {
                service = InternetExplorerDriverService.CreateDefaultService(IEDriverServer);
            }
            else
            {
                string path = Environment.GetEnvironmentVariable("webdriver.ie.driver", EnvironmentVariableTarget.Machine);
                if (path != null)
                {
                    service = InternetExplorerDriverService.CreateDefaultService(path);
                }
                else
                {
                    service = InternetExplorerDriverService.CreateDefaultService();
                }
            }

            var driver = new InternetExplorerDriver(service, GetOptions(), TimeSpan.FromSeconds(Timeouts.HttpCommandTimeout));

            ProcessID = service.ProcessId;

            return(driver);
        }
Example #6
0
        private void selectBrowser(string browser)
        {
            switch (browser)
            {
            case "Chrome":
            {
                driver = new ChromeDriver(chromeDriverService, cOptions);
            } break;

            case "FireFox":
            {
                var driverService = FirefoxDriverService.CreateDefaultService();
                driverService.HideCommandPromptWindow = true;
                driver = new FirefoxDriver(driverService);
            } break;

            case "IE":
            {
                var driverService = InternetExplorerDriverService.CreateDefaultService();
                driverService.HideCommandPromptWindow = true;
                driver = new InternetExplorerDriver(driverService);
            } break;

            case "랜덤":
            {
                string[] browsers = { "Chrome", "FireFox", "IE" };
                selectBrowser(browsers[CommonUtils.GetRandomValue(0, browsers.Length - 1)]);
            }
            break;
            }
        }
Example #7
0
        public static RemoteWebDriver getRemoteDriver(Browser b)
        {
            switch (b)
            {
            case Browser.ie:
                return(new InternetExplorerDriver(
                           InternetExplorerDriverService.CreateDefaultService(),
                           new InternetExplorerOptions(),
                           TimeSpan.FromMinutes(10)
                           ));

            case Browser.firefox:

                return(new FirefoxDriver(
                           new FirefoxBinary(),
                           new FirefoxProfile(),
                           TimeSpan.FromMinutes(10)
                           ));

            case Browser.chrome:

                return(new ChromeDriver(
                           ChromeDriverService.CreateDefaultService(),
                           new ChromeOptions(),
                           TimeSpan.FromMinutes(10)
                           ));
            }

            return(null);
        }
Example #8
0
        /// <summary>
        /// Creates the web driver from the specified browser factory configuration.
        /// </summary>
        /// <returns>The configured web driver.</returns>
        protected override IWebDriver CreateLocalDriver()
        {
            bool ignoreProtectedModeSettings = false;

            if (this.Settings.ContainsKey(IgnoreProtectedModeSettings))
            {
                string ignoreProtectedModeSettingsValue = this.Settings[IgnoreProtectedModeSettings];
                if (!string.IsNullOrWhiteSpace(ignoreProtectedModeSettingsValue))
                {
                    if (!bool.TryParse(ignoreProtectedModeSettingsValue, out ignoreProtectedModeSettings))
                    {
                        throw new ConfigurationErrorsException(
                                  $"The {IgnoreProtectedModeSettings} setting is not a valid boolean: {ignoreProtectedModeSettingsValue}");
                    }
                }
            }

            var explorerOptions = new InternetExplorerOptions
            {
                EnsureCleanSession = this.EnsureCleanSession,
                IntroduceInstabilityByIgnoringProtectedModeSettings = ignoreProtectedModeSettings
            };

            var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();

            internetExplorerDriverService.HideCommandPromptWindow = true;
            return(new InternetExplorerDriver(internetExplorerDriverService, explorerOptions));
        }
        private void SetWebDriverToIE()
        {
            var driverExePath = _driverPaths + "ie" + Path.DirectorySeparatorChar + _ieDriverServer;

            _driverservice = InternetExplorerDriverService.CreateDefaultService(driverExePath);
            var settings = new InternetExplorerOptions
            {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                EnsureCleanSession = true
            };

            try
            {
                _driverservice.Start();
            }
            catch (Exception err)
            {
                throw new DriverServiceNotFoundException(err.Message);
            }

            _capabilities = DesiredCapabilities.InternetExplorer();
            SetAdditionalCapabilities();

            WebDriver = new ScreenShotRemoteWebDriver(_driverservice.ServiceUrl, _capabilities);
        }
Example #10
0
        public IWebDriver CreateDriver(Type driverType)
        {
            List <Type> constructorArgTypeList = new List <Type>();
            IWebDriver  driver = null;

            if (typeof(ChromeDriver).IsAssignableFrom(driverType))
            {
                ChromeDriverService service = ChromeDriverService.CreateDefaultService(this.driverPath);
                constructorArgTypeList.Add(typeof(ChromeDriverService));
                ConstructorInfo ctorInfo = driverType.GetConstructor(constructorArgTypeList.ToArray());
                return((IWebDriver)ctorInfo.Invoke(new object[] { service }));
            }

            if (typeof(InternetExplorerDriver).IsAssignableFrom(driverType))
            {
                InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService(this.driverPath);
                constructorArgTypeList.Add(typeof(InternetExplorerDriverService));
                ConstructorInfo ctorInfo = driverType.GetConstructor(constructorArgTypeList.ToArray());
                return((IWebDriver)ctorInfo.Invoke(new object[] { service }));
            }

            if (typeof(FirefoxDriver).IsAssignableFrom(driverType))
            {
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService(this.driverPath);
                constructorArgTypeList.Add(typeof(FirefoxDriverService));
                ConstructorInfo ctorInfo = driverType.GetConstructor(constructorArgTypeList.ToArray());
                return((IWebDriver)ctorInfo.Invoke(new object[] { service }));
            }

            driver = (IWebDriver)Activator.CreateInstance(driverType);
            return(driver);
        }
Example #11
0
        private void _btnLoadInternetExplorer_Click(object sender, RoutedEventArgs e)
        {
            var service = InternetExplorerDriverService.CreateDefaultService();
            var driver  = new InternetExplorerDriver(service);

            Replace(ref _Driver, driver, service, _SeleniumHost);
        }
        public static IWebDriver GetWebDriver(WebDriverType driverType)
        {
            IWebDriver d;

            if (driverType == WebDriverType.PhantomJS)
            {
                d = new PhantomJSDriver();
            }
            else if (driverType == WebDriverType.Chrome)
            {
                ChromeDriverService svc = ChromeDriverService.CreateDefaultService(  );

                ChromeOptions opt = new ChromeOptions();
                //{
                //	BinaryLocation = ...
                //};

                d = new ChromeDriver(svc, opt, TimeSpan.FromSeconds(10));
            }
            else if (driverType == WebDriverType.Firefox)
            {
                FirefoxDriverService svc = FirefoxDriverService.CreateDefaultService(  );

                FirefoxOptions opt = new FirefoxOptions()
                {
                    BrowserExecutableLocation = Properties.Settings.Default.PathFirefox,
                    //@"C:\Program Files\Mozilla Firefox\firefox.exe"
                };
                d = new FirefoxDriver(svc, opt, TimeSpan.FromSeconds(10));
            }
            else if (driverType == WebDriverType.IE)
            {
                //DesiredCapabilities capabilities = DesiredCapabilities.InternetExplorer();
                //capabilities.SetCapability( CapabilityType.BrowserName, "IE" );
                //capabilities.SetCapability( CapabilityType.Version, "11" );

                //capabilities.SetCapability( InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true );
                //capabilities.SetCapability( InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true );
                //System.setProperty( "webdriver.ie.driver", "C://MavenTest//driver//IEDriverServer.exe" );
                //driver = new InternetExplorerDriver();

                InternetExplorerOptions opt = new InternetExplorerOptions()
                {
                    RequireWindowFocus = false
                };

                InternetExplorerDriverService svc = InternetExplorerDriverService.CreateDefaultService(  );

                d = new InternetExplorerDriver(svc, opt, TimeSpan.FromSeconds(10));
            }
            else
            {
                throw new ArgumentException("Unknown driver requested");
            }


            WebDriverFactory.driver = d;

            return(d);
        }
        public static IWebDriver IniciarWebsite(string url, EDRIVERS navegador)
        {
            string     pathIe     = @DRIVER_IE;
            string     pathChrome = @DRIVER_CHROME;
            IWebDriver driver     = null;

            switch (navegador)
            {
            case EDRIVERS.IE:
                var options           = new InternetExplorerOptions();
                var driverServiceieIE = InternetExplorerDriverService.CreateDefaultService(pathIe);
                //driverServiceieIE.HideCommandPromptWindow = true;
                options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                options.EnablePersistentHover = false;
                driver = new InternetExplorerDriver(driverServiceieIE, options);
                break;

            case EDRIVERS.CHROME:
                var driverService = ChromeDriverService.CreateDefaultService(pathChrome);
                //driverService.HideCommandPromptWindow = true;
                ChromeOptions optionsChrome = new ChromeOptions();
                optionsChrome.AddArgument("--log-level=3");
                optionsChrome.AddArgument("--start-maximized");
                driver = new ChromeDriver(driverService, optionsChrome);
                break;

            default:
                Console.WriteLine("Não encontrado");
                break;
            }
            driver.Navigate().GoToUrl(url);
            return(driver);
        }
Example #14
0
        /// <summary>
        /// The initialize web driver internet explorer.
        /// </summary>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        private bool InitializeWebDriverInternetExplorer()
        {
            var retVal        = true;
            var driverOptions = GetInternetExplorerOptions();

            try
            {
                var driverService = InternetExplorerDriverService.CreateDefaultService(Configuration.DriverServerPath);

                driverService.LogFile      = DriverLogFile;
                driverService.LoggingLevel = GetDriverLoggingLevel();

                WebDriver = new InternetExplorerDriver(
                    driverService,
                    driverOptions,
                    TimeSpan.FromSeconds(Configuration.BrowserTimeout));
                WebDriver.Manage().Window.Maximize();
                ResetImplicitlyWait();
            }
            catch (Exception ex)
            {
                StfLogger.LogInternal($"Couldn't Initialize WebAdapter - got error [{ex.Message}]");
                retVal = false;
            }

            StfLogger.LogDebug("Done initializing {0}. Successful: {1}", GetType().Name, retVal.ToString());

            return(retVal);
        }
Example #15
0
        public ConcreteDriver(string driverName)
        {
            if (driverName == "chrome")
            {
                driver = new ChromeDriver();
            }
            else if (driverName == "ie")
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService();

                driverService.LibraryExtractionPath = Environment.CurrentDirectory;

                InternetExplorerOptions options = new InternetExplorerOptions();
                options.EnableNativeEvents = true;
                options.IgnoreZoomLevel    = true;
                options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                options.EnsureCleanSession = true;

                // The followng field is a workaround for a known Selenium bug;
                //      IE11 Driver cannot perform any actions while the download bar is visible
                options.PageLoadStrategy = PageLoadStrategy.Eager;

                driver = new InternetExplorerDriver(driverService, options, TimeSpan.FromSeconds(60));
            }
            else
            {
                throw new NotImplementedException(driverName + " not implemented");
            }
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            driver.Manage().Window.Maximize();
        }
Example #16
0
        /// <summary>
        /// Method to get Internet Explorer drivers
        /// </summary>
        /// <returns></returns>
        public static IWebDriver GetInternetExplorerDriver()
        {
            KillProcessByName("IExplore");
            KillProcessByName("IEDriverServer");

            var options = new InternetExplorerOptions
            {
                RequireWindowFocus = false,
                EnableNativeEvents = false,
                IgnoreZoomLevel    = true,
                //UnhandledPromptBehavior.Accept;
                //InternetExplorerUnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Accept,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true
            };

            options.AddAdditionalCapability("disable-popup-blocking", true);
            TimeSpan timeout = new TimeSpan(1200000000);

            var driverService = InternetExplorerDriverService.CreateDefaultService(Config.SolutionPath + @"\packages\Selenium.WebDriver.IEDriver.3.11.1\driver\");

            driverService.HideCommandPromptWindow = true;

            Utils.driver = new InternetExplorerDriver(driverService, options, timeout);

            return(Utils.driver);
        }
Example #17
0
        /// <summary>
        /// Method to get Internet Explorer drivers
        /// </summary>
        /// <returns></returns>
        public static InternetExplorerDriver GetInternetExplorerDriver()
        {
            KillProcessByName("IExplore");
            KillProcessByName("IEDriverServer");

            var options = new InternetExplorerOptions
            {
                RequireWindowFocus      = false,
                EnableNativeEvents      = false,
                IgnoreZoomLevel         = true,
                UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Accept,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true
            };

            options.AddAdditionalCapability("disable-popup-blocking", true);
            TimeSpan timeout = new TimeSpan(1200000000);

            var driverService = InternetExplorerDriverService.CreateDefaultService(@Config.BrowserDrivers);

            driverService.HideCommandPromptWindow = true;

            HelperLibrary.driver = new InternetExplorerDriver(driverService, options, timeout);

            return(HelperLibrary.driver);
        }
        public static IWebDriver GetDriver(BrowserType browserType)
        {
            IWebDriver driver;

            switch (browserType)

            {
            case BrowserType.Chrome:
            {
                var options = new ChromeOptions();
                var service = ChromeDriverService.CreateDefaultService();
                driver = new ChromeDriver(service, options);
                break;
            }

            case BrowserType.IE:
            {
                var options = new InternetExplorerOptions();
                var service = InternetExplorerDriverService.CreateDefaultService();
                driver = new InternetExplorerDriver(service, options);
                break;
            }

            default:
            {
                throw new ArgumentException("Your browser is not supported");        // excpб если какой-то другой браузер будет
            }
            }

            return(driver);
        }
Example #19
0
        //Start WebDriver
        public static IWebDriver opendriver(Browser browser)
        {
            Console.WriteLine("Opening seleniumdriver");
            driver = null;
            switch (browser)
            {
            case Browser.Firefox:
                FirefoxDriverService service = FirefoxDriverService.CreateDefaultService();
                service.FirefoxBinaryPath = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                FirefoxDriver webDriver = new FirefoxDriver(service);
                break;

            case Browser.Chrome:
                driver = new ChromeDriver();
                driver.Manage().Window.Maximize();
                break;

            case Browser.IE:
                InternetExplorerDriverService ieservice = InternetExplorerDriverService.CreateDefaultService();
                ieservice.SuppressInitialDiagnosticInformation = true;
                var options = new InternetExplorerOptions();
                options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                driver = new InternetExplorerDriver(ieservice, options);
                driver.Manage().Window.Maximize();
                break;
            }
            if (driver != null)
            {
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(200);
            }
            return(driver);
        }
Example #20
0
        // Schreibt die Aufrufe von Trace nach Console.Out und somit in das Resharper Output-Window!
        //private static TraceListener _listener;

        public static void InitTests(TestContext testContext)
        {
            if (App != null)
            {
                return;
            }

            Trace.Listeners.Add(new ConsoleTraceListener());

            testContext.WriteLine($"Test initialized '{testContext.TestName}'.");
            testContext.WriteLine("Instantiation of WebDriver ... ");

            WebsiteBaseUrl = ConfigurationManager.AppSettings["WebsiteBaseUrl"];
            _browserType   = ConfigurationManager.AppSettings["BrowserType"];
            var timeOutStr = ConfigurationManager.AppSettings["DefaultTimeOutInSeconds"] ?? "4";
            var timeOut    = int.Parse(timeOutStr);

            try
            {
                switch (_browserType.ToLower())
                {
                case "ie":
                    var service = InternetExplorerDriverService.CreateDefaultService();
                    service.SuppressInitialDiagnosticInformation = true;
                    Driver = new InternetExplorerDriver(service);
                    break;

                case "firefox":
                    Driver = new FirefoxDriver();
                    break;

                case "chrome":
                    Driver = new ChromeDriver();
                    break;
                }
            }
            catch (Exception ex)
            {
                Trace.WriteLine("Instantiation of WebDriver failed: " + ex.Message);
                throw;
            }

            var reportPath = testContext.TestDir.Replace(" ", "_") + "_Report";

            if (!Directory.Exists(reportPath))
            {
                Directory.CreateDirectory(reportPath);
            }

            ReportFile = Path.Combine(reportPath, $"{_browserType.ToLower()}-report.html");
            var extent = new ExtentReports(ReportFile, CultureInfo.GetCultureInfo("de"), ReplaceExisting: true, Order: DisplayOrder.NewestFirst);

            ReportLogger = new ReportLogger(reportPath, extent, Driver);
            App          = new App(Driver, WebsiteBaseUrl, ReportLogger, timeOut);

            Driver.Manage().Window.Size = new System.Drawing.Size(1600, 1000);

            App.Open("/");
        }
Example #21
0
        private static IWebDriver GetIeDriver()
        {
            var service = InternetExplorerDriverService.CreateDefaultService(Configuration.IeBinPath);
            var driver  = new InternetExplorerDriver(service);

            driver.Manage().Window.Maximize();
            return(driver);
        }
        public static IWebDriver GetInternetExplorerBrowser()
        {
            var service = InternetExplorerDriverService.CreateDefaultService(DriverFolder);

            service.HideCommandPromptWindow = true;

            return(new InternetExplorerDriver(service, InternetExplorerOptions));
        }
        /// <summary>
        /// Starts a new instance of the web driver, installing or updating it as necessary.
        /// </summary>
        /// <param name="hideCommandWindow">Whether to hide the Selenium command window.</param>
        public override IWebDriver Start(bool hideCommandWindow = true)
        {
            var path          = Install();
            var driverService = InternetExplorerDriverService.CreateDefaultService(path);

            driverService.HideCommandPromptWindow = hideCommandWindow;
            return(new InternetExplorerDriver(driverService));
        }
Example #24
0
        private static IWebDriver InternetExplorer(NavigatorSessionParameters session)
        {
            var service = InternetExplorerDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = session.HideCommandPromptWindow;

            return(new InternetExplorerDriver(service, new InternetExplorerOptions()));
        }
Example #25
0
        public static IWebDriver Create()
        {
            IWebDriver driver = null;

            switch (GetBrowser())
            {
            case Browser.Chrome:
                driver = new ChromeDriver(DriverPath, DefaultChromeOptions());
                break;

            case Browser.Firefox:
                var ffds = FirefoxDriverService.CreateDefaultService(DriverPath, "geckodriver.exe");
                driver = new FirefoxDriver(ffds);
                MaximizeWindow(driver);
                break;

            case Browser.Edge:
                var edgeDriverService = EdgeDriverService.CreateDefaultService(DriverPath, "MicrosoftWebDriver.exe");
                driver = new EdgeDriver(edgeDriverService);
                MaximizeWindow(driver);
                break;

            case Browser.Ie11:
                var ie11DriverService = InternetExplorerDriverService.CreateDefaultService(DriverPath,
                                                                                           "IEDriverServer.exe");
                driver = new InternetExplorerDriver(ie11DriverService, DefaultIe11Options());
                MaximizeWindow(driver);
                break;

            case Browser.RemoteChrome:
                driver = RemoteWebDriver(DefaultChromeOptions().ToCapabilities());
                break;

            case Browser.RemoteFirefox:
                driver = RemoteWebDriver(new FirefoxOptions().ToCapabilities());
                MaximizeWindow(driver);
                break;

            case Browser.RemoteEdge:
                var edgeCapabilities = new EdgeOptions();
                driver = RemoteWebDriver(edgeCapabilities.ToCapabilities());
                MaximizeWindow(driver);
                break;

            case Browser.RemoteIe11:
                driver = RemoteWebDriver(DefaultIe11Options().ToCapabilities());
                MaximizeWindow(driver);
                break;

            default:
                Assert.Inconclusive($"Browser: {GetBrowser()} is not supported");
                break;
            }

            driver.SetDefaultImplicitWait();

            return(driver);
        }
Example #26
0
        public void SetUp()
        {
            var VendorDirectory = System.IO.Directory.GetParent(System.AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.FullName + @"\Vendor";
            var Service         = InternetExplorerDriverService.CreateDefaultService(VendorDirectory);

            _driver = new InternetExplorerDriver(Service);
            _login  = new LoginPage(_driver);
            _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
        }
        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);
        }
        public IWebDriver Create(string logPath)
        {
            var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();

            internetExplorerDriverService.LogFile      = $"\"{logPath}\"";;
            internetExplorerDriverService.LoggingLevel = InternetExplorerDriverLogLevel.Debug;

            return(new InternetExplorerDriver(internetExplorerDriverService, new InternetExplorerOptions()));
        }
Example #29
0
        private void SetIEDriver()
        {
            KillProc("IEServerDriver");
            var service = InternetExplorerDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;
            service.SuppressInitialDiagnosticInformation = true;
            driver = new InternetExplorerDriver(service);
        }
Example #30
0
        /// <summary>
        /// Returns an instance of IE based driver.
        /// </summary>
        /// <returns>IE based driver.</returns>
        private static IWebDriver IeWebDriver()
        {
            // get machine processor architecture
            String getProcessorArchitecture = Registry.GetValue(
                "HKEY_LOCAL_MACHINE\\System\\CurrentControlSet\\Control\\Session Manager\\Environment"
                , "PROCESSOR_ARCHITECTURE", null).ToString();
            // get installed browser's version in machine
            Dictionary <string, string> browserList = GetBrowserDetails();
            // get Ie driver path based on Ie version installed in
            String getIeDriverPath;

            if (getProcessorArchitecture.Contains("64") && (browserList.ContainsKey("IE") && browserList["IE"].Contains("10.") ||
                                                            (browserList.ContainsKey("IE") && browserList["IE"].Contains("11."))))
            {
                // get Ie driver path
                getIeDriverPath =
                    (Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
                     + "\\..\\..\\..\\..\\ExternalAssemblies\\x86").Replace("file:\\", "");
            }
            else
            {
                // Ie driver path
                getIeDriverPath =
                    (Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase)
                     + "\\..\\..\\..\\..\\ExternalAssemblies\\" + ((getProcessorArchitecture == "x86") ? "x86" : "x64"))
                    .Replace("file:\\", "");
            }
            // start internet explorer driver service
            InternetExplorerDriverService ieservice = InternetExplorerDriverService.CreateDefaultService(getIeDriverPath);

            ieservice.LoggingLevel = InternetExplorerDriverLogLevel.Info;
            // get path for save log execution file
            String getExecutingPath = new FileInfo(Assembly.GetExecutingAssembly().Location).DirectoryName;

            if (getExecutingPath != null)
            {
                ieservice.LogFile = Path.Combine(getExecutingPath, "Log", "IEDriver" + DateTime.Now.Ticks + ".log");
            }
            // set internet explorer options
            var options = new InternetExplorerOptions
            {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore,
                IgnoreZoomLevel         = true,
                EnableNativeEvents      = true,
                BrowserAttachTimeout    = TimeSpan.FromMinutes(20),
                EnablePersistentHover   = false
            };
            // create internet explorer driver object
            IWebDriver webDriver = new InternetExplorerDriver(ieservice, options, TimeSpan.FromMinutes(20));

            // set webDriver page load duration
            webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromMinutes(20));
            // set cursor position center of the screen
            Cursor.Position = new Point(Screen.PrimaryScreen.Bounds.Width / 2, Screen.PrimaryScreen.Bounds.Height / 2);
            return(webDriver);
        }