Example #1
0
 public SeleniumBrowserFactory(Settings configuration)
 {
     this.configuration = configuration;
     driverFactory      = new Dictionary <BrowserNames, Func <string, IBrowserDriver> >
     {
         { BrowserNames.chrome, bdp =>
           //TODO: extract window parameters in specDrillConfig.json
           {
               var chromeOptions = new ChromeOptions();
               chromeOptions.AddArgument("window-size=1920,1080");
               return(SeleniumBrowserDriver.Create(new ChromeDriver(bdp, chromeOptions)));
           } },
         { BrowserNames.ie, bdp => SeleniumBrowserDriver.Create(new InternetExplorerDriver(bdp)) },
         { BrowserNames.firefox, bdp => SeleniumBrowserDriver.Create(new FirefoxDriver()) },
         { BrowserNames.opera, bdp => SeleniumBrowserDriver.Create(new OperaDriver()) },
         { BrowserNames.safari, bdp => SeleniumBrowserDriver.Create(new SafariDriver()) }
         //,{ BrowserNames.appium, bdp => {
         //    DesiredCapabilities capabilities = new DesiredCapabilities();
         //    capabilities.SetCapability(MobileCapabilityType.PlatformVersion, "5.1");
         //    capabilities.SetCapability(MobileCapabilityType.DeviceName, "Samsung Galaxy S4");
         //    //capabilities.SetCapability(MobileCapabilityType.App, app);
         //    capabilities.SetCapability("unicodeKeyboard", true);
         //    capabilities.SetCapability("autoAcceptAlerts", true);
         //    return SeleniumBrowserDriver.Create(new AndroidDriver<AppiumWebElement>(
         //        new Uri("http://127.0.0.1:4723/wd/hub"), capabilities, TimeSpan.FromSeconds(60))); } }
     };
 }
        public SeleniumBrowserFactory(Settings configuration)
        {
            var aPath = System.Reflection.Assembly.GetExecutingAssembly().Location;

            Log.Info($"Assembly path = {aPath}");
            this.configuration = configuration;
            driverFactory      = new Dictionary <BrowserNames, Func <IBrowserDriver> >
            {
                { BrowserNames.chrome, () =>
                  {
                      Log.Info("Initializig Chrome driver...");
                      var bdp = GetBrowserDriversPath(configuration?.WebDriver?.Browser?.Drivers?.Chrome?.Path ?? "");
                      return(SeleniumBrowserDriver.Create(new ChromeDriver(bdp, BuildChromeOptions()), this.configuration));
                  } },
                { BrowserNames.ie, () =>
                  {
                      Log.Info("Initializig IE driver...");
                      return(SeleniumBrowserDriver.Create(new InternetExplorerDriver(GetBrowserDriversPath(configuration?.WebDriver?.Browser?.Drivers?.Ie?.Path ?? ""), BuildInternetExplorerOptions()), this.configuration));
                  } },
                { BrowserNames.edge, () =>
                  {
                      Log.Info("Initializig Edge driver...");
                      return(SeleniumBrowserDriver.Create(new EdgeDriver(GetBrowserDriversPath(configuration?.WebDriver?.Browser?.Drivers?.Edge?.Path ?? ""), BuildEdgeOptions()), this.configuration));
                  } },
                { BrowserNames.firefox, () =>
                  {
                      Log.Info("Initializig Firefox driver...");
                      var binPath = configuration?.WebDriver?.Browser?.Drivers?.Firefox?.BrowserBinaryPath ?? "";
                      var fds     = FirefoxDriverService.CreateDefaultService(configuration?.WebDriver?.Browser?.Drivers?.Firefox?.Path ?? "");

                      if (!string.IsNullOrWhiteSpace(binPath))
                      {
                          fds.FirefoxBinaryPath = binPath;
                      }

                      //Environment.SetEnvironmentVariable("webdriver.gecko.driver", configuration.WebDriver.Browser.Drivers.Firefox.Path);
                      return(SeleniumBrowserDriver.Create(new FirefoxDriver(fds, BuildFirefoxOptions(), TimeSpan.FromSeconds(60)), this.configuration));
                  } },
                { BrowserNames.opera, () => {
                      Log.Info("Initializig Opera driver...");
                      return(SeleniumBrowserDriver.Create(new OperaDriver(configuration?.WebDriver?.Browser?.Drivers?.Opera?.Path ?? "", BuildOperaOptions()), this.configuration));
                  } },
                { BrowserNames.safari, () =>
                  {
                      Log.Info("Initializig Safari driver...");
                      return(SeleniumBrowserDriver.Create(new SafariDriver(configuration?.WebDriver?.Browser?.Drivers?.Safari?.Path ?? "", BuildSafariOptions()), this.configuration));
                  } }
            };
        }
Example #3
0
 public IBrowserDriver CreateRemoteWebDriver(DesiredCapabilities desiredCapabilities)
 {
     return(SeleniumBrowserDriver.Create(
                new RemoteWebDriver(
                    new Uri(configuration.WebDriver.SeleniumServerUri), desiredCapabilities)));
 }