/// <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;
 }
        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);
        }
Exemplo n.º 5
0
        public void RunInstalledBrowserTests(WebDriverType driverType)
        {
            _testSettings.TestType = TestType.InstalledBrowser;
            _testSettings.DriverType = driverType;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Installed Browsers\\";
            _driver = WebDriverManager.InitializeInstalledBrowserDriver(_testSettings, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
Exemplo n.º 6
0
        public void RunStandaloneBrowserTests(WebDriverType driverType, decimal version)
        {
            _testSettings.TestType = TestType.StandaloneBrowser;
            _testSettings.DriverType = driverType;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Standalone Browsers\\";
            _driver = WebDriverManager.InitializeStandaloneBrowserDriver(_testSettings, version, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
Exemplo n.º 7
0
        public void RunInstalledBrowserTests(WebDriverType driverType)
        {
            _testSettings.TestType      = TestType.InstalledBrowser;
            _testSettings.DriverType    = driverType;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Installed Browsers\\";
            _driver = WebDriverManager.InitializeInstalledBrowserDriver(_testSettings, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
Exemplo n.º 8
0
        public void RunMultiBrowserEmulatorTests(Emulator emulator, DeviceOrientation orientation)
        {
            _testSettings.TestType      = TestType.EmulatorBrowser;
            _testSettings.DriverType    = WebDriverType.EmulatorBrowser;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Emulator Browsers\\";
            _driver = WebDriverManager.InitializeMultiBrowserEmulatorDriver(_testSettings, emulator, orientation, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
Exemplo n.º 9
0
        public void RunStandaloneBrowserTests(WebDriverType driverType, decimal version)
        {
            _testSettings.TestType      = TestType.StandaloneBrowser;
            _testSettings.DriverType    = driverType;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Standalone Browsers\\";
            _driver = WebDriverManager.InitializeStandaloneBrowserDriver(_testSettings, version, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
        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);
        }
 public WebDriverLogger(ITestWebDriver testWebDriver, ITestOutputHelper testOutputHelper)
     : base(testWebDriver, testOutputHelper)
 {
     _testWebDriver = testWebDriver;
     _testOutputHelper = testOutputHelper;
 }
        /// <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);
        }
Exemplo n.º 14
0
        public void RunMultiBrowserEmulatorTests(Emulator emulator, DeviceOrientation orientation)
        {
            _testSettings.TestType = TestType.EmulatorBrowser;
            _testSettings.DriverType = WebDriverType.ChromeDriver;
            _testSettings.TestDirectory = _testSettings.TestDirectory + "\\Emulator Browsers\\";
            _driver = WebDriverManager.InitializeMultiBrowserEmulatorDriver(_testSettings, emulator, orientation, _testOutputHelper);
            if (_driver == null)
            {
                throw new NullReferenceException("_driver cannot be null");
            }

            PerformTest();

            _driver.Close();
        }
        /// <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;
        }
Exemplo n.º 16
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="WebDriverHighlighter" /> class.
 /// </summary>
 /// <param name="driver">
 ///     The driver.
 /// </param>
 public WebDriverHighlighter(ITestWebDriver driver)
 {
     _driver = driver;
 }
        /// <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 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");
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Logger" /> class.
 /// </summary>
 /// <param name="testWebDriver">The Test Web driver.</param>
 /// <param name="testOutputHelper">The test output helper.</param>
 protected Logger(ITestWebDriver testWebDriver, ITestOutputHelper testOutputHelper)
 {
     _testWebDriver    = testWebDriver;
     _testOutputHelper = testOutputHelper;
 }
        /// <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>
 ///     Initializes a new instance of the <see cref="WebDriverHighlighter" /> class.
 /// </summary>
 /// <param name="driver">
 ///     The driver.
 /// </param>
 public WebDriverHighlighter(ITestWebDriver driver)
 {
     _driver = driver;
 }
        /// <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;
        }
        /// <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;
        }
Exemplo n.º 24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Logger" /> class.
 /// </summary>
 /// <param name="testWebDriver">The Test Web driver.</param>
 /// <param name="testOutputHelper">The test output helper.</param>
 protected Logger(ITestWebDriver testWebDriver, ITestOutputHelper testOutputHelper)
 {
     _testWebDriver = testWebDriver;
     _testOutputHelper = testOutputHelper;
 }
Exemplo n.º 25
0
 public WebDriverLogger(ITestWebDriver testWebDriver, ITestOutputHelper testOutputHelper)
     : base(testWebDriver, testOutputHelper)
 {
     _testWebDriver    = testWebDriver;
     _testOutputHelper = testOutputHelper;
 }