The test settings for the test
 /// <summary>
 /// Gets the web driver for standalone browsers.
 /// </summary>
 /// <param name="testSettings">The test settings.</param>
 /// <param name="browserVersion">The browser version.</param>
 /// <param name="testOutputHelper">The test output helper.</param>
 /// <returns></returns>
 public static ITestWebDriver InitializeStandaloneBrowserDriver(TestSettings testSettings, decimal browserVersion,
     ITestOutputHelper testOutputHelper)
 {
     ScreenShotCounter = 0;
     TestOutputHelper = testOutputHelper;
     testSettings = ValidateSavePaths(testSettings);
     switch (testSettings.DriverType)
     {
         case WebDriverType.ChromeDriver:
         {
             string driverLocation;
             switch (browserVersion.ToString(CultureInfo.InvariantCulture))
             {
                 case "48":
                 case "47":
                 case "46":
                 case "45":
                 case "44":
                 case "43":
                     driverLocation =
                         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                         "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.20\\chromedriver.exe";
                     break;
                 case "42":
                 case "41":
                 case "40":
                 case "39":
                     driverLocation =
                         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                         "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.14\\chromedriver.exe";
                     break;
                 case "38":
                 case "37":
                 case "36":
                     driverLocation =
                         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                         "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.11\\chromedriver.exe";
                     break;
                 case "35":
                 case "34":
                 case "33":
                     driverLocation =
                         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                         "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.10\\chromedriver.exe";
                     break;
                 case "32":
                 case "31":
                 case "30":
                     driverLocation =
                         Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                         "\\MultiBrowser\\Drivers\\ChromeDrivers\\2.8\\chromedriver.exe";
                     break;
                 default:
                     driverLocation = Path.Combine(AssemblyDirectory, "chromedriver.exe");
                     break;
             }
             ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);
             testSettings.BrowserName = "Chrome " + browserVersion;
             var multiBrowserExe =
                 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                 "\\MultiBrowser\\MB_Chrome" + browserVersion + ".exe";
             var driverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation),
                 Path.GetFileName(driverLocation));
             var options = new ChromeOptions
             {
                 LeaveBrowserRunning = false,
                 BinaryLocation = multiBrowserExe
             };
             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);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.FirefoxDriver:
         {
             testSettings.BrowserName = "Firefox " + browserVersion;
             var multiBrowserExe =
                 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                 "\\MultiBrowser\\MB_Chrome" + browserVersion + ".exe";
             var driverService = FirefoxDriverService.CreateDefaultService();
             driverService.FirefoxBinaryPath = multiBrowserExe;
             var options = new FirefoxOptions();
             var driver = new FirefoxDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.InternetExplorerDriver:
         {
             testSettings.BrowserName = "IE " + browserVersion;
             string driverLocation;
             if (!Environment.Is64BitProcess)
             {
                 driverLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                                  "\\MultiBrowser\\Drivers\\IEDrivers\\x86\\IEDriverServer.exe";
             }
             else
             {
                 driverLocation = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                                  "\\MultiBrowser\\Drivers\\IEDrivers\\x64\\IEDriverServer64.exe";
             }
             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().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.EdgeDriver:
         {
             testSettings.BrowserName = "Edge " + browserVersion;
             var driverService = EdgeDriverService.CreateDefaultService(AssemblyDirectory,
                 "MicrosoftWebDriver.exe");
             var options = new EdgeOptions
             {
                 PageLoadStrategy = EdgePageLoadStrategy.Default
             };
             var driver = new EdgeDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.OperaDriver:
         {
             testSettings.BrowserName = "Opera " + browserVersion;
             var multiBrowserExe =
                 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                 "\\MultiBrowser\\MB_Chrome" + browserVersion + ".exe";
             var driverService = OperaDriverService.CreateDefaultService();
             var options = new OperaOptions
             {
                 LeaveBrowserRunning = false,
                 BinaryLocation = multiBrowserExe
             };
             var driver = new OperaDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.SafariDriver:
         {
             testSettings.BrowserName = "Firefox " + browserVersion;
             var multiBrowserExe =
                 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                 "\\MultiBrowser\\MB_Chrome" + browserVersion + ".exe";
             var options = new SafariOptions
             {
                 SafariLocation = multiBrowserExe
             };
             var driver = new SafariDriver(options);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
     }
     return null;
 }
 public TestSearchContext(TestSettings settings, By selfSelector, ISearchContext context,Func<IWebElement> selfLookup)
 {
     _settings = settings;
     _selfSelector = selfSelector;
     _context = context;
     _selfLookup = selfLookup;
 }
 public Example(ITestOutputHelper testOutputHelper)
 {
     _testOutputHelper = testOutputHelper;
     _testSettings = TestSettings.Default;
     _testSettings.TestUri = new Uri("http://test.multibrowser.com/mb_aft_rec_web/");
     _testSettings.LogScreenShots = true;
     _testSettings.LogLevel = LogLevel.Verbose;
     _testSettings.HighlightElements = true;
     _testSettings.TimeoutTimeSpan = new TimeSpan(0, 0, 30);
     _testSettings.DeleteAllCookies = false;
     _testSettings.MaximiseBrowser = true;
     _testSettings.TestDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Tests\\";
 }
 /// <summary>
 /// Validates the save path.
 /// </summary>
 /// <param name="testSettings">The test settings.</param>
 /// <returns></returns>
 private static TestSettings ValidateSavePaths(TestSettings testSettings)
 {
     if (testSettings.LogScreenShots || testSettings.LogLevel != LogLevel.None)
     {
         if (!string.IsNullOrEmpty(testSettings.TestDirectory))
         {
             if (!testSettings.TestDirectory.EndsWith("\\"))
             {
                 testSettings.TestDirectory = testSettings.TestDirectory + "\\";
             }
             try
             {
                 if (!Directory.Exists(testSettings.TestDirectory))
                 {
                     Directory.CreateDirectory(testSettings.TestDirectory);
                 }
                 if (testSettings.LogScreenShots)
                 {
                     if (!Directory.Exists(testSettings.TestDirectory + "ScreenShots"))
                     {
                         Directory.CreateDirectory(testSettings.TestDirectory + "ScreenShots");
                     }
                 }
                 if (testSettings.LogLevel != LogLevel.None)
                 {
                     if (!Directory.Exists(testSettings.TestDirectory + "Logs"))
                     {
                         Directory.CreateDirectory(testSettings.TestDirectory + "Logs");
                     }
                 }
             }
             catch
             {
                 testSettings.TestDirectory = "";
             }
         }
     }
     return(testSettings);
 }
        /// <summary>
        /// Validates the save path.
        /// </summary>
        /// <param name="testSettings">The test settings.</param>
        /// <returns></returns>
        private static TestSettings ValidateSavePaths(TestSettings testSettings)
        {
            if (testSettings.LogScreenShots || testSettings.LogLevel != LogLevel.None)
            {
                if (!string.IsNullOrEmpty(testSettings.TestDirectory))
                {
                    if (!testSettings.TestDirectory.EndsWith("\\"))
                    {
                        testSettings.TestDirectory = testSettings.TestDirectory + "\\";
                    }
                    try
                    {
                        if (!Directory.Exists(testSettings.TestDirectory))
                        {
                            Directory.CreateDirectory(testSettings.TestDirectory);
                        }
                        if (testSettings.LogScreenShots)
                        {
                            if (!Directory.Exists(testSettings.TestDirectory + "ScreenShots"))
                            {
                                Directory.CreateDirectory(testSettings.TestDirectory + "ScreenShots");
                            }
                        }
                        if (testSettings.LogLevel != LogLevel.None)
                        {
                            if (!Directory.Exists(testSettings.TestDirectory + "Logs"))
                            {
                                Directory.CreateDirectory(testSettings.TestDirectory + "Logs");
                            }
                        }
                    }
                    catch
                    {
                        testSettings.TestDirectory = "";
                    }

                }
            }
            return testSettings;
        }
        /// <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;
        }
 /// <summary>
 /// Gets the web driver for locally installed browsers.
 /// </summary>
 /// <param name="testSettings">The test settings.</param>
 /// <param name="testOutputHelper">The test output helper.</param>
 /// <returns></returns>
 /// <exception cref="TestConfigurationException">The details you specified are invalid</exception>
 /// <exception cref="TestConfigurationException">The details you specified are invalid</exception>
 public static ITestWebDriver InitializeInstalledBrowserDriver(TestSettings testSettings,
     ITestOutputHelper testOutputHelper)
 {
     ScreenShotCounter = 0;
     TestOutputHelper = testOutputHelper;
     testSettings = ValidateSavePaths(testSettings);
     switch (testSettings.DriverType)
     {
         case WebDriverType.ChromeDriver:
         {
             string driverLocation = Path.Combine(AssemblyDirectory, "chromedriver.exe");
             driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.ChromeDriver, driverLocation);
             testSettings.BrowserName = "Chrome";
             var driverService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation),
                 Path.GetFileName(driverLocation));
             var options = new ChromeOptions
             {
                 LeaveBrowserRunning = false
             };
             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().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 firingDriver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(firingDriver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.FirefoxDriver:
         {
             testSettings.BrowserName = "Firefox";
             string winePath =
                 Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) +
                 "\\MultiBrowser\\Drivers\\FirefoxDrivers\\wires-0.6.2-win\\";
             var driverService = FirefoxDriverService.CreateDefaultService(winePath);
                 //var driverService = FirefoxDriverService.CreateDefaultService();
                 var options = new FirefoxOptions();
             options.IsMarionette = true;
             var driver = new FirefoxDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.InternetExplorerDriver:
         {
             testSettings.BrowserName = "IE";
             var driverName = "IEDriverServer.exe";
             if (Environment.Is64BitProcess)
             {
                 driverName = "IEDriverServer64.exe";
             }
             string driverLocation = Path.Combine(AssemblyDirectory, 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().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.EdgeDriver:
         {
             string driverLocation = Path.Combine(AssemblyDirectory, "MicrosoftWebDriver.exe");
             driverLocation = ValidateDriverPresentOrUnblocked(WebDriverType.EdgeDriver, driverLocation);
             testSettings.BrowserName = "Edge";
             var driverService = EdgeDriverService.CreateDefaultService(Path.GetDirectoryName(driverLocation),
                 Path.GetFileName(driverLocation));
             var options = new EdgeOptions
             {
                 PageLoadStrategy = EdgePageLoadStrategy.Default
             };
             var driver = new EdgeDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.OperaDriver:
         {
             testSettings.BrowserName = "Opera";
             var driverService = OperaDriverService.CreateDefaultService();
             var options = new OperaOptions
             {
                 LeaveBrowserRunning = false
             };
             var driver = new OperaDriver(driverService, options, testSettings.TimeoutTimeSpan);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
         case WebDriverType.SafariDriver:
         {
             testSettings.BrowserName = "Safari";
             var options = new SafariOptions();
             var driver = new SafariDriver(options);
             if (testSettings.DeleteAllCookies)
             {
                 driver.Manage().Cookies.DeleteAllCookies();
             }
             driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
             if (testSettings.MaximiseBrowser)
             {
                 driver.Manage().Window.Maximize();
             }
             var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
             TestWebDriver = extendedWebDriver;
             return extendedWebDriver;
         }
     }
     throw new TestConfigurationException("The details you specified are invalid");
 }
        /// <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().ImplicitlyWait(testSettings.TimeoutTimeSpan);
            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
            TestWebDriver = extendedWebDriver;
            return extendedWebDriver;
        }
 /// <summary>
 /// Gets the desired browser capability.
 /// </summary>
 /// <param name="username">The username.</param>
 /// <param name="accessKey">The access key.</param>
 /// <param name="browserName">Name of the browser.</param>
 /// <param name="os">The os.</param>
 /// <param name="apiName">Name of the API.</param>
 /// <param name="device">The device.</param>
 /// <param name="version">The version.</param>
 /// <param name="orientation">The device orientation.</param>
 /// <param name="testSettings">The test settings.</param>
 /// <returns></returns>
 /// <exception cref="TestConfigurationException">Unable to set the desired capabilities</exception>
 public static DesiredCapabilities GetDesiredCapability(string username, string accessKey, string browserName, string os, string apiName, string device, string version, DeviceOrientation orientation, TestSettings testSettings)
 {
     DesiredCapabilities caps = null;
     switch (apiName)
     {
         case "iphone":
         case "ipad":
             caps = DesiredCapabilities.IPad();
             caps.SetCapability("browserName", apiName);
             caps.SetCapability("platform", "OS X " + os.Replace("Mac ",""));
             caps.SetCapability("version", version);
             caps.SetCapability("deviceName", device);
             caps.SetCapability("deviceOrientation", orientation == DeviceOrientation.Portrait ? "portrait" : "landscape");
             caps.SetCapability("username", username);
             caps.SetCapability("accessKey", accessKey);
             caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
             caps.SetCapability("javascriptEnabled", true);
             caps.SetCapability("acceptSslCerts", true);
             caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
             return caps;
         case "chrome":
         case "firefox":
         case "internet explorer":
         case "microsoftedge":
         case "opera":
         case "safari":
             switch (apiName)
             {
                 case "chrome":
                     caps = DesiredCapabilities.Chrome();
                     break;
                 case "firefox":
                     caps = DesiredCapabilities.Firefox();
                     break;
                 case "internet explorer":
                     caps = DesiredCapabilities.InternetExplorer();
                     break;
                 case "microsoftedge":
                     caps = DesiredCapabilities.Edge();
                     break;
                 case "opera":
                     caps = DesiredCapabilities.Opera();
                     break;
                 case "safari":
                     caps = DesiredCapabilities.Safari();
                     break;
                 default:
                     caps = DesiredCapabilities.HtmlUnit();
                     break;
             }
             caps.SetCapability("browserName", device);
             caps.SetCapability("platform", os);
             caps.SetCapability("version", version);
             caps.SetCapability("username", username);
             caps.SetCapability("accessKey", accessKey);
             caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
             caps.SetCapability("javascriptEnabled", true);
             caps.SetCapability("acceptSslCerts", true);
             caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
             return caps;
         case "android":
             caps = DesiredCapabilities.Android();
             if (device == "Android")
             {
                 caps.SetCapability("browserName", device);
                 caps.SetCapability("platform", os);
                 caps.SetCapability("version", version);
                 caps.SetCapability("deviceName", "Android Emulator");
             }
             else
             {
                 caps.SetCapability("browserName", "Android");
                 caps.SetCapability("deviceName", device);
             }
             caps.SetCapability("deviceOrientation", orientation == DeviceOrientation.Portrait ? "portrait" : "landscape");
             caps.SetCapability("username", username);
             caps.SetCapability("accessKey", accessKey);
             caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
             caps.SetCapability("javascriptEnabled", true);
             caps.SetCapability("acceptSslCerts", true);
             caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
             return caps;
     }
     return null;
 }
        /// <summary>
        /// Gets the full screen shot.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="testSettings">The test settings.</param>
        /// <returns></returns>
        public static Bitmap GetFullScreenShot(ITestWebDriver driver, TestSettings testSettings)
        {
            Bitmap stitchedImage = null;

            try
            {
                var totalwidth1  = (long)(driver.ExecuteScript("return document.body.offsetWidth"));
                var totalHeight1 = (long)(driver.ExecuteScript("return  document.body.parentNode.scrollHeight"));
                var totalWidth   = (int)totalwidth1;
                var totalHeight  = (int)totalHeight1;
                // Get the Size of the Viewport
                var viewportWidth1  = (long)(driver.ExecuteScript("return document.body.clientWidth"));
                var viewportHeight1 = (long)(driver.ExecuteScript("return window.innerHeight"));
                var viewportWidth   = (int)viewportWidth1;
                var viewportHeight  = (int)viewportHeight1;
                // Split the Screen in multiple Rectangles
                var rectangles = new List <Rectangle>();
                // Loop until the Total Height is reached
                for (int i = 0; i < totalHeight; i += viewportHeight)
                {
                    int newHeight = viewportHeight;
                    // Fix if the Height of the Element is too big
                    if (i + viewportHeight > totalHeight)
                    {
                        newHeight = totalHeight - i;
                    }
                    // Loop until the Total Width is reached
                    for (int ii = 0; ii < totalWidth; ii += viewportWidth)
                    {
                        int newWidth = viewportWidth;
                        // Fix if the Width of the Element is too big
                        if (ii + viewportWidth > totalWidth)
                        {
                            newWidth = totalWidth - ii;
                        }

                        // Create and add the Rectangle
                        var currRect = new Rectangle(ii, i, newWidth, newHeight);
                        rectangles.Add(currRect);
                    }
                }
                // Build the Image
                stitchedImage = new Bitmap(totalWidth, totalHeight);
                // Get all Screenshots and stitch them together
                Rectangle previous = Rectangle.Empty;
                //int numb = 0;

                foreach (Rectangle rectangle in rectangles)
                {
                    if (testSettings.DriverType == WebDriverType.ChromeDriver)
                    {
                        // Calculate the Scrolling (if needed)
                        if (previous != Rectangle.Empty)
                        {
                            int xDiff = rectangle.Right - previous.Right;
                            int yDiff = rectangle.Bottom - previous.Bottom;
                            // Scroll
                            driver.ExecuteScript($"window.scrollBy({xDiff}, {yDiff})");

                            Thread.Sleep(1000);
                        }
                    }
                    // Take Screenshot
                    Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();
                    //numb++;
                    //screenshot.SaveAsFile(@"\\psf\Home\Documents\Hack\" + numb + ".png",ImageFormat.Png);
                    //
                    //screenshot.SaveAsFile("C:\\Backup\\" + numb + ".png",ImageFormat.Png);
                    //numb ++;
                    // Build an Image out of the Screenshot
                    Image screenshotImage;
                    using (var memStream = new MemoryStream(screenshot.AsByteArray))
                    {
                        screenshotImage = Image.FromStream(memStream);
                    }
                    // Calculate the Source Rectangle
                    var sourceRectangle = new Rectangle(viewportWidth - rectangle.Width, viewportHeight - rectangle.Height, rectangle.Width, rectangle.Height);
                    // Copy the Image
                    using (Graphics g = Graphics.FromImage(stitchedImage))
                    {
                        g.DrawImage(screenshotImage, rectangle, sourceRectangle, GraphicsUnit.Pixel);
                    }
                    // Set the Previous Rectangle
                    previous = rectangle;
                }
            }
            catch
            {
                // handle
            }
            if (testSettings.DriverType == WebDriverType.ChromeDriver)
            {
                driver.ExecuteScript("window.scrollBy(0, 0)");
            }
            return(stitchedImage);
        }
        /// <summary>
        /// Gets the full screen shot.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="testSettings">The test settings.</param>
        /// <returns></returns>
        public static Bitmap GetFullScreenShot(ITestWebDriver driver, TestSettings testSettings)
        {
            Bitmap stitchedImage = null;
            try
            {
                var totalwidth1 = (long) (driver.ExecuteScript("return document.body.offsetWidth"));
                var totalHeight1 = (long) (driver.ExecuteScript("return  document.body.parentNode.scrollHeight"));
                var totalWidth = (int) totalwidth1;
                var totalHeight = (int) totalHeight1;
                // Get the Size of the Viewport
                var viewportWidth1 = (long) (driver.ExecuteScript("return document.body.clientWidth"));
                var viewportHeight1 = (long) (driver.ExecuteScript("return window.innerHeight"));
                var viewportWidth = (int) viewportWidth1;
                var viewportHeight = (int) viewportHeight1;
                // Split the Screen in multiple Rectangles
                var rectangles = new List<Rectangle>();
                // Loop until the Total Height is reached
                for (int i = 0; i < totalHeight; i += viewportHeight)
                {
                    int newHeight = viewportHeight;
                    // Fix if the Height of the Element is too big
                    if (i + viewportHeight > totalHeight)
                    {
                        newHeight = totalHeight - i;
                    }
                    // Loop until the Total Width is reached
                    for (int ii = 0; ii < totalWidth; ii += viewportWidth)
                    {
                        int newWidth = viewportWidth;
                        // Fix if the Width of the Element is too big
                        if (ii + viewportWidth > totalWidth)
                        {
                            newWidth = totalWidth - ii;
                        }

                        // Create and add the Rectangle
                        var currRect = new Rectangle(ii, i, newWidth, newHeight);
                        rectangles.Add(currRect);
                    }
                }
                // Build the Image
                stitchedImage = new Bitmap(totalWidth, totalHeight);
                // Get all Screenshots and stitch them together
                Rectangle previous = Rectangle.Empty;
                //int numb = 0;
                
                foreach (Rectangle rectangle in rectangles)
                {
                    if (testSettings.DriverType == WebDriverType.ChromeDriver)
                    {
                        // Calculate the Scrolling (if needed)
                        if (previous != Rectangle.Empty)
                        {
                            int xDiff = rectangle.Right - previous.Right;
                            int yDiff = rectangle.Bottom - previous.Bottom;
                            // Scroll
                            driver.ExecuteScript($"window.scrollBy({xDiff}, {yDiff})");

                            Thread.Sleep(1000);
                        }
                    }
                    else if (testSettings.DriverType == WebDriverType.SafariDriver)
                    {
                        // Calculate the Scrolling (if needed)
                        if (previous != Rectangle.Empty)
                        {
                            driver.ExecuteScript($"document.body.style.top = \"-{previous.Bottom}px\"");

                            Thread.Sleep(1000);
                        }
                    }
                    // Take Screenshot
                    Screenshot screenshot = ((ITakesScreenshot)driver).GetScreenshot();
                    //numb++;
                    //screenshot.SaveAsFile(@"\\psf\Home\Documents\Hack\" + numb + ".png",ImageFormat.Png);
                    //
                    //screenshot.SaveAsFile("C:\\Backup\\" + numb + ".png",ImageFormat.Png);
                    //numb ++;
                    // Build an Image out of the Screenshot
                    Image screenshotImage;
                    using (var memStream = new MemoryStream(screenshot.AsByteArray))
                    {
                        screenshotImage = Image.FromStream(memStream);
                    }
                    // Calculate the Source Rectangle
                    var sourceRectangle = new Rectangle(viewportWidth - rectangle.Width, viewportHeight - rectangle.Height, rectangle.Width, rectangle.Height);
                    // Copy the Image
                    using (Graphics g = Graphics.FromImage(stitchedImage))
                    {
                        g.DrawImage(screenshotImage, rectangle, sourceRectangle, GraphicsUnit.Pixel);
                    }
                    // Set the Previous Rectangle
                    previous = rectangle;
                }
            }
            catch
            {
                // handle
            }
            if (testSettings.DriverType == WebDriverType.ChromeDriver)
            {
                driver.ExecuteScript("window.scrollBy(0, 0)");
            }
            if (testSettings.DriverType == WebDriverType.SafariDriver)
            {
                driver.ExecuteScript("document.body.style.top = \"0px\"");
            }
            return stitchedImage;
        }
        /// <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";
            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 + "\\";
                }
            }
            var options = new ChromeOptions
            {
                LeaveBrowserRunning = false,
                BinaryLocation =
                    Path.Combine(installPathValue ?? @"C:\Program Files (x86)\MultiBrowser", "MultiBrowser Emulator.exe")
            };
#if DEBUG
                options.BinaryLocation = @"C:\Projects\MobileEmulator\bin\Debug\x64\MultiBrowser Emulator.exe";
#endif
            var driver = new ChromeDriver(driverService, options, testSettings.TimeoutTimeSpan);
            if (testSettings.DeleteAllCookies)
            {
                driver.Manage().Cookies.DeleteAllCookies();
            }
            driver.Manage().Timeouts().ImplicitlyWait(testSettings.TimeoutTimeSpan);
            var extendedWebDriver = new TestWebDriver(driver, testSettings, TestOutputHelper);
            TestWebDriver = extendedWebDriver;
            return extendedWebDriver;
        }
Example #13
0
        /// <summary>
        /// Gets the desired browser capability.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="accessKey">The access key.</param>
        /// <param name="browserName">Name of the browser.</param>
        /// <param name="os">The os.</param>
        /// <param name="apiName">Name of the API.</param>
        /// <param name="device">The device.</param>
        /// <param name="version">The version.</param>
        /// <param name="orientation">The device orientation.</param>
        /// <param name="testSettings">The test settings.</param>
        /// <returns></returns>
        /// <exception cref="TestConfigurationException">Unable to set the desired capabilities</exception>
        public static DesiredCapabilities GetDesiredCapability(string username, string accessKey, string browserName, string os, string apiName, string device, string version, DeviceOrientation orientation, TestSettings testSettings)
        {
            DesiredCapabilities caps = null;

            switch (apiName)
            {
            case "iphone":
            case "ipad":
                caps = DesiredCapabilities.IPad();
                caps.SetCapability("browserName", apiName);
                caps.SetCapability("platform", "OS X " + os.Replace("Mac ", ""));
                caps.SetCapability("version", version);
                caps.SetCapability("deviceName", device);
                caps.SetCapability("deviceOrientation", orientation == DeviceOrientation.Portrait ? "portrait" : "landscape");
                caps.SetCapability("username", username);
                caps.SetCapability("accessKey", accessKey);
                caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
                caps.SetCapability("javascriptEnabled", true);
                caps.SetCapability("acceptSslCerts", true);
                caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
                return(caps);

            case "chrome":
            case "firefox":
            case "internet explorer":
            case "microsoftedge":
                switch (apiName)
                {
                case "chrome":
                    caps = (DesiredCapabilities) new ChromeOptions().ToCapabilities();
                    break;

                case "firefox":
                    caps = (DesiredCapabilities) new FirefoxOptions().ToCapabilities();
                    break;

                case "internet explorer":
                    caps = (DesiredCapabilities) new InternetExplorerOptions().ToCapabilities();
                    break;

                case "microsoftedge":
                    caps = (DesiredCapabilities) new EdgeOptions().ToCapabilities();
                    break;

                default:
                    caps = DesiredCapabilities.HtmlUnit();
                    break;
                }
                caps.SetCapability("browserName", device);
                caps.SetCapability("platform", os);
                caps.SetCapability("version", version);
                caps.SetCapability("username", username);
                caps.SetCapability("accessKey", accessKey);
                caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
                caps.SetCapability("javascriptEnabled", true);
                caps.SetCapability("acceptSslCerts", true);
                caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
                return(caps);

            case "android":
                caps = DesiredCapabilities.Android();
                if (device == "Android")
                {
                    caps.SetCapability("browserName", device);
                    caps.SetCapability("platform", os);
                    caps.SetCapability("version", version);
                    caps.SetCapability("deviceName", "Android Emulator");
                }
                else
                {
                    caps.SetCapability("browserName", "Android");
                    caps.SetCapability("deviceName", device);
                }
                caps.SetCapability("deviceOrientation", orientation == DeviceOrientation.Portrait ? "portrait" : "landscape");
                caps.SetCapability("username", username);
                caps.SetCapability("accessKey", accessKey);
                caps.SetCapability("name", browserName + " - " + DateTime.Now.ToString("F"));
                caps.SetCapability("javascriptEnabled", true);
                caps.SetCapability("acceptSslCerts", true);
                caps.SetCapability("takesScreenshot", testSettings.LogScreenShots);
                return(caps);
            }
            return(null);
        }
        /// <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);
        }
        /// <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);
        }