Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="BrowserFactory"/> class.
        /// </summary>
        protected BrowserFactory()
        {
            var configSection = SettingHelper.GetConfigurationSection();
            var browserFactoryConfigurationElement = configSection.BrowserFactory;

            this.driverNeedsValidation = browserFactoryConfigurationElement.DriverNeedsValidation;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the web driver.
        /// </summary>
        /// <param name="seleniumDriver">The selenium driver.</param>
        /// <param name="browserFactoryConfiguration">The browser factory configuration.</param>
        /// <returns>The created web driver.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the browser is not supported.</exception>
        internal IWebDriver CreateWebDriver(ISeleniumDriver seleniumDriver, BrowserFactoryConfiguration browserFactoryConfiguration)
        {
            IWebDriver driver = seleniumDriver.Create(browserFactoryConfiguration);

            // Set Driver Settings
            var managementSettings = driver.Manage();

            // Set timeouts
            var applicationConfiguration = SettingHelper.GetConfigurationSection().Application;

            var timeouts = managementSettings.Timeouts();

            timeouts.ImplicitWait = browserFactoryConfiguration.ElementLocateTimeout;
            timeouts.PageLoad     = browserFactoryConfiguration.PageLoadTimeout;

            ActionBase.DefaultTimeout              = browserFactoryConfiguration.ElementLocateTimeout;
            WaitForPageAction.DefaultTimeout       = browserFactoryConfiguration.PageLoadTimeout;
            ActionBase.RetryValidationUntilTimeout = applicationConfiguration.RetryValidationUntilTimeout;

            if (seleniumDriver.MaximizeWindow)
            {
                // Maximize window
                managementSettings.Window.Maximize();
            }

            return(driver);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="WebDriverSupport" /> class.
        /// </summary>
        /// <param name="objectContainer">The object container.</param>
        public WebDriverSupport(IObjectContainer objectContainer)
        {
            this.objectContainer = objectContainer;
            var configSection = SettingHelper.GetConfigurationSection();
            var browserFactoryConfigurationElement = configSection.BrowserFactory;

            ensureCleanSession = browserFactoryConfigurationElement.EnsureCleanSession;
            reuseBrowser       = browserFactoryConfigurationElement.ReuseBrowser;
        }
Ejemplo n.º 4
0
 public void AfterScenario()
 {
     if (ScenarioContext.Current.TestError != null)
     {
         var driver   = this._objectContainer.Resolve <IBrowser>().Driver();
         var settings = SettingHelper.GetConfigurationSection().BrowserFactory.Settings;
         if (driver is RemoteWebDriver && !(driver is PhantomJSDriver) && !string.IsNullOrEmpty(settings["browserstack.user"].Value) && !string.IsNullOrEmpty(settings["browserstack.key"].Value))
         {
             this._objectContainer.Resolve <IBrowserStackApi>().FailTestSession(ScenarioContext.Current.TestError);
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            var configSection      = SettingHelper.GetConfigurationSection();
            var excludedAssemblies = configSection.Application.ExcludedAssemblies.Cast <AssemblyElement>().Select(a => a.Name);
            // Get all items from the current assemblies
            var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && !a.GlobalAssemblyCache && !excludedAssemblies.Contains(a.FullName));

            foreach (var asmType in assemblies.SelectMany(a => a.GetExportedTypes()).Where(t => !t.IsAbstract && !t.IsInterface))
            {
                this.RegisterType(asmType);
            }
        }
Ejemplo n.º 6
0
        public void BeforeScenario()
        {
            Console.WriteLine("##### Scenario: " + ScenarioContext.Current.ScenarioInfo.Title);

            var log      = this._objectContainer.Resolve <ILog>();
            var settings = SettingHelper.GetConfigurationSection().BrowserFactory.Settings;

            foreach (var key in settings.AllKeys.Where(x => !x.StartsWith("browserstack.")))
            {
                if (!string.IsNullOrEmpty(settings[key]?.Value))
                {
                    log.Info($"{key}:\"{settings[key]?.Value}\"");
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Loads the configuration and creates the browser object.
        /// </summary>
        /// <param name="createMethod">The create method.</param>
        /// <returns>The <see cref="IBrowser"/> object.</returns>
        private IBrowser LoadConfigurationAndCreateBrowser(Func <BrowserType, BrowserFactoryConfigurationElement, ILogger, IBrowser> createMethod)
        {
            var configSection = SettingHelper.GetConfigurationSection();

            // Default configuration settings
            var browserFactoryConfiguration = new BrowserFactoryConfigurationElement
            {
                BrowserType          = Enum.GetName(typeof(BrowserType), BrowserType.IE),
                ElementLocateTimeout = TimeSpan.FromSeconds(30.0),
                PageLoadTimeout      = TimeSpan.FromSeconds(30.0)
            };

            if (configSection != null && configSection.BrowserFactory != null)
            {
                browserFactoryConfiguration = configSection.BrowserFactory;
            }

            var browserType = this.GetBrowserType(browserFactoryConfiguration);

            return(createMethod(browserType, browserFactoryConfiguration, this.Logger));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        public void Initialize()
        {
            var configSection      = SettingHelper.GetConfigurationSection();
            var excludedAssemblies = configSection.Application.ExcludedAssemblies.Select(a => a.Name);
            // Get all items from the current assemblies
            var assemblies = AppDomain.CurrentDomain.GetAssemblies().Where(a => !a.IsDynamic && !a.GlobalAssemblyCache && !excludedAssemblies.Contains(a.FullName));

            foreach (Assembly assembly in assemblies)
            {
                try
                {
                    foreach (var asmType in assembly.GetExportedTypes().Where(t => !t.IsAbstract && !t.IsInterface))
                    {
                        this.RegisterType(asmType);
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception($"Failed to load assembly '{assembly.FullName}'.", ex);
                }
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the browser factory.
        /// </summary>
        /// <param name="logger">The logger.</param>
        /// <returns>A created browser factory.</returns>
        /// <exception cref="System.InvalidOperationException">
        /// The specBind config section must have a browser factor with a provider configured.
        /// </exception>
        internal static BrowserFactory GetBrowserFactory(ILogger logger)
        {
            var configSection = SettingHelper.GetConfigurationSection();

            if (configSection == null || configSection.BrowserFactory == null || string.IsNullOrWhiteSpace(configSection.BrowserFactory.Provider))
            {
                throw new InvalidOperationException("The specBind config section must have a browser factor with a provider configured.");
            }

            var type = Type.GetType(configSection.BrowserFactory.Provider, OnAssemblyCheck, OnGetType);

            if (type == null || !typeof(BrowserFactory).IsAssignableFrom(type))
            {
                throw new InvalidOperationException(string.Format("Could not load factory type: {0}. Make sure this is fully qualified and the assembly exists. Also ensure the base type is BrowserFactory", configSection.BrowserFactory.Provider));
            }

            var factory = (BrowserFactory)Activator.CreateInstance(type);

            factory.Logger = logger;

            return(factory);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Initializes the <see cref="ButtonClickAction"/> class.
        /// </summary>
        static ButtonClickAction()
        {
            var configSection = SettingHelper.GetConfigurationSection();

            WaitForStillElementBeforeClicking = configSection.Application.WaitForStillElementBeforeClicking;
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Determines whether or not to perform web driver validation
        /// </summary>
        /// <returns><c>true</c> if the web driver should be validated; otherwise <c>false</c></returns>
        private static bool ValidateWebDriver()
        {
            var configSection = SettingHelper.GetConfigurationSection();

            return(configSection.BrowserFactory.ValidateWebDriver);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates the web driver.
        /// </summary>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="browserFactoryConfiguration">The browser factory configuration.</param>
        /// <returns>The created web driver.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the browser is not supported.</exception>
        internal static IWebDriver CreateWebDriver(BrowserType browserType, BrowserFactoryConfigurationElement browserFactoryConfiguration)
        {
            if (!RemoteDriverExists(browserFactoryConfiguration.Settings, browserType, out IWebDriver driver))
            {
                switch (browserType)
                {
                case BrowserType.IE:

                    NameValueConfigurationElement ignoreProtectedModeSettingsNameValueConfigurationElement
                        = browserFactoryConfiguration.Settings[IgnoreProtectedModeSettings];
                    bool ignoreProtectedModeSettings = false;
                    if (!string.IsNullOrWhiteSpace(ignoreProtectedModeSettingsNameValueConfigurationElement?.Value))
                    {
                        if (!bool.TryParse(ignoreProtectedModeSettingsNameValueConfigurationElement.Value, out ignoreProtectedModeSettings))
                        {
                            throw new ConfigurationErrorsException(
                                      $"The {IgnoreProtectedModeSettings} setting is not a valid boolean: {ignoreProtectedModeSettingsNameValueConfigurationElement.Value}");
                        }
                    }

                    var explorerOptions = new InternetExplorerOptions
                    {
                        EnsureCleanSession = browserFactoryConfiguration.EnsureCleanSession,
                        IntroduceInstabilityByIgnoringProtectedModeSettings = ignoreProtectedModeSettings
                    };

                    var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();
                    internetExplorerDriverService.HideCommandPromptWindow = true;
                    driver = new InternetExplorerDriver(internetExplorerDriverService, explorerOptions);
                    break;

                case BrowserType.FireFox:
                    driver = GetFireFoxDriver(browserFactoryConfiguration);
                    break;

                case BrowserType.Chrome:
                case BrowserType.ChromeHeadless:
                    var chromeOptions = new ChromeOptions {
                        LeaveBrowserRunning = false
                    };

                    var cmdLineSetting = browserFactoryConfiguration.Settings[ChromeArgumentSetting];
                    if (!string.IsNullOrWhiteSpace(cmdLineSetting?.Value))
                    {
                        foreach (var arg in cmdLineSetting.Value.Split(';'))
                        {
                            chromeOptions.AddArgument(arg);
                        }
                    }

                    // Activate chrome headless via a command line
                    if (browserType == BrowserType.ChromeHeadless)
                    {
                        chromeOptions.AddArgument("--headless");
                    }

                    var chromeDriverService = ChromeDriverService.CreateDefaultService();
                    chromeDriverService.HideCommandPromptWindow = true;

                    driver = new ChromeDriver(chromeDriverService, chromeOptions);
                    break;

                case BrowserType.PhantomJS:
                    var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
                    phantomJsDriverService.HideCommandPromptWindow = true;
                    driver = new PhantomJSDriver(phantomJsDriverService);
                    break;

                case BrowserType.Safari:
                    driver = new SafariDriver();
                    break;

                case BrowserType.Edge:
                    var edgeOptions = new EdgeOptions {
                        PageLoadStrategy = EdgePageLoadStrategy.Normal
                    };
                    var edgeDriverService = EdgeDriverService.CreateDefaultService();
                    driver = new EdgeDriver(edgeDriverService, edgeOptions);
                    break;

                default:
                    throw new InvalidOperationException(
                              $"Browser type '{browserType}' is not supported in Selenium local mode. Did you mean to configure a remote driver?");
                }
            }

            // Set Driver Settings
            var managementSettings = driver.Manage();

            // Set timeouts

            var applicationConfiguration = SettingHelper.GetConfigurationSection().Application;

            var timeouts = managementSettings.Timeouts();

            timeouts.ImplicitWait = browserFactoryConfiguration.ElementLocateTimeout;
            timeouts.PageLoad     = browserFactoryConfiguration.PageLoadTimeout;

            ActionBase.DefaultTimeout              = browserFactoryConfiguration.ElementLocateTimeout;
            WaitForPageAction.DefaultTimeout       = browserFactoryConfiguration.PageLoadTimeout;
            ActionBase.RetryValidationUntilTimeout = applicationConfiguration.RetryValidationUntilTimeout;

            // Maximize window
            managementSettings.Window.Maximize();

            return(driver);
        }
Ejemplo n.º 13
0
        public NetworkCredential FindNetworkCredential()
        {
            var settings = SettingHelper.GetConfigurationSection().BrowserFactory.Settings;

            return(new NetworkCredential(settings["browserstack.user"].Value, settings["browserstack.key"].Value));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Loads the configuration.
        /// </summary>
        /// <returns>The browser factory configuration.</returns>
        protected static BrowserFactoryConfiguration LoadConfiguration()
        {
            var configSection = SettingHelper.GetConfigurationSection();

            return(configSection.BrowserFactory);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Initializes the <see cref="ActionPipelineService"/> class.
        /// </summary>
        static ActionPipelineService()
        {
            var configSection = SettingHelper.GetConfigurationSection();

            ConfiguredActionRetryLimit = configSection.Application.ActionRetryLimit;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes the <see cref="ActionPipelineService"/> class.
 /// </summary>
 static ActionPipelineService()
 {
     var configSection = SettingHelper.GetConfigurationSection();
 }