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<>());
}
}
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);
}
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);
}
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;
}
}
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);
}
}
}
Aggregations