Example #1
0
        private static T ConfigureSettings <T>(ILogger logger, string prefix, string settingsFolderName, string defaultFilename, string settingsName, IServiceCollection services, bool registerInstance = false) where T : class, new()
        {
            var runtimeSettingsUtilities = new RuntimeSettingsUtilities(logger);
            var paths             = runtimeSettingsUtilities.GetSettingsFiles(prefix, Path.Combine(Directory.GetCurrentDirectory(), "Runtime"), settingsFolderName, defaultFilename);
            var configurationRoot = runtimeSettingsUtilities.Buildconfiguration(prefix, paths);

            var controlSettings = configurationRoot.GetSection(settingsName);

            var instance = new T();

            controlSettings.Bind(instance);

            instance = SubstituteEnvironmentVariables <T>(instance);

            var cleansor = instance as ICleanse;

            if (cleansor != null)
            {
                cleansor.Cleanse();
            }

            if (registerInstance)
            {
                services.AddSingleton <T>(isp => instance);
            }

            return(instance);
        }
Example #2
0
        private static void ConfigureDeviceSettings(ILogger logger, string prefix, IServiceCollection services)
        {
            var runtimeSettingsUtilities = new RuntimeSettingsUtilities(logger);
            var paths             = runtimeSettingsUtilities.GetSettingsFiles(prefix, Path.Combine(Directory.GetCurrentDirectory(), "Runtime"), "DeviceSettings", "desktop-selenium-default.json");
            var configurationRoot = runtimeSettingsUtilities.Buildconfiguration(prefix, paths);

            var platformName = configurationRoot.GetSection("platformName")?.Value?.ToUpper();

            switch (platformName)
            {
            case "DESKTOP":
                var instance = new DesktopSettings();

                instance.PlatformName = platformName;

                services.AddSingleton(instance);
                services.AddSingleton <IDeviceProperties>(instance);
                break;

            /*
             * case "ANDROID":
             * var androidSettings = new AppiumSettings();
             *
             * configurationRoot.Bind(androidSettings);
             *
             * androidSettings = SubstituteEnvironmentVariables<AppiumSettings>(androidSettings);
             *
             * androidSettings.PlatformName = platformName;
             * androidSettings.Cleanse();
             *
             * services.AddSingleton(androidSettings);
             * services.AddSingleton<IDeviceProperties>(androidSettings);
             * break;
             */
            default:
                throw new System.ArgumentOutOfRangeException($"The device called {platformName} is currently not supported. ");
            }
        }
Example #3
0
        private static void ConfigureBrowserSettings(ILogger logger, string prefix, IServiceCollection services)
        {
            var runtimeSettingsUtilities = new RuntimeSettingsUtilities(logger);
            var paths             = runtimeSettingsUtilities.GetSettingsFiles(prefix, Path.Combine(Directory.GetCurrentDirectory(), "Runtime"), "BrowserSettings", "default-chrome.json");
            var configurationRoot = runtimeSettingsUtilities.Buildconfiguration(prefix, paths);

            var browserName     = configurationRoot.GetSection("browserName")?.Value?.ToUpper();
            var browserSettings = configurationRoot.GetSection("browserSettings");

            switch (browserName)
            {
            case "CHROME":
                var instance = new ChromeBrowserSettings();

                browserSettings.Bind(instance);

                instance = SubstituteEnvironmentVariables <ChromeBrowserSettings>(instance);

                instance.BrowserName = browserName;
                instance.Cleanse();

                services.AddSingleton(instance);
                services.AddSingleton <IBrowserProperties>(instance);
                break;

            /*
             * case "EDGE":
             * var edgeInstance = new EdgeBrowserSettings();
             *
             * browserSettings.Bind(edgeInstance);
             *
             * edgeInstance = SubstituteEnvironmentVariables<EdgeBrowserSettings>(edgeInstance);
             *
             * edgeInstance.BrowserName = browserName;
             * edgeInstance.Cleanse();
             *
             * services.AddSingleton(edgeInstance);
             * services.AddSingleton<IBrowserProperties>(edgeInstance);
             * break;
             * case "FIREFOX":
             * var ffInstance = new FireFoxBrowserSettings();
             *
             * browserSettings.Bind(ffInstance);
             *
             * ffInstance = SubstituteEnvironmentVariables<FireFoxBrowserSettings>(ffInstance);
             *
             * ffInstance.BrowserName = browserName;
             * ffInstance.Cleanse();
             *
             * services.AddSingleton(ffInstance);
             * services.AddSingleton<IBrowserProperties>(ffInstance);
             * break;
             * case "INTERNETEXPLORER":
             * var ieInstance = new InternetExplorerBrowserSettings();
             *
             * browserSettings.Bind(ieInstance);
             *
             * ieInstance = SubstituteEnvironmentVariables<InternetExplorerBrowserSettings>(ieInstance);
             *
             * ieInstance.BrowserName = browserName;
             * ieInstance.Cleanse();
             *
             * services.AddSingleton(ieInstance);
             * services.AddSingleton<IBrowserProperties>(ieInstance);
             * break;
             */
            default:
                throw new System.ArgumentOutOfRangeException($"The browser called {browserName} is currently not supported. ");
            }
        }