Navigator session parameters.
For a list of valid remote browsers, versions and platforms, check https://saucelabs.com/platforms/webdriver
        private static IWebDriver Chrome(NavigatorSessionParameters session)
        {
            var service = ChromeDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = session.HideCommandPromptWindow;

            return new ChromeDriver(service, new ChromeOptions());
        }
        private static FirefoxDriver Firefox(NavigatorSessionParameters session)
        {
            var profile = new FirefoxProfile { AcceptUntrustedCertificates = session.AcceptUntrustedCertificates };
            profile.SetPreference("browser.startup.homepage", "about:blank");

            return new FirefoxDriver(profile);
        }
Ejemplo n.º 3
0
        public static void Initialize(NavigatorSessionParameters session)
        {
            if (navigator != null)
            {
                navigator.Close();
            }

            var driver = WebDriverFactory.Create(session);

            navigator = new Navigator(driver, session.NavigationMap)
            {
                IsQuietMode =
                    session.WebDriverType
                    == WebDriverType.PhantomJs
            };
        }
 private static IWebDriver CreateDriver(NavigatorSessionParameters session)
 {
     switch (session.WebDriverType)
     {
         case WebDriverType.Chrome:
             return Chrome(session);
         case WebDriverType.Firefox:
             return Firefox(session);
         case WebDriverType.InternetExplorer:
             return InternetExplorer(session);
         case WebDriverType.PhantomJs:
             return PhantomJs(session);
         case WebDriverType.Remote:
             return RemoteDriver(session);
         case WebDriverType.Safari:
             return Safari();
         default:
             return PhantomJs(session);
     }
 }
Ejemplo n.º 5
0
        public static void Setup(INavigationMap map)
        {
            try
            {
                map.Initialize(TestEnvironment.Current.WebsiteUrl);

                var parameters = new NavigatorSessionParameters
                                 {
                                         NavigationMap = map,
                                         AcceptUntrustedCertificates = TestEnvironment.Current.AcceptUntrustedCertificates,
                                         WebDriverType = TestEnvironment.Current.WebDriverType,
                                         HideCommandPromptWindow = TestEnvironment.Current.HideCommandPromptWindow,
                                         ImplicitlyWait = TestEnvironment.Current.ImplicitlyWait,
                                         PageLoadTimeout = TestEnvironment.Current.PageLoadTimeout,
                                         ScriptTimeout = TestEnvironment.Current.ScriptTimeout,
                                         RunUsingSauceLabs = TestEnvironment.Current.RunUsingSauceLabs,
                                         SauceLabsRemoteBrowser = TestEnvironment.Current.SauceLabsRemoteBrowser,
                                         SauceLabsRemoteBrowserVersion = TestEnvironment.Current.SauceLabsRemoteBrowserVersion,
                                         SauceLabsRemotePlatform = TestEnvironment.Current.SauceLabsRemotePlatform,
                                         SauceLabsRemoteDriverUrl = TestEnvironment.Current.SauceLabsRemoteUrl,
                                         SauceLabsRemoteUsername = TestEnvironment.Current.SauceLabsRemoteUsername,
                                         SauceLabsRemoteKey = TestEnvironment.Current.SauceLabsRemoteKey
                                 };

                Navigator.Initialize(parameters);
            }
            catch (Exception ex)
            {
                var sb = new StringBuilder();
                sb.AppendLine("[Error] BrowserSetup");

                sb.AppendLine("Exception:");
                sb.AppendLine("   ");
                sb.AppendLine(ex.ToString());

                sb.AppendLine("Parameters:");
                sb.AppendLine(TestEnvironment.Current.Description);

                throw new ApplicationException(sb.ToString());
            }
        }
        private static IWebDriver InternetExplorer(NavigatorSessionParameters session)
        {
            var service = InternetExplorerDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = session.HideCommandPromptWindow;

            return new InternetExplorerDriver(service, new InternetExplorerOptions());
        }
 public static IWebDriver Create(NavigatorSessionParameters session)
 {
     var driver = CreateDriver(session);
     Manage(driver, session);
     return driver;
 }
        private static IWebDriver RemoteDriver(NavigatorSessionParameters session)
        {
            var remoteAddress = new Uri(session.SauceLabsRemoteDriverUrl);

            var capabilities = GetDefaultCapabilities(session.SauceLabsRemoteBrowser);

            capabilities.SetCapability(CapabilityType.Platform, session.SauceLabsRemotePlatform);
            capabilities.SetCapability(CapabilityType.Version, session.SauceLabsRemoteBrowserVersion);
            capabilities.SetCapability(CapabilityTypeExt.Username, session.SauceLabsRemoteUsername);
            capabilities.SetCapability(CapabilityTypeExt.AccessKey, session.SauceLabsRemoteKey);
            capabilities.SetCapability(CapabilityTypeExt.TestName, TestContext.CurrentContext.Test.Name);

            if (session.AcceptUntrustedCertificates)
            {
                capabilities.SetCapability("AcceptUntrustedCertificates", true);
            }

            return new RemoteDriver(remoteAddress, capabilities);
        }
        private static IWebDriver PhantomJs(NavigatorSessionParameters session)
        {
            var service = PhantomJSDriverService.CreateDefaultService();
            service.HideCommandPromptWindow = session.HideCommandPromptWindow;

            return new PhantomJSDriver(service, new PhantomJSOptions());
        }
        private static void Manage(IWebDriver driver, NavigatorSessionParameters session)
        {
            var elementSearchTimeout = TimeSpan.FromSeconds(session.ImplicitlyWait);
            driver.Manage().Timeouts().ImplicitlyWait(elementSearchTimeout);

            // Note: Issue with SauceLabs. Some platform+browser+version 
            // combinations throw an exception when trying to set this.
            if (!session.RunUsingSauceLabs)
            {
                var pageLoadTimeout = TimeSpan.FromSeconds(session.PageLoadTimeout);
                driver.Manage().Timeouts().SetPageLoadTimeout(pageLoadTimeout);
            }

            var scriptTimeout = TimeSpan.FromSeconds(session.ScriptTimeout);
            driver.Manage().Timeouts().SetScriptTimeout(scriptTimeout);
        }