/// <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;
 }
예제 #2
0
 public void InitScenario()
 {
     FirefoxOptions options = new FirefoxOptions();
     var profile = new FirefoxProfile();
     var binary = new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");
     driver = new FirefoxDriver(binary, profile);
 }
예제 #3
0
        public WebTestContext()
        {
            FirefoxOptions options = new FirefoxOptions();
            var profile = new FirefoxProfile();
            var binary = new FirefoxBinary(@"C:\Program Files (x86)\Mozilla Firefox\firefox.exe");

            if (Driver == null)
                Driver = new FirefoxDriver(binary, profile);
        }
예제 #4
0
        private static FirefoxOptions CreateOptionsFromCapabilities(ICapabilities capabilities)
        {
            // This is awkward and hacky. To be removed when the legacy driver is retired.
            FirefoxBinary       binary      = ExtractBinary(capabilities);
            FirefoxProfile      profile     = ExtractProfile(capabilities);
            DesiredCapabilities desiredCaps = RemoveUnneededCapabilities(capabilities) as DesiredCapabilities;

            FirefoxOptions options = new FirefoxOptions(profile, binary);

            if (desiredCaps != null)
            {
                Dictionary <string, object> capsDictionary = desiredCaps.ToDictionary();
                foreach (KeyValuePair <string, object> capability in capsDictionary)
                {
                    options.AddAdditionalCapability(capability.Key, capability.Value);
                }
            }

            return(options);
        }
예제 #5
0
        private static DriverOptions getBrowserOptions(DriverConfig config)
        {
            DriverOptions opts;

            switch (config.Browser)
            {
            case "firefox":
                var ffOpts = new OpenQA.Selenium.Firefox.FirefoxOptions();

                if (config.Headless)
                {
                    ffOpts.AddArgument("--headless");
                }
                ffOpts.LogLevel = FirefoxDriverLogLevel.Fatal;

                opts = ffOpts;
                break;

            case "chrome":
                var chromeOpts = new OpenQA.Selenium.Chrome.ChromeOptions();
                if (config.Headless)
                {
                    chromeOpts.AddArgument("--headless");
                }
                chromeOpts.AddArgument("--log-level=3");
                chromeOpts.AddArgument("--silent");

                opts = chromeOpts;
                break;

            default:
                throw new NotImplementedException("Not implemented for browser: " + config.Browser);
            }
            opts.SetLoggingPreference(LogType.Browser, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Driver, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Client, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Profiler, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Server, LogLevel.Off);
            return(opts);
        }
예제 #6
0
        public void ShouldAllowUserToSuccessfullyOverrideTheHomePage()
        {
            FirefoxProfile profile = new FirefoxProfile();

            profile.SetPreference("browser.startup.page", "1");
            profile.SetPreference("browser.startup.homepage", javascriptPage);

            FirefoxOptions options = new FirefoxOptions();

            options.Profile = profile;

            IWebDriver driver2 = new FirefoxDriver(options);

            try
            {
                Assert.AreEqual(javascriptPage, driver2.Url);
            }
            finally
            {
                driver2.Quit();
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            FirefoxOptions option = new FirefoxOptions();
            ICapabilities cap = option.ToCapabilities();

            FirefoxProfileManager mangage = new FirefoxProfileManager();
            FirefoxProfile profile = mangage.GetProfile(mangage.ExistingProfiles[0]);

            IWebDriver driver = new FirefoxDriver(profile);

            driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(60));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            driver.Manage().Window.Maximize();
            driver.Navigate().GoToUrl("https://www.baidu.com/");
            IWebElement input = driver.FindElement(By.Id("kw"));
            input.SendKeys("shinetech");
            IWebElement search = driver.FindElement(By.Id("su"));
            search.Click();
            IWebElement shinetech = driver.FindElement(By.XPath("//div[@id='1']/h3/a"));
            if(shinetech!=null)
            {
                if(shinetech.Text.Contains("盛安德"))
                {
                    Console.WriteLine("Find shinetech, test passed");
                }
                else
                {
                    Console.WriteLine("Cannot find Shinetech, test case failed");
                }
            }
            else
            {
                Console.WriteLine("Cannot find Shinetech, test case failed");
            }
            shinetech.Click();
            driver.Dispose();
        }
 public NightlyFirefoxWebDriver(FirefoxDriverService service, FirefoxOptions options)
     : base(service, options)
 {
 }
예제 #9
0
        private static ICapabilities ConvertOptionsToCapabilities(FirefoxOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "options must not be null");
            }

            return options.ToCapabilities();
        }
예제 #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
 {
 }
 public NightlyChannelFirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
     : base(service, options)
 {
 }
예제 #12
0
 public StableChannelFirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
     : base(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
     : base(CreateExecutor(service, options, commandTimeout), ConvertOptionsToCapabilities(options))
 {
 }
        public void Start()
        {
            switch (BaseConfiguration.TestBrowser)
            {
                case BrowserType.Firefox:
                    var fireFoxOptionsLegacy = new FirefoxOptions { Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation };
                    this.driver = new FirefoxDriver(fireFoxOptionsLegacy);
                    break;
                case BrowserType.FirefoxPortable:
                    var fireFoxOptions = new FirefoxOptions { BrowserExecutableLocation = BaseConfiguration.FirefoxPath, Profile = this.FirefoxProfile, UseLegacyImplementation = BaseConfiguration.FirefoxUseLegacyImplementation };
                    this.driver = new FirefoxDriver(fireFoxOptions);
                    break;
                case BrowserType.InternetExplorer:
                    this.driver = new InternetExplorerDriver(this.InternetExplorerProfile);
                    break;
                case BrowserType.Chrome:
                    this.driver = new ChromeDriver(this.ChromeProfile);
                    break;
                case BrowserType.Safari:
                    this.driver = new SafariDriver(this.SafariProfile);
                    break;
                case BrowserType.PhantomJs:
                    this.driver = new PhantomJSDriver(this.CurrentDirectory + BaseConfiguration.PhantomJsPath);
                    break;
                case BrowserType.RemoteWebDriver:
                    this.driver = new RemoteWebDriver(BaseConfiguration.RemoteWebDriverHub, this.SetCapabilities());
                    break;
                default:
                    throw new NotSupportedException(
                        string.Format(CultureInfo.CurrentCulture, "Driver {0} is not supported", BaseConfiguration.TestBrowser));
            }

            this.driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(BaseConfiguration.LongTimeout));
            this.driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(BaseConfiguration.ShortTimeout));
            this.driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(BaseConfiguration.ImplicitlyWaitMilliseconds));
            this.driver.Manage().Window.Maximize();
        }
예제 #15
0
 public ReleaseFirefoxWebDriver(FirefoxDriverService service, FirefoxOptions options)
     : base(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), options.ToCapabilities())
 {
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
 {
     // Add the custom commands unique to Firefox
     this.AddCustomFirefoxCommands();
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
     : base(new DriverServiceCommandExecutor(service, commandTimeout), ConvertOptionsToCapabilities(options))
 {
     // Add the custom commands unique to Firefox
     this.CommandExecutor.CommandInfoRepository.TryAddCommand(SetContextCommand, new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/moz/context"));
 }
예제 #19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified path
 /// to the directory containing geckodriver.exe, options, and command timeout.
 /// </summary>
 /// <param name="geckoDriverDirectory">The full path to the directory containing geckodriver.exe.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 /// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
 public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options, TimeSpan commandTimeout)
     : this(FirefoxDriverService.CreateDefaultService(geckoDriverDirectory), options, commandTimeout)
 {
 }
 /// <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");
 }
예제 #21
0
 private static FirefoxDriverService CreateService(FirefoxOptions options)
 {
     return(FirefoxDriverService.CreateDefaultService());
 }
예제 #22
0
        private static ICommandExecutor CreateExecutor(FirefoxDriverService service, FirefoxOptions options, TimeSpan commandTimeout)
        {
            ICommandExecutor executor = null;
            if (options.UseLegacyImplementation)
            {
                // Note: If BrowserExecutableLocation is null or empty, the legacy driver
                // will still do the right thing, and find Firefox in the default location.
                FirefoxBinary binary = new FirefoxBinary(options.BrowserExecutableLocation);

                FirefoxProfile profile = options.Profile;
                if (profile == null)
                {
                    profile = new FirefoxProfile();
                }

                executor = CreateExtensionConnection(binary, profile, commandTimeout);
            }
            else
            {
                if (service == null)
                {
                    throw new ArgumentNullException("service", "You requested a service-based implementation, but passed in a null service object.");
                }

                return new DriverServiceCommandExecutor(service, commandTimeout);
            }

            return executor;
        }
예제 #23
0
파일: Bot.cs 프로젝트: Deviach/ShowdownBot
        public void initialise(bool browser=true)
        {
            if (browser)
            {
                FirefoxProfileManager pm = new FirefoxProfileManager();
                FirefoxProfile ffp = pm.GetProfile(Global.FF_PROFILE);
                FirefoxOptions fo = new FirefoxOptions();
                fo.SetLoggingPreference(LogType.Driver, LogLevel.Off); //todo allow toggling this
                fo.SetLoggingPreference(LogType.Client, LogLevel.Off);
                
                mainBrowser = new FirefoxDriver(ffp);
            
                mainBrowser.Manage().Window.Maximize(); //prevent unintenttionally hiding elements in some versions of FF
                
                gBrowserInstance = mainBrowser;
                DesiredCapabilities d = new DesiredCapabilities();
            }

            analyticModule = new AnalyticModule(this, mainBrowser);
            randomModule = new RandomModule(this, mainBrowser);
            biasedModule = new BiasedModule(this, mainBrowser);
            compareModule = new ComparativeModule(this, mainBrowser);

        }
예제 #24
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified path
 /// to the directory containing geckodriver.exe and options.
 /// </summary>
 /// <param name="geckoDriverDirectory">The full path to the directory containing geckodriver.exe.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 public FirefoxDriver(string geckoDriverDirectory, FirefoxOptions options)
     : this(geckoDriverDirectory, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #25
0
        private static ICapabilities ConvertOptionsToCapabilities(FirefoxOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "options must not be null");
            }

            ICapabilities capabilities = options.ToCapabilities();
            if (options.UseLegacyImplementation)
            {
                capabilities = RemoveUnneededCapabilities(capabilities);
            }

            return capabilities;
        }
예제 #26
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options, driver service, and timeout. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="service">The <see cref="FirefoxDriverService"/> to use.</param>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 public FirefoxDriver(FirefoxDriverService service, FirefoxOptions options)
     : this(service, options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #27
0
        private static FirefoxOptions CreateOptionsFromCapabilities(ICapabilities capabilities)
        {
            // This is awkward and hacky. To be removed when the legacy driver is retired.
            FirefoxBinary binary = ExtractBinary(capabilities);
            FirefoxProfile profile = ExtractProfile(capabilities);
            DesiredCapabilities desiredCaps = RemoveUnneededCapabilities(capabilities) as DesiredCapabilities;

            FirefoxOptions options = new FirefoxOptions(profile, binary);
            if (desiredCaps != null)
            {
                Dictionary<string, object> capsDictionary = desiredCaps.ToDictionary();
                foreach (KeyValuePair<string, object> capability in capsDictionary)
                {
                    options.AddAdditionalCapability(capability.Key, capability.Value);
                }
            }

            return options;
        }
예제 #28
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 public FirefoxDriver(FirefoxOptions options)
     : this(CreateService(options), options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }
예제 #29
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FirefoxDriver"/> class using the specified options. Uses the Mozilla-provided Marionette driver implementation.
 /// </summary>
 /// <param name="options">The <see cref="FirefoxOptions"/> to be used with the Firefox driver.</param>
 public FirefoxDriver(FirefoxOptions options)
     : this(FirefoxDriverService.CreateDefaultService(), options, RemoteWebDriver.DefaultCommandTimeout)
 {
 }