Example #1
0
        private static IWebDriver CreateWebDriver(SeleniumWebDriverType type)
        {
            IWebDriver webDriver;

            switch (type)
            {
            case SeleniumWebDriverType.Edge:
                var edgeOptions = new EdgeOptions();
                edgeOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);

                var edgeDriverService = EdgeDriverService.CreateDefaultService(AppContext.BaseDirectory);
                webDriver = new ThreadLocal <IWebDriver>(() => new EdgeDriver(edgeDriverService, edgeOptions)).Value;
                break;

            case SeleniumWebDriverType.Firefox:
                var firefoxProfile = new FirefoxProfile
                {
                    AcceptUntrustedCertificates = true
                };

                var firefoxOptions = new FirefoxOptions
                {
                    Profile = firefoxProfile
                };

                var firefoxDriverService = FirefoxDriverService.CreateDefaultService(AppContext.BaseDirectory);
                webDriver = new ThreadLocal <IWebDriver>(() => new FirefoxDriver(firefoxDriverService, firefoxOptions, TimeSpan.FromSeconds(60))).Value;
                break;

            case SeleniumWebDriverType.GoogleChrome:
                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArgument("--ignore-certificate-errors");

                var chromeDriverService = ChromeDriverService.CreateDefaultService(AppContext.BaseDirectory);
                webDriver = new ThreadLocal <IWebDriver>(() => new ChromeDriver(chromeDriverService, chromeOptions)).Value;
                break;

            case SeleniumWebDriverType.InternetExplorer:
                var internetExplorerOptions = new InternetExplorerOptions();
                internetExplorerOptions.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);

                var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService(AppContext.BaseDirectory);
                webDriver = new ThreadLocal <IWebDriver>(() => new InternetExplorerDriver(internetExplorerDriverService, internetExplorerOptions)).Value;
                break;

            default:
                throw new NullReferenceException("WebDriver is null.");
            }

            webDriver.Manage().Window.Maximize();

            return(webDriver);
        }
Example #2
0
        public InternetExplorerOptions GetIeOptions()
        {
            var options = new InternetExplorerOptions
            {
                //Proxy = _proxyInstance,
                EnsureCleanSession = true,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                IgnoreZoomLevel = true
            };

            return(options);
        }
Example #3
0
        public static IWebDriver GetIEDriver()
        {
            // TODO: Remove the below two lines once iE settings are done
            var options = new InternetExplorerOptions();

            options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

            //IWebDriver driver = new InternetExplorerDriver(currentDir + @"\SeleniumWebDriver\Driver\", options);
            IWebDriver driver = new InternetExplorerDriver(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), options);

            return(driver);
        }
Example #4
0
        /// <summary>
        /// Get the remote driver options
        /// </summary>
        /// <param name="remoteBrowser">The remote browser type</param>
        /// <param name="remotePlatform">The remote platform</param>
        /// <param name="remoteBrowserVersion">The remote browser version</param>
        /// <param name="remoteCapabilities">Additional remote capabilities</param>
        /// <returns>The remote driver options</returns>
        public static DriverOptions GetRemoteOptions(RemoteBrowserType remoteBrowser, string remotePlatform, string remoteBrowserVersion, Dictionary <string, object> remoteCapabilities)
        {
            DriverOptions options;

            switch (remoteBrowser)
            {
            case RemoteBrowserType.IE:
                options = new InternetExplorerOptions();
                break;

            case RemoteBrowserType.Firefox:
                options = new FirefoxOptions();
                break;

            case RemoteBrowserType.Chrome:
                options = new ChromeOptions();
                break;

            case RemoteBrowserType.Edge:
                options = new EdgeOptions();
                break;

            case RemoteBrowserType.Safari:
                options = new SafariOptions();
                break;

            default:
                throw new ArgumentException($"Remote browser type '{remoteBrowser}' is not supported");
            }

            // Make sure the remote capabilities dictionary exists
            if (remoteCapabilities == null)
            {
                remoteCapabilities = new Dictionary <string, object>();
            }

            // Add a platform setting if one was provided
            if (!string.IsNullOrEmpty(remotePlatform) && !remoteCapabilities.ContainsKey("platform"))
            {
                options.PlatformName = remotePlatform;
            }

            // Add a remote browser setting if one was provided
            if (!string.IsNullOrEmpty(remoteBrowserVersion) && !remoteCapabilities.ContainsKey("version"))
            {
                options.BrowserVersion = remoteBrowserVersion;
            }

            // Add additional capabilities to the driver options
            options.SetDriverOptions(remoteCapabilities);
            options.SetProxySettings();
            return(options);
        }
Example #5
0
        public static IWebDriver LaunchBrowser()
        {
            string _BrowserType = ConfigurationManager.AppSettings["Browser"];
            string _url         = ConfigurationManager.AppSettings["URL"];
            int    wait         = Convert.ToInt32(ConfigurationManager.AppSettings["Wait"]);

            if (_BrowserType == "IE")
            {
                IWebDriver _Idriver;
                InternetExplorerOptions d = new InternetExplorerOptions();
                d.InitialBrowserUrl = _url;
                _Idriver            = new InternetExplorerDriver(d);
                _Idriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(wait);
                _Idriver.Navigate().GoToUrl("javascript:document.getElementById('overridelink').click()");

                _Idriver.Manage().Window.Maximize();
                return(_Idriver);
            }
            else if (_BrowserType == "Firefox")
            {
                IWebDriver _Fdriver = new FirefoxDriver();
                _Fdriver.Navigate().GoToUrl(_url);
                _Fdriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(wait);
                // _Fdriver.Manage().Window.Maximize();

                return(_Fdriver);
            }
            else if (_BrowserType == "Chrome")
            {
                Console.WriteLine("Launching Chrome Browser");
                IWebDriver _Cdriver = new ChromeDriver();
                _Cdriver.Navigate().GoToUrl(_url);
                _Cdriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(wait);
                Console.WriteLine("Loaded URL is: " + _url);
                BaseMethods.IsAlertPresent(_Cdriver, "Accept");
                _Cdriver.Manage().Window.Maximize();
                return(_Cdriver);
            }
            else if ((_BrowserType == "Edge"))
            {
                IWebDriver _MEdriver = new EdgeDriver();
                _MEdriver.Navigate().GoToUrl(_url);
                _MEdriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(wait);
                _MEdriver.Navigate().GoToUrl("javascript:document.getElementById('moreInformationDropdownSpan').click()");
                Thread.Sleep(3000);
                _MEdriver.Navigate().GoToUrl("javascript:document.getElementById('invalidcert_continue').click()");
                return(_MEdriver);
            }
            else
            {
                return(null);
            }
        }
Example #6
0
        public void Initialize()
        {
            InternetExplorerOptions IEcaps = new InternetExplorerOptions();

            IEcaps.IgnoreZoomLevel = true;
            IEcaps.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            IEcaps.RequireWindowFocus = true;
            driver = new InternetExplorerDriver(IEcaps);
            driver.Manage().Window.Maximize();
            //isInitialized = true;
            driver.Navigate().GoToUrl("http://lolatestfe/");
        }
Example #7
0
 public IWebDriver Create()
 {
     if (browserType == Type)
     {
         var profileIE = new InternetExplorerOptions();
         profileIE.EnableNativeEvents = true;
         var browser = new InternetExplorerDriver(profileIE);
         browser.Manage().Cookies.DeleteAllCookies();
         return(browser);
     }
     return(null);
 }
        public static IWebDriver Initalize()
        {
            switch (ValidateGenerateReport)
            {
            case "true":
                scenario = feature.CreateNode <Scenario>(ScenarioContext.Current.ScenarioInfo.Title);
                break;

            case "false":
                break;

            default:
                Assert.Fail("Incorrect condition" + ValidateGenerateReport + ". suggestion(true or false)");
                break;
            }

            //TODO: implement logic that has to run before executing each scenario
            switch (Browser)
            {
            case "Chrome":
                driver = new ChromeDriver(ConfigurationManager.AppSettings["BrowserDriverPath"]);
                break;

            case "Firefox":
                driver = new FirefoxDriver(ConfigurationManager.AppSettings["BrowserDriverPath"]);
                break;

            case "Explorer":
                InternetExplorerOptions options = new InternetExplorerOptions {
                    IgnoreZoomLevel = true
                };
                driver = new InternetExplorerDriver(ConfigurationManager.AppSettings["BrowserDriverPath"], options);
                break;

            case "Edge":
                driver = new EdgeDriver(ConfigurationManager.AppSettings["BrowserDriverPath"]);
                break;

            case "Opera":
                driver = new OperaDriver(ConfigurationManager.AppSettings["BrowserDriverPath"]);
                break;

            case "Safari":
                driver = new SafariDriver(ConfigurationManager.AppSettings["BrowserDriverPath"]);
                break;

            default:
                Assert.Fail("browser " + Browser + " option not found. Suggestions (Chrome, Firefox, Explorer, Edge, Opera, Safari.)");
                break;
            }

            return(driver);
        }
Example #9
0
        private void SetupDriverOptions(BrowserType browser, DriverOptions options, LogLevel logLevel)
        {
            switch (browser)
            {
            case BrowserType.Chrome:
                if (options != null && options is ChromeOptions)
                {
                    _chromeOpts = options as ChromeOptions;
                }
                _chromeOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Edge:
                if (options != null && options is EdgeOptions)
                {
                    _edgeOpts = options as EdgeOptions;
                }
                _edgeOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Firefox:
                if (options != null && options is FirefoxOptions)
                {
                    _firefoxOpts = options as FirefoxOptions;
                }
                _firefoxOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.IE:
                if (options != null && options is InternetExplorerOptions)
                {
                    _ieOpts = options as InternetExplorerOptions;
                }
                _ieOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Phantomjs:
                if (options != null && options is PhantomJSOptions)
                {
                    _phantomJsOpts = options as PhantomJSOptions;
                }
                _phantomJsOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;

            case BrowserType.Safari:
                if (options != null && options is SafariOptions)
                {
                    _safariOpts = options as SafariOptions;
                }
                _safariOpts.SetLoggingPreference(LogType.Browser, logLevel);
                break;
            }
        }
        private static InternetExplorerOptions Options()
        {
            var options = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                EnsureCleanSession       = true,
                EnableFullPageScreenshot = true
            };

            return(options);
        }
Example #11
0
        public static IWebDriver Instance()
        {
            InternetExplorerOptions options = new InternetExplorerOptions();

            if (driver == null)
            {
                options.EnableNativeEvents = false;
                driver = new InternetExplorerDriver(options);
            }

            return(driver);
        }
        private static void CreateDriver(string Driver)
        {
            switch (Driver)
            {
            case "IE":
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                //ieService.HideCommandPromptWindow = true;

                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.SetLoggingPreference(LogType.Driver, LogLevel.Severe);


                //ieOptions.RequireWindowFocus = true;
                //ieOptions.EnablePersistentHover = true;
                //ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

                //ieOptions.AddAdditionalCapability("requireWindowFocus", true);
                //ieOptions.AddAdditionalCapability("enablePersistentHover", false);

                webDriver = new InternetExplorerDriver(ieService, ieOptions, TimeSpan.FromSeconds(300));
                webDriver.Manage().Window.Maximize();
                webDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(20));
                webDriver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(300));
                break;

            case "Firefox":
                var options = new FirefoxOptions();
                FirefoxDriverService ffService = FirefoxDriverService.CreateDefaultService(@"\\s-files\QA_IT\Ascendum_Automation", "geckodriver.exe");
                //ffService.HideCommandPromptWindow = true;


                //FirefoxDriverService service2 = new FirefoxDriverService//new FirefoxDriverService(@"\\s-files\QA_IT\Ascendum_Automation\geckodriver.exe");

                //System.setProperty("webdriver.gecko.driver", "G:\\Selenium\\Firefox driver\\geckodriver.exe");
                webDriver = new FirefoxDriver(ffService);
                webDriver.Manage().Window.Maximize();

                //ITimeouts time;
                //time. = TimeSpan.FromSeconds(30);
                webDriver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(30);
                webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
                break;

            case "Chrome":
                OpenQA.Selenium.Remote.DesiredCapabilities cap = new OpenQA.Selenium.Remote.DesiredCapabilities();
                ChromeOptions op = new ChromeOptions();
                op.LeaveBrowserRunning = true;
                webDriver = new ChromeDriver(op);
                webDriver.Manage().Window.Maximize();
                webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
                break;
            }
        }
Example #13
0
        /// <summary>
        /// <see cref="IDriverBuilder.SetCapabilities"/>.
        /// </summary>
        public IDriverBuilder SetCapabilities(Browsers browser)
        {
            internetExplorerOptions = new InternetExplorerOptions();
            var capabilitySet = Configuration.ConfigurationReader.FrameworkConfig.GetDriverCapabilities(browser);

            foreach (var capability in capabilitySet)
            {
                internetExplorerOptions.AddAdditionalCapability(capability.Name, capability.Value);
            }

            return(this);
        }
Example #14
0
        public void InternetExplorer_Service()
        {
            var ieDriverService = InternetExplorerDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
            var ieOptions       = new InternetExplorerOptions();

            ieDriverService.LoggingLevel = InternetExplorerDriverLogLevel.Trace;
            ieDriverService.LogFile      = $"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}" + log;
            var Driver = new InternetExplorerDriver(ieDriverService, ieOptions);

            Driver.Navigate().GoToUrl(url);
            Driver.Dispose();
        }
        private IWebDriver GetInternetExplorerDriver()
        {
            var internetExplorerOptions = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true
            };

            return(new InternetExplorerDriver(internetExplorerOptions)
            {
                Url = _configurationDriver.SeleniumBaseUrl
            });
        }
Example #16
0
        public void SetupTest()
        {
            var options = new InternetExplorerOptions
            {
                EnsureCleanSession      = true,
                UsePerProcessProxy      = true,
                EnablePersistentHover   = true,
                UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Ignore
            };

            _driver = new InternetExplorerDriver(options);
        }
Example #17
0
        public static IWebDriver Initialize()
        {
            InternetExplorerOptions IEcaps = new InternetExplorerOptions();

            IEcaps.IgnoreZoomLevel = true;
            IEcaps.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            myDriver = new InternetExplorerDriver(IEcaps);
            myDriver.Manage().Window.Maximize();


            return(myDriver);
        }
        private IWebDriver GetInternetExplorerDriver()
        {
            var internetExplorerOptions = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true,
            };

            return(new InternetExplorerDriver(InternetExplorerDriverService.CreateDefaultService(_testRunContext.TestDirectory), internetExplorerOptions)
            {
                Url = _configurationDriver.SeleniumBaseUrl,
            });
        }
Example #19
0
        public InitiateIEDriver()
        {
            //string IE_DRIVER_PATH = @"C:\selenium";
            string IE_DRIVER_PATH = @"C:\Users\jpita\Documents\Visual Studio 2013\Projects\ConsoleApplication2\packages";
            //System.Environment.SetEnvironmentVariable("webdriver.ie.driver", "C:\\selenium\\iedriver\\IEDriverServer.exe");
            var options = new InternetExplorerOptions()
            {
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
            };

            driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);
        }
        private IWebDriver GetInternetExplorerDriver()
        {
            var internetExplorerOptions = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true,
            };

            return(new InternetExplorerDriver(InternetExplorerDriverService.CreateDefaultService(_testRunContext.TestDirectory), internetExplorerOptions)
            {
                Url = _webServerDriver.Hostname,
            });
        }
        private static InternetExplorerOptions GetIEOptions()
        {
            InternetExplorerOptions options = new InternetExplorerOptions();

            options.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            options.IgnoreZoomLevel = true;
            //options.EnsureCleanSession = true;
            options.EnablePersistentHover = false;
            options.EnableNativeEvents    = false;
            //options.AddAdditionalCapability(CapabilityType.AcceptSslCertificates, true);
            return(options);
        }
        /// <summary>
        /// Return a configured InternetExplorerOptions instance.
        /// </summary>
        /// <param name="platformType"></param>
        /// <returns></returns>
        public static InternetExplorerOptions GetInternetExplorerOptions(PlatformType platformType = PlatformType.Any)
        {
            InternetExplorerOptions options = new InternetExplorerOptions
            {
                EnablePersistentHover   = true,
                IgnoreZoomLevel         = true,
                UnhandledPromptBehavior = UnhandledPromptBehavior.Dismiss,
            };

            SetPlatform(options, platformType);
            return(options);
        }
Example #23
0
        public void Test()
        {
            var options = new InternetExplorerOptions()
            {
                InitialBrowserUrl = URL,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true
            };
            var driver = new InternetExplorerDriver(IE_DRIVER_PATH, options);

            driver.Navigate();
            driver.Quit();
        }
Example #24
0
        /// <summary>
        /// Get a new IE driver
        /// </summary>
        /// <param name="commandTimeout">Browser command timeout</param>
        /// <param name="internetExplorerOptions">Browser options</param>
        /// <param name="size">Browser size in the following format: MAXIMIZE, DEFAULT, or #x# (such as 1920x1080)</param>
        /// <returns>A new IE driver</returns>
        public static IWebDriver GetIEDriver(TimeSpan commandTimeout, InternetExplorerOptions internetExplorerOptions, string size = "MAXIMIZE")
        {
            return(CreateDriver(() =>
            {
                LazyInitializer.EnsureInitialized(ref IEDriverPath, () => new DriverManager().SetUpDriver(new InternetExplorerConfig(), SeleniumConfig.GetIEVersion()));

                var driver = new InternetExplorerDriver(Path.GetDirectoryName(IEDriverPath), internetExplorerOptions, commandTimeout);
                SetBrowserSize(driver, size);

                return driver;
            }, SeleniumConfig.GetRetryRefused()));
        }
Example #25
0
        public IWebDriver getWebDriver()
        {
            ChromeOptions           options = new ChromeOptions();
            InternetExplorerOptions caps    = new InternetExplorerOptions();

            caps.IgnoreZoomLevel         = true;
            caps.EnableNativeEvents      = false;
            caps.InitialBrowserUrl       = "http://localhost";
            caps.UnhandledPromptBehavior = UnhandledPromptBehavior.Accept;
            caps.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            caps.EnablePersistentHover = true;

            string browserType = ExcelHelpers.getParameter("Browser");

            switch (browserType)
            {
            case "Chrome":
                options.AddArguments("--disable-notifications");

                if (!string.IsNullOrEmpty(browserType))
                {
                    driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
                }
                else
                {
                    driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
                }

                break;

            case "IE":
                //set capability
                driver = new InternetExplorerDriver(caps);
                break;

            case "Safari":
                driver = new SafariDriver();
                break;

            case "Headless-Chrome":
                //Headless ChromeBrowser
                options.AddArguments("--disable-notifications");
                options.AddArguments("--headless");
                driver = new ChromeDriver(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), options);
                break;

            default:
                Logger.log("No Broswer Found");
                break;
            }

            return(driver);
        }
Example #26
0
        private DriverOptions GetDriverOptions()
        {
            switch (this.BrowserStackSettings.BrowserName.ToLower(CultureInfo.CurrentCulture))
            {
            case "chrome":
                var chromeDriverOptions = new ChromeOptions();
                foreach (var capability in this.AdditionalCapabilities)
                {
                    chromeDriverOptions.AddAdditionalCapability(capability.Key, capability.Value, true);
                }

                return(chromeDriverOptions);

            case "ie":
                var ieDriverOptions = new InternetExplorerOptions();
                foreach (var capability in this.AdditionalCapabilities)
                {
                    ieDriverOptions.AddAdditionalCapability(capability.Key, capability.Value, true);
                }

                return(ieDriverOptions);

            case "edge":
                var edgeDriverOptions = new EdgeOptions();
                foreach (var capability in this.AdditionalCapabilities)
                {
                    edgeDriverOptions.AddAdditionalCapability(capability.Key, capability.Value);
                }

                return(edgeDriverOptions);

            case "firefox":
                var firefoxDriverOptions = new FirefoxOptions();
                foreach (var capability in this.AdditionalCapabilities)
                {
                    firefoxDriverOptions.AddAdditionalCapability(capability.Key, capability.Value, true);
                }

                return(firefoxDriverOptions);

            case "safari":
                var safariDriverOptions = new SafariOptions();
                foreach (var capability in this.AdditionalCapabilities)
                {
                    safariDriverOptions.AddAdditionalCapability(capability.Key, capability.Value);
                }

                return(safariDriverOptions);

            default:
                throw new ArgumentOutOfRangeException("Unable to create the browser specific driver options. An update is required.");
            }
        }
Example #27
0
        private static InternetExplorerOptions GetIEOptions()
        {
            InternetExplorerOptions option = new InternetExplorerOptions();

            // this is going to delete the cookies

            option.EnsureCleanSession = true;
            option.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
            option.ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom;

            return(option);
        }
        public void StartDriver()
        {
            testRunnedWithCurentDriverInstance = 1;
            switch (this.Browser)
            {
            case Browsers.Firefox:
                //FirefoxProfile firefoxProfile = new FirefoxProfile(); // comment out if you do not need firebug while debugging
                //firefoxProfile.AddExtension(Settings.Default.FirebugPath);// comment out if you do not need firebug while debugging
                // Avoid startup screen // comment out if you do not need firebug while debugging
                //firefoxProfile.SetPreference("extensions.firebug.currentVersion", Settings.Default.FirebugVersion); // Avoid startup screen
                //this.Driver = new FirefoxDriver(firefoxProfile); // remove firefox profile if you do not need firebug for debugging
                this.Driver = new FirefoxDriver();
                this.Driver.Manage().Window.Maximize();
                break;

            case Browsers.IE:
                // bear in mind that IE9 has a memory leak, if testing against IE9 set TestsToRunOnSingleWebDriverInstance to 1 to prevent false-negatives due to OutOfMemoryException
                int forcedWait = GeneralSettings.Default.ForcedWait;
                System.Threading.Thread.Sleep(forcedWait);     // gives closing browser frame some time
                InternetExplorerOptions ieOptions = new InternetExplorerOptions();
                ieOptions.EnableNativeEvents = true;
                ieOptions.IgnoreZoomLevel    = true;
                ieOptions.RequireWindowFocus = false;
                ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                TimeSpan ieOperationTimeout = new TimeSpan(days: 0, hours: 0, minutes: 10, seconds: 0);
                this.Driver = new InternetExplorerDriver(Environment.CurrentDirectory, ieOptions, ieOperationTimeout);
                this.Driver.Manage().Window.Maximize();
                break;

            // add android driver requires a virtual android machine to be running that has the selenium web driver installed and running on the virtual device
            //case Browsers.Android:
            //    this.Driver = new AndroidDriver();
            //    break;
            case Browsers.Chrome:
                this.Driver = new ChromeDriver();
                this.Driver.Manage().Window.Maximize();
                break;

            //HTML driver requires some additional steps to start, before adding it to your test fixture make shure to implement your own version of StartHtmlStandaloneServer(); which should start the htmlDriver standalone server on the current machine
            //case Browsers.HtmlDriver:
            //    this.StartHtmlStandaloneServer();
            //    System.Threading.Thread.Sleep(Settings.Default.GlobalForcedWait);
            //    this.Driver = new RemoteWebDriver(DesiredCapabilities.HtmlUnitWithJavaScript());
            //    break;
            default:
                throw new Exception(string.Format("No testfixture setup steps have been implemented for {0} browser", this.Browser));
            }

            int testWaitTime = GeneralSettings.Default.TimeoutThreshold;

            this.Wait = new WebDriverWait(this.Driver, TimeSpan.FromMilliseconds(testWaitTime));
        }
Example #29
0
        /// <summary>
        /// Get the remote desired capability
        /// </summary>
        /// <returns>The remote desired capability</returns>
        private static ICapabilities GetRemoteCapabilities()
        {
            DriverOptions options              = null;
            string        remoteBrowser        = GetRemoteBrowserName();
            string        remotePlatform       = GetRemotePlatform();
            string        remoteBrowserVersion = GetRemoteBrowserVersion();

            switch (remoteBrowser.ToUpper())
            {
            case "INTERNET EXPLORER":
            case "INTERNETEXPLORER":
            case "IE":
                options = new InternetExplorerOptions();
                break;

            case "FIREFOX":
                options = new FirefoxOptions();
                break;

            case "CHROME":
                options = new ChromeOptions();
                break;

            case "EDGE":
                options = new EdgeOptions();
                break;

            case "SAFARI":
                options = new SafariOptions();
                break;

            default:
                throw new ArgumentException(StringProcessor.SafeFormatter("Remote browser type '{0}' is not supported", remoteBrowser));
            }

            // Add a platform setting if one was provided
            if (remotePlatform.Length > 0)
            {
                options.AddAdditionalCapability("platform", remotePlatform);
            }

            // Add a remote browser setting if one was provided
            if (remoteBrowserVersion.Length > 0)
            {
                options.AddAdditionalCapability("version", remoteBrowserVersion);
            }

            // Add RemoteCapabilites section if it exists
            options.SetDriverOptions();

            return(options.ToCapabilities());
        }
Example #30
0
        public IWebDriver CreateDriverInstance(String BrowserName)
        {
            IWebDriver driver = null;

            try
            {
                switch (BrowserName)
                {
                case "ie":
                    InternetExplorerOptions options = new InternetExplorerOptions()
                    {
                        EnsureCleanSession = true,
                        InitialBrowserUrl  = string.Empty,
                        IgnoreZoomLevel    = true,
                        //PageLoadStrategy = InternetExplorerPageLoadStrategy.Eager
                    };
                    //options.ForceCreateProcessApi = true;
                    // options.BrowserCommandLineArguments = "-private";
                    driver = new InternetExplorerDriver("", options, new TimeSpan(0, 5, 0));
                    driver.Manage().Window.Maximize();
                    // driver = new InternetExplorerDriver(ConfigHelper.DriverPath);
                    break;

                case "chrome":
                    // var chromeOptions = new ChromeOptions();
                    //chromeOptions.AddArgument("incognito");
                    driver = new ChromeDriver("C:\\Users\\prmagre\\Downloads\\chromedriver_win32");
                    //driver.Manage().Window.Maximize();
                    //driver = new ChromeDriver(ConfigHelper.DriverPath);
                    break;

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

                case "edge":
                    driver = new EdgeDriver("");
                    break;

                default:
                    driver = new PhantomJSDriver();
                    //driver.Manage().Timeouts().ImplicitWait(new TimeSpan(0, 0, 25));
                    break;
                }
                return(driver);
            }
            catch (Exception e)
            {
                //Utilities.Logger.LogMessage($"Failed to launch the browser, \n Exception: {exception.Message} \n Details: {exception.StackTrace}");
                return(null);
            }
        }