All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.version1.webdriver.configuration.ConfigurationLoader Maven / Gradle / Ivy

Go to download

A simple Selenium framework offering externalised configuration, a good selection of libraries for supporting test data, simple WebDriver browser binary resolution and an opinionated approach for WebDriver test design.

The newest version!
package com.version1.webdriver.configuration;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.version1.webdriver.configuration.utils.FileLoaderUtils;
import com.version1.webdriver.utils.JsonUtils;

import java.io.IOException;

/**
 * Provides a way to load either a default configuration of a configuration from file
 */
public class ConfigurationLoader {

    private final String INTERNAL_CONFIGURATION_FILE = "config.json";
    private String targetConfigurationFile;

    /**
     * Method for figuring out if we're using the internal, default configuration, or we're setting a reference
     * to an external configuration file (from the file system).
     * @return ConfigurationLoader builder pattern so returns self
     */
    public ConfigurationLoader decideWhichConfigurationToUse() {
        String configurationProperty = System.getProperty("config", "DEFAULT");
        if(configurationProperty.toUpperCase().trim().equals("DEFAULT")) {
            this.targetConfigurationFile = INTERNAL_CONFIGURATION_FILE;
            return this;
        }

        if(configurationProperty.toLowerCase().trim().contains(".json")) {
            this.targetConfigurationFile = configurationProperty;
            return this;
        }

        throw new RuntimeException("Issue figuring out what configuration to use");
    }

    /**
     * This method builds the configuration and returns it
     * @return WebDriverConfig the loaded WebDriverConfig
     */
    public WebDriverConfig build() {
        try {
            return JsonUtils.fromFile(
                    FileLoaderUtils.loadFromClasspathOrFileSystem(targetConfigurationFile), WebDriverConfig.class);
        } catch (IOException e) {
            throw new RuntimeException("Unable to load configuration from " + targetConfigurationFile);
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy