private static ITestWebDriver CreateEdgeDriver(TestSettings testSettings, int browserVersion)
        {
            string driverLocation = GetMultiBrowserDriverBasePath();

            driverLocation = Path.Combine(driverLocation, "EdgeDrivers", browserVersion.ToString(), "MicrosoftWebDriver.exe");
            driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.EdgeDriver, driverLocation);

            testSettings.BrowserName = "Edge " + browserVersion;
            var driverService = EdgeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation), Path.GetFileName(driverLocation));

            var options = new EdgeOptions();
            var driver  = new EdgeDriver(driverService, options, testSettings.TimeoutTimeSpan);

            if (testSettings.DeleteAllCookies)
            {
                driver.Manage().Cookies.DeleteAllCookies();
            }

            driver.Manage().Timeouts().ImplicitWait = testSettings.TimeoutTimeSpan;

            if (testSettings.MaximiseBrowser)
            {
                driver.Manage().Window.Maximize();
            }

            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);

            TestWebDriver = extendedWebDriver;
            return(extendedWebDriver);
        }
        /// <summary>
        /// Gets the sauce labs web driver.
        /// </summary>
        /// <param name="browserName">The full browser name.</param>
        /// <param name="os">The operating system.</param>
        /// <param name="apiName">The api name.</param>
        /// <param name="device">The device name.</param>
        /// <param name="version">The version name.</param>
        /// <param name="testSettings">The test settings.</param>
        /// <param name="deviceOrientation">The device orientation.</param>
        /// <param name="testOutputHelper">The test output helper.</param>
        /// <returns></returns>
        /// <exception cref="TestConfigurationException">Selenium settings not set.</exception>
        public static ITestWebDriver InitializeSauceLabsDriver(string browserName, string os, string apiName,
                                                               string device, string version, TestSettings testSettings, DeviceOrientation deviceOrientation,
                                                               ITestOutputHelper testOutputHelper)
        {
            ScreenShotCounter        = 0;
            TestOutputHelper         = testOutputHelper;
            testSettings.BrowserName = browserName;
            if (testSettings.SeleniumHubSettings == null)
            {
                throw new TestConfigurationException("SauceLabs settings not set.");
            }
            if (testSettings.SeleniumHubSettings.HubUsername == null)
            {
                throw new TestConfigurationException("SauceLabs username settings not set.");
            }
            if (testSettings.SeleniumHubSettings.HubPassword == null)
            {
                throw new TestConfigurationException("SauceLabs access token settings not set.");
            }
            var capabilities = SauceLabs.GetDesiredCapability(testSettings.SeleniumHubSettings.HubUsername,
                                                              testSettings.SeleniumHubSettings.HubPassword, browserName, os, apiName, device, version,
                                                              deviceOrientation, testSettings);

            testSettings = ValidateSavePaths(testSettings);

            var driver = new TestRemoteWebDriver(new Uri(testSettings.SeleniumHubSettings.HubUrl), capabilities,
                                                 testSettings.TimeoutTimeSpan);
            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);

            TestWebDriver = extendedWebDriver;
            return(extendedWebDriver);
        }
        private static ITestWebDriver CreateChromeDriver(TestSettings testSettings, int browserVersion, bool isStandalone)
        {
            string driverLocation = GetMultiBrowserDriverBasePath();

            driverLocation = Path.Combine(driverLocation, "ChromeDrivers", browserVersion.ToString());

            driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);

            testSettings.BrowserName = "Chrome " + browserVersion;

            var driverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation), Path.GetFileName(driverLocation));

            var options = new ChromeOptions
            {
                LeaveBrowserRunning = false
            };

            if (isStandalone)
            {
                options.BinaryLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\MultiBrowser\\MB_Chrome" + browserVersion + ".exe";
            }

            options.AddArgument("--no-default-browser-check");
            options.AddArgument("--test-type=browser");
            options.AddArgument("--start-maximized");
            options.AddArgument("--allow-no-sandbox-job");
            options.AddArgument("--disable-component-update");
            options.AddArgument("--auth-server-whitelist=" + testSettings.TestUri.Authority.Replace("www", "*"));

            var driver = new ChromeDriver(driverService, options, testSettings.TimeoutTimeSpan);

            var firingDriver = AttachDriverEvents(driver);

            if (testSettings.DeleteAllCookies)
            {
                firingDriver.Manage().Cookies.DeleteAllCookies();
            }

            driver.Manage().Timeouts().ImplicitWait = testSettings.TimeoutTimeSpan;

            if (testSettings.MaximiseBrowser)
            {
                firingDriver.Manage().Window.Maximize();
            }

            var extendedWebDriver = new TestWebDriver(firingDriver, testSettings, TestOutputHelper);

            TestWebDriver = extendedWebDriver;

            return(extendedWebDriver);
        }
        private static ITestWebDriver CreateIEDriver(TestSettings testSettings, int browserVersion)
        {
            testSettings.BrowserName = "IE " + browserVersion;

            string driverBasePath = GetMultiBrowserDriverBasePath();

            var driverName = "IEDrivers\\x86\\IEDriverServer.exe";

            if (Environment.Is64BitProcess)
            {
                driverName = "IEDrivers\\x64\\IEDriverServer64.exe";
            }

            string driverLocation = Path.Combine(driverBasePath, driverName);

            driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.InternetExplorerDriver, driverLocation);
            var driverService = InternetExplorerDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation), Path.GetFileName(driverLocation));
            var options       = new InternetExplorerOptions
            {
                IgnoreZoomLevel = true,
                IntroduceInstabilityByIgnoringProtectedModeSettings = true,
                BrowserAttachTimeout  = testSettings.TimeoutTimeSpan,
                RequireWindowFocus    = true,
                ElementScrollBehavior = InternetExplorerElementScrollBehavior.Bottom,
                InitialBrowserUrl     = testSettings.TestUri.AbsoluteUri,
                EnsureCleanSession    = true,
                EnableNativeEvents    = true
            };

            var driver = new InternetExplorerDriver(driverService, options, testSettings.TimeoutTimeSpan);

            if (testSettings.DeleteAllCookies)
            {
                driver.Manage().Cookies.DeleteAllCookies();
            }

            driver.Manage().Timeouts().ImplicitWait = testSettings.TimeoutTimeSpan;

            if (testSettings.MaximiseBrowser)
            {
                driver.Manage().Window.Maximize();
            }

            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);

            TestWebDriver = extendedWebDriver;
            return(extendedWebDriver);
        }
        private static ITestWebDriver CreateFirefoxDriver(TestSettings testSettings, int browserVersion, bool isStandalone)
        {
            testSettings.BrowserName = "Firefox " + browserVersion;

            string driverLocation = GetMultiBrowserDriverBasePath();

            driverLocation = Path.Combine(driverLocation, "FirefoxDrivers", browserVersion.ToString());

            var driverService = FirefoxDriverService.CreateDefaultService(driverLocation);

            var options = new FirefoxOptions();

            if (isStandalone)
            {
                options.BrowserExecutableLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\\MultiBrowser\\MB_Firefox" + browserVersion + ".exe";
            }

            options.UseLegacyImplementation = false;

            var driver = new FirefoxDriver(driverService, options, testSettings.TimeoutTimeSpan);

            if (testSettings.DeleteAllCookies)
            {
                driver.Manage().Cookies.DeleteAllCookies();
            }

            if (browserVersion > 50)
            {
                driver.Manage().Timeouts().ImplicitWait = testSettings.TimeoutTimeSpan;
            }

            if (testSettings.MaximiseBrowser)
            {
                driver.Manage().Window.Maximize();
            }

            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);

            TestWebDriver = extendedWebDriver;

            return(extendedWebDriver);
        }
        /// <summary>
        /// Gets the multi browser emulator web driver.
        /// </summary>
        /// <param name="testSettings">The test settings.</param>
        /// <param name="emulator">The emulator.</param>
        /// <param name="orientation">The device orientation.</param>
        /// <param name="testOutputHelper">The test output helper.</param>
        /// <returns></returns>
        public static ITestWebDriver InitializeMultiBrowserEmulatorDriver(TestSettings testSettings, Emulator emulator, DeviceOrientation orientation, ITestOutputHelper testOutputHelper)
        {
            ScreenShotCounter        = 0;
            TestOutputHelper         = testOutputHelper;
            testSettings.BrowserName = emulator + " " + orientation;
            testSettings             = ValidateSavePaths(testSettings);
            //string driverLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
            //                        "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.20\\chromedriver.exe";
            string driverLocation = Path.Combine(AssemblyDirectory, "chromedriver.exe");

            driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);

            var driverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation),
                                                                         Path.GetFileName(driverLocation));

            ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);

            var currentInstallPath = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\MultiBrowser", false) ??
                                     Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432node\MultiBrowser",
                                                                      false);
            string installPathValue = null;

            if (currentInstallPath != null)
            {
                installPathValue = (string)currentInstallPath.GetValue("Path");
            }
            if (installPathValue != null)
            {
                if (!installPathValue.EndsWith("\\"))
                {
                    installPathValue = installPathValue + "\\";
                }
            }

#if DEBUG
            installPathValue = @"C:\Projects\MobileEmulator\bin\Debug\x64\";
#endif
            var options = new ChromeOptions
            {
                LeaveBrowserRunning = false,
                BinaryLocation      =
                    Path.Combine(installPathValue ?? @"C:\Program Files (x86)\MultiBrowser", "MultiBrowser Emulator.exe")
            };

            var emulatorSettings = MultiBrowser.GetMultiBrowserEmulators(emulator);
            if (orientation == DeviceOrientation.Portrait)
            {
                var mobileEmulationSettings = new ChromeMobileEmulationDeviceSettings
                {
                    UserAgent         = emulatorSettings.DeviceUserAgent,
                    Width             = emulatorSettings.DeviceWidth,
                    Height            = emulatorSettings.DeviceHeight,
                    EnableTouchEvents = true,
                    PixelRatio        = emulatorSettings.DevicePixelRatio
                };
                options.EnableMobileEmulation(mobileEmulationSettings);
                //options.AddAdditionalCapability("mobileEmulation", new
                //{
                //    deviceMetrics = new
                //    {
                //        width = emulatorSettings.DeviceWidth,
                //        height = emulatorSettings.DeviceHeight,
                //        pixelRatio = emulatorSettings.DevicePixelRatio
                //    },
                //    userAgent = emulatorSettings.DeviceUserAgent
                //});
            }
            else
            {
                var mobileEmulationSettings = new ChromeMobileEmulationDeviceSettings
                {
                    UserAgent         = emulatorSettings.DeviceUserAgent,
                    Width             = emulatorSettings.DeviceHeight,
                    Height            = emulatorSettings.DeviceWidth,
                    EnableTouchEvents = true,
                    PixelRatio        = emulatorSettings.DevicePixelRatio
                };
                options.EnableMobileEmulation(mobileEmulationSettings);


                //options.AddAdditionalCapability("mobileEmulation", new
                //{
                //    deviceMetrics = new
                //    {
                //        width = emulatorSettings.DeviceHeight,
                //        height = emulatorSettings.DeviceWidth,
                //        pixelRatio = emulatorSettings.DevicePixelRatio
                //    },
                //    userAgent = emulatorSettings.DeviceUserAgent
                //});
            }
#if DEBUG
            options.BinaryLocation = @"C:\Projects\MobileEmulator\bin\Debug\x64\MultiBrowser Emulator.exe";
#endif
            string authServerWhitelist = "auth-server-whitelist=" + testSettings.TestUri.Authority.Replace("www", "*");
            string startUrl            = "startUrl=" + testSettings.TestUri.AbsoluteUri;
            string selectedEmulator    = "emulator=" + emulatorSettings.EmulatorArgument;

            var argsToPass = new[]
            {
                "test-type", "start-maximized", "no-default-browser-check", "allow-no-sandbox-job",
                "disable-component-update", "disable-translate", "disable-hang-monitor", authServerWhitelist, startUrl,
                selectedEmulator
            };
            options.AddArguments(argsToPass);
            var driver = new ChromeDriver(driverService, options, testSettings.TimeoutTimeSpan);
            if (testSettings.DeleteAllCookies)
            {
                driver.Manage().Cookies.DeleteAllCookies();
            }
            driver.Manage().Timeouts().ImplicitWait = testSettings.TimeoutTimeSpan;
            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
            TestWebDriver = extendedWebDriver;
            return(extendedWebDriver);
        }