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

utilities.TestRunningManager Maven / Gradle / Ivy

Go to download

An open-source Selenium Java-based Test automation Framework that allows you to perform multiple actions to test a web application's functionality, behaviour, which provides easy to use syntax, and easy to set up environment according to the needed requirements for testing

There is a newer version: 1.1.1
Show newest version
package utilities;

import org.junit.platform.launcher.LauncherSessionListener;
import org.testng.ITestNGListener;
import org.testng.TestNG;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Stream;

public class TestRunningManager {

    private static boolean isJunitRunBool = false;
    private static boolean isTestNGRunBool = false;

    private TestRunningManager() {

    }

    public static void initializeRunConfigurations() {

        identifyRunType();

        if (isTestNGRunBool) {
            ServiceLoader serviceLoader = ServiceLoader.load(ITestNGListener.class);
            serviceLoader.reload();
            LoggingManager.info("Start Running Tests via TestNG Runner");
        }

        if (isJunitRunBool) {
            ServiceLoader serviceLoader =
                    ServiceLoader.load(LauncherSessionListener.class);
            serviceLoader.reload();
            LoggingManager.info("Start Running Tests via JUnit 5 Runner");
        }


    }


    private static void identifyRunType() {

        Supplier> stacktraceSupplier = () -> Arrays.stream((new Throwable()).getStackTrace()).map(StackTraceElement::getClassName);
        boolean isUsingJunitDiscovery = stacktraceSupplier.get().anyMatch(org.junit.platform.launcher.core.EngineDiscoveryOrchestrator.class.getCanonicalName()::equals);
        boolean isUsingTestNG = stacktraceSupplier.get().anyMatch(TestNG.class.getCanonicalName()::equals);

        if (isUsingJunitDiscovery || isUsingTestNG) {
            isTestNGRunBool = true;

        } else {
            isJunitRunBool = true;
        }
    }


}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy