Search in sources :

Example 46 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumTestsContext method setReporterPluginClasses.

public void setReporterPluginClasses(String classNames) {
    if (classNames != null) {
        List<Class<IReporter>> reporterClasses = new ArrayList<>();
        for (String className : classNames.split(",")) {
            try {
                Class<IReporter> clazz = (Class<IReporter>) Class.forName(className);
                if (!IReporter.class.isAssignableFrom(clazz)) {
                    throw new ClassCastException();
                }
                reporterClasses.add(clazz);
            } catch (ClassNotFoundException e) {
                throw new ConfigurationException(String.format("Class %s cannot be loaded: %s", className, e.getMessage()));
            } catch (ClassCastException e) {
                throw new ConfigurationException(String.format("Class %s does not implement IReporter interface", className));
            }
        }
        setAttribute(REPORTER_PLUGIN_CLASSES, reporterClasses);
    } else {
        setAttribute(REPORTER_PLUGIN_CLASSES, new ArrayList<>());
    }
}
Also used : IReporter(org.testng.IReporter) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ArrayList(java.util.ArrayList)

Example 47 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumTestsContext method setWebDriverListener.

public void setWebDriverListener(String listener) {
    List<String> listeners = new ArrayList<>();
    listeners.add(DriverExceptionListener.class.getName());
    if (listener != null && !listener.isEmpty()) {
        for (String listenerClassName : listener.split(",")) {
            // check we can access the class
            try {
                Class<WebDriverEventListener> listenerClass = (Class<WebDriverEventListener>) Class.forName(listenerClassName);
                if (!WebDriverEventListener.class.isAssignableFrom(listenerClass)) {
                    throw new ConfigurationException(String.format("Class %s must implement WebDriverEventListener class", listenerClassName));
                }
                listeners.add(listenerClassName);
            } catch (ExceptionInInitializerError | ClassNotFoundException e) {
                throw new ConfigurationException(String.format("Class %s cannot be loaded", listenerClassName), e);
            }
        }
    }
    setAttribute(WEB_DRIVER_LISTENER, listeners);
}
Also used : DriverExceptionListener(com.seleniumtests.driver.DriverExceptionListener) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ArrayList(java.util.ArrayList) WebDriverEventListener(org.openqa.selenium.support.events.WebDriverEventListener)

Example 48 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumTestsContext method setCapabilities.

public void setCapabilities(String capabilities) {
    MutableCapabilities caps = new MutableCapabilities();
    if (capabilities != null) {
        for (String cap : capabilities.split(",")) {
            String[] keyValue = cap.split("=", 2);
            if (keyValue.length != 2) {
                throw new ConfigurationException("format of capability is '<key>=<value>'");
            }
            caps.setCapability(keyValue[0], keyValue[1]);
        }
    }
    setAttribute(CAPABILITIES, caps);
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) MutableCapabilities(org.openqa.selenium.MutableCapabilities)

Example 49 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class SeleniumTestsContextManager method setThreadContextFromTestResult.

/**
 * get SR context stored in test result if it exists. Else, create a new one (happens when a test method has been skipped for example)
 * called from reporters only
 * @param testNGCtx
 * @param testName
 * @param testResult
 */
public static SeleniumTestsContext setThreadContextFromTestResult(ITestContext testNGCtx, ITestResult testResult) {
    if (testResult == null) {
        throw new ConfigurationException("Cannot set context from testResult as it is null");
    }
    if (TestNGResultUtils.getSeleniumRobotTestContext(testResult) != null) {
        return TestNGResultUtils.getSeleniumRobotTestContext(testResult);
    } else {
        logger.error("Result did not contain thread context, initializing a new one");
        ITestContext newTestNGCtx = getContextFromConfigFile(testNGCtx);
        SeleniumTestsContext seleniumTestsCtx = new SeleniumTestsContext(newTestNGCtx);
        seleniumTestsCtx.configureContext(testResult);
        TestNGResultUtils.setSeleniumRobotTestContext(testResult, seleniumTestsCtx);
        return seleniumTestsCtx;
    }
}
Also used : ConfigurationException(com.seleniumtests.customexception.ConfigurationException) ITestContext(org.testng.ITestContext)

Example 50 with ConfigurationException

use of com.seleniumtests.customexception.ConfigurationException in project seleniumRobot by bhecquet.

the class TestTasks method addStep.

/**
 * Add step to test and add snapshot to it
 * If a previous step exists, store it
 * @param stepName			name of the step
 * 							If name is null, only previous step is stored, no new step is created
 * @param passwordsToMask	array of strings that must be replaced by '*****' in reports
 */
public static void addStep(String stepName, String... passwordsToMask) {
    if (!SeleniumTestsContextManager.getThreadContext().isManualTestSteps()) {
        throw new ConfigurationException("manual steps can only be used when automatic steps are disabled ('manualTestSteps' option set to true)");
    }
    NLWebDriver neoloadDriver = WebUIDriver.getNeoloadDriver();
    // log the previous step if it exists and create the new one
    terminateCurrentStep();
    // stepName is null when test is terminating. We don't create a new step
    if (stepName != null) {
        TestStep step = new TestStep(stepName, Reporter.getCurrentTestResult(), Arrays.asList(passwordsToMask), SeleniumTestsContextManager.getThreadContext().getMaskedPassword());
        TestStepManager.setCurrentRootTestStep(step);
        capturePageSnapshot();
        // start a new page when using BrowserMobProxy (network capture)
        BrowserMobProxy mobProxy = WebUIDriver.getBrowserMobProxy();
        if (mobProxy != null) {
            mobProxy.newPage(stepName);
        }
        // start a new transaction when using Neoload
        if (neoloadDriver != null) {
            neoloadDriver.startTransaction(stepName);
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ConfigurationException(com.seleniumtests.customexception.ConfigurationException) NLWebDriver(com.neotys.selenium.proxies.NLWebDriver) BrowserMobProxy(net.lightbody.bmp.BrowserMobProxy)

Aggregations

ConfigurationException (com.seleniumtests.customexception.ConfigurationException)66 ArrayList (java.util.ArrayList)19 File (java.io.File)18 IOException (java.io.IOException)14 HashMap (java.util.HashMap)13 Test (org.testng.annotations.Test)13 Matcher (java.util.regex.Matcher)9 List (java.util.List)8 UnirestException (kong.unirest.UnirestException)8 GenericTest (com.seleniumtests.GenericTest)7 SeleniumRobotServerException (com.seleniumtests.customexception.SeleniumRobotServerException)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 ScenarioException (com.seleniumtests.customexception.ScenarioException)5 BrowserType (com.seleniumtests.driver.BrowserType)5 Map (java.util.Map)5 Pattern (java.util.regex.Pattern)5 Collectors (java.util.stream.Collectors)5 Win32Exception (com.sun.jna.platform.win32.Win32Exception)4 StandardCharsets (java.nio.charset.StandardCharsets)4 Files (java.nio.file.Files)4