Search in sources :

Example 1 with CapabilitiesLoder

use of com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoder in project carina by qaprosoft.

the class AbstractTest method executeBeforeTestSuite.

@BeforeSuite(alwaysRun = true)
public void executeBeforeTestSuite(ITestContext context) {
    // Add shutdown hook
    Runtime.getRuntime().addShutdownHook(new ShutdownHook());
    // Set log4j properties
    PropertyConfigurator.configure(ClassLoader.getSystemResource("log4j.properties"));
    // Set SoapUI log4j properties
    System.setProperty("soapui.log4j.config", "./src/main/resources/soapui-log4j.xml");
    try {
        Logger root = Logger.getRootLogger();
        Enumeration<?> allLoggers = root.getLoggerRepository().getCurrentCategories();
        while (allLoggers.hasMoreElements()) {
            Category tmpLogger = (Category) allLoggers.nextElement();
            if (tmpLogger.getName().equals("com.qaprosoft.carina.core")) {
                tmpLogger.setLevel(Level.toLevel(Configuration.get(Parameter.CORE_LOG_LEVEL)));
            }
        }
    } catch (NoSuchMethodError e) {
        LOGGER.error("Unable to redefine logger level due to the conflicts between log4j and slf4j!");
    }
    startDate = new Date().getTime();
    LOGGER.info(Configuration.asString());
    // Configuration.validateConfiguration();
    LOGGER.debug("Default thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());
    context.getCurrentXmlTest().getSuite().setThreadCount(Configuration.getInt(Parameter.THREAD_COUNT));
    LOGGER.debug("Updated thread_count=" + context.getCurrentXmlTest().getSuite().getThreadCount());
    // update DataProviderThreadCount if any property is provided otherwise sync with value from suite xml file
    int count = Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT);
    if (count > 0) {
        LOGGER.debug("Updated 'data_provider_thread_count' from " + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount() + " to " + count);
        context.getCurrentXmlTest().getSuite().setDataProviderThreadCount(count);
    } else {
        LOGGER.debug("Synching data_provider_thread_count with values from suite xml file...");
        R.CONFIG.put(Parameter.DATA_PROVIDER_THREAD_COUNT.getKey(), String.valueOf(context.getCurrentXmlTest().getSuite().getDataProviderThreadCount()));
        LOGGER.debug("Updated 'data_provider_thread_count': " + Configuration.getInt(Parameter.DATA_PROVIDER_THREAD_COUNT));
    }
    LOGGER.debug("Default data_provider_thread_count=" + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());
    LOGGER.debug("Updated data_provider_thread_count=" + context.getCurrentXmlTest().getSuite().getDataProviderThreadCount());
    if (!Configuration.isNull(Parameter.URL)) {
        if (!Configuration.get(Parameter.URL).isEmpty()) {
            RestAssured.baseURI = Configuration.get(Parameter.URL);
        }
    }
    try {
        L10N.init();
    } catch (Exception e) {
        LOGGER.error("L10N bundle is not initialized successfully!", e);
    }
    try {
        I18N.init();
    } catch (Exception e) {
        LOGGER.error("I18N bundle is not initialized successfully!", e);
    }
    try {
        L10Nparser.init();
    } catch (Exception e) {
        LOGGER.error("L10Nparser bundle is not initialized successfully!", e);
    }
    // TODO: move out from AbstractTest->executeBeforeTestSuite
    String customCapabilities = Configuration.get(Parameter.CUSTOM_CAPABILITIES);
    if (!customCapabilities.isEmpty()) {
        // redefine core CONFIG properties using custom capabilities file
        new CapabilitiesLoder().loadCapabilities(customCapabilities);
    }
    String extraCapabilities = Configuration.get(Parameter.EXTRA_CAPABILITIES);
    if (!extraCapabilities.isEmpty()) {
        // redefine core CONFIG properties using extra capabilities file
        new CapabilitiesLoder().loadCapabilities(extraCapabilities);
    }
    try {
        TestRail.updateBeforeSuite(context, this.getClass().getName(), getTitle(context));
    } catch (Exception e) {
        LOGGER.error("TestRail is not initialized successfully!", e);
    }
    updateAppPath();
}
Also used : Category(org.apache.log4j.Category) Logger(org.apache.log4j.Logger) CapabilitiesLoder(com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoder) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

CapabilitiesLoder (com.qaprosoft.carina.core.foundation.webdriver.core.capability.CapabilitiesLoder)1 FileNotFoundException (java.io.FileNotFoundException)1 Category (org.apache.log4j.Category)1 Logger (org.apache.log4j.Logger)1