Пример #1
0
        public static IWebDriver Build(string browserName)
        {
            switch (browserName.ToLower())
            {
            case "chrome":
                var chromeService = ChromeDriverService.CreateDefaultService(pathToDriversDir);
                //service.LogPath = "./chromedriver.log";
                //service.EnableVerboseLogging = true;
                return(new ChromeDriver(chromeService));

            case "firefox":
                var firefoxService = FirefoxDriverService.CreateDefaultService(pathToDriversDir);
                //firefoxService.FirefoxBinaryPath = @"C:\Program Files (x86)\Mozilla Firefox\firefox.exe";
                firefoxService.FirefoxBinaryPath = GetFolderPath(SpecialFolder.LocalApplicationData) + "\\Mozilla Firefox\\firefox.exe";
                return(new FirefoxDriver(firefoxService));

            case "edge":
                //Version 4.0.0-alpha05
                var edgeOptions = new EdgeOptions()
                {
                    UseChromium = true
                };                                                              //set to false so do not create legacy version
                //edgeOptions.UseInPrivateBrowsing = true;
                // prevents popup regarding ability to load extensions when browser
                // spawned due to non admin permissions on file system
                edgeOptions.AddAdditionalChromeOption("useAutomationExtension", false);
                var edgeService = EdgeDriverService.CreateChromiumService(pathToDriversDir);
                return(new EdgeDriver(edgeService, edgeOptions));

            default:
                throw new System.ArgumentException($"{browserName} not supported.");
            }
        }
Пример #2
0
 public MsEdgeDriverBuilder()
 {
     service = EdgeDriverService.CreateChromiumService(
         Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location), $"{ExecutableName}.exe");
     service.EnableVerboseLogging = false;
     service.SuppressInitialDiagnosticInformation = true;
     service.HideCommandPromptWindow = true;
 }
Пример #3
0
        public override IWebDriver GetDriver()
        {
            var options = new EdgeOptions();

            options.UseChromium = true;
            options.AddArgument("ignore-certificate-errors");
            var service = EdgeDriverService.CreateChromiumService(DriversPath);

            return(new OpenQA.Selenium.Edge.EdgeDriver(service, options, TimeSpan.FromMinutes(3)));
        }
Пример #4
0
        private static IWebDriver CreateSeleniumDriver(this SpecFlowContext specFlowContext, IConfiguration configuration)
        {
            System.Enum.TryParse(configuration[Constants.EnvironmentVariableKeys.Browser], true, out BrowserTypes browser);

            switch (browser)
            {
            case BrowserTypes.Edge:
                EdgeOptions egdeOptions = new EdgeOptions
                {
                    PageLoadStrategy = PageLoadStrategy.Normal,
                    UseChromium      = true
                };

                EdgeDriverService edgeDriverService = EdgeDriverService.CreateChromiumService(configuration[Constants.EnvironmentVariableKeys.EdgeWebDriver]);

                specFlowContext.Set((IWebDriver) new EdgeDriver(edgeDriverService, egdeOptions));
                break;

            case BrowserTypes.Firefox:
                specFlowContext.Set((IWebDriver) new FirefoxDriver());
                break;

            case BrowserTypes.InternetExplorer:

                InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions()
                {
                    BrowserVersion  = configuration[Constants.EnvironmentVariableKeys.InternetExplorerVersion],
                    IgnoreZoomLevel = true
                };

                specFlowContext.Set((IWebDriver) new InternetExplorerDriver(internetExplorerOptions));
                break;

            case BrowserTypes.Safari:
                SafariDriverService safariDriverService = SafariDriverService.CreateDefaultService();
                SafariOptions       safariOptions       = new SafariOptions();
                safariOptions.PageLoadStrategy = PageLoadStrategy.Normal;
                specFlowContext.Set((IWebDriver) new SafariDriver(safariDriverService));
                break;

            default:
            {
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
                chromeDriverService.SuppressInitialDiagnosticInformation = true;
                specFlowContext.Set((IWebDriver) new ChromeDriver(chromeDriverService));
            }
            break;
            }

            return(specFlowContext.Get <IWebDriver>());
        }
Пример #5
0
 public void TestChromiumServiceWithLegacyOptions()
 {
     using (var service = EdgeDriverService.CreateChromiumService())
     {
         try
         {
             var driver = new EdgeDriver(service, new EdgeOptions());
             Assert.Fail();
         }
         catch (WebDriverException e)
         {
             Assert.AreEqual("options.UseChromium must be set to true when using an Edge Chromium driver service.", e.Message);
         }
     }
 }
Пример #6
0
        public EdgeDriverCreator(Proxy proxy, TimeSpan timeout) : base(proxy, timeout)
        {
            var driverFolder = Environment.GetEnvironmentVariable("EdgeWebDriver");

            try
            {
                _driverService = driverFolder == null
                    ? EdgeDriverService.CreateChromiumService()
                    : EdgeDriverService.CreateChromiumService(driverFolder);
            }
            catch (DriverServiceNotFoundException)
            {
                // Ignore, we might not need the driver
            }
        }
Пример #7
0
 public void TestChromiumServiceWithChromiumOptions()
 {
     using (var service = EdgeDriverService.CreateChromiumService())
     {
         var driver = new EdgeDriver(service, new EdgeOptions()
         {
             UseChromium = true
         });
         try
         {
             UsesChromium(driver);
         }
         finally
         {
             driver.Quit();
         }
     }
 }
Пример #8
0
        public EdgeBrowser(string driver, TimeSpan timeout, params string[] arguments)
        {
            var file = base.ValidateDriver(driver);

            var options = new EdgeOptions
            {
                UseChromium = true
            };

            if (arguments != null && arguments.Length > 0)
            {
                options.AddArguments(arguments);
            }

            var service = EdgeDriverService.CreateChromiumService(file.DirectoryName, file.Name);

            service.EnableVerboseLogging    = false;
            service.HideCommandPromptWindow = true;

            this.Timeout    = timeout;
            this.Driver     = new EdgeDriver(service, options);
            this.DriverWait = new WebDriverWait(base.Driver, timeout);
        }
Пример #9
0
        private static IWebDriver CreateDriver()
        {
            try
            {
                var programDirectory = System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var edgeService      = EdgeDriverService.CreateChromiumService($"{programDirectory}\\Drivers", $"{DriverName}.exe");
                edgeService.SuppressInitialDiagnosticInformation = true;
                edgeService.HideCommandPromptWindow = true;

                var options = new EdgeOptions {
                    UseChromium = true
                };
                options.AddArgument("headless");
                options.AddArgument("disable-gpu");

                return(new EdgeDriver(edgeService, options));
            }
            catch (InvalidOperationException)
            {
                Console.WriteLine("Unable to download due to MicrosoftEdge not up to date. Please update it before proceeding.");
                throw;
            }
        }
Пример #10
0
        public IWebDriver CreateDriver()
        {
            EdgeDriverService service = EdgeDriverService.CreateChromiumService(AppDomain.CurrentDomain.BaseDirectory);

            service.LogPath = $"{AppDomain.CurrentDomain.BaseDirectory}MsEdgeDriver.log";

            EdgeOptions options = new() { UseChromium = true };

            //options.AddExcludedArgument("enable-automation");
            options.AddAdditionalCapability("useAutomationExtension", false);
            options.AddUserProfilePreference("download.default_directory", AppDomain.CurrentDomain.BaseDirectory);
            options.AddUserProfilePreference("download.prompt_for_download", true);
            options.AddUserProfilePreference("disable-popup-blocking", true);
            options.AddUserProfilePreference("credentials_enable_service", false);
            options.AddUserProfilePreference("profile.password_manager_enabled", false);
            options.AddArguments(
                "--disable-extensions",
                "--disable-web-security",
                "--disable-popup-blocking",
                "--disable-notifications",
                "--start-maximized");
            return(new EdgeDriver(service, options));
        }
    }