Beispiel #1
0
        private static T RegisterSettings <T>(ILogger logger, string prefix, string settingsFolderName, string defaultFilename, string settingsName, IServiceCollection services, bool registerInstance = false) where T : class, new()
        {
            var runtimeSettingsUtilities = new RuntimeSettings(logger);
            var paths             = runtimeSettingsUtilities.CalculatePathsOfSettingsFiles(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(instance);

            var cleansor = instance as ICleanse;

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

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

            return(instance);
        }
Beispiel #2
0
        private static void RegisterDeviceSettings(ILogger logger, string prefix, IServiceCollection services)
        {
            var runtimeSettingsUtilities = new RuntimeSettings(logger);
            var paths             = runtimeSettingsUtilities.CalculatePathsOfSettingsFiles(prefix, Path.Combine(Directory.GetCurrentDirectory(), "Runtime"), "DeviceSettings", "common-desktop-selenium.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(androidSettings);

                androidSettings.PlatformName = platformName;
                androidSettings.Cleanse();

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

            default:
                throw new ArgumentOutOfRangeException($"The device called {platformName} is currently not supported. ");
            }
        }
Beispiel #3
0
        private static void RegisterBrowserSettings(ILogger logger, string prefix, IServiceCollection services)
        {
            var runtimeSettingsUtilities = new RuntimeSettings(logger);
            var paths             = runtimeSettingsUtilities.CalculatePathsOfSettingsFiles(prefix, Path.Combine(Directory.GetCurrentDirectory(), "Runtime"), "BrowserSettings", "common-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(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(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(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(ieInstance);

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

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

            default:
                throw new ArgumentOutOfRangeException($"The browser called {browserName} is currently not supported. ");
            }
        }