use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class CustomEventFiringWebDriver method captureDesktopToBase64String.
/**
* Returns a Base64 string of the desktop
* @param onlyMainScreen if true, only capture the default (or main) screen
* @param driverMode
* @param gridConnector
* @return
*/
public static String captureDesktopToBase64String(boolean onlyMainScreen, DriverMode driverMode, SeleniumGridConnector gridConnector) {
if (driverMode == DriverMode.LOCAL) {
BufferedImage bi;
if (onlyMainScreen) {
bi = captureMainDesktopScreenToBuffer();
} else {
bi = captureDesktopToBuffer();
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
OutputStream b64 = new Base64OutputStream(os);
try {
ImageIO.write(bi, "png", b64);
return os.toString("UTF-8");
} catch (IOException e) {
return "";
}
} else if (driverMode == DriverMode.GRID && gridConnector != null) {
return gridConnector.captureDesktopToBuffer();
} else {
throw new ScenarioException("driver supports captureDesktopToBase64String only in local and grid mode");
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class SeleniumRobotTestPlan method executeUftScript.
/**
* Execute a UFT script locally or remotely via a VBS script called through csscript.exe
* @param args parameters to give to UFT script
* @param timeout timeout in seconds. Max time the script will run
*/
public void executeUftScript(Uft uft, int timeout, Map<String, String> args) {
TestTasks.terminateCurrentStep();
List<TestStep> uftSteps = uft.executeScript(timeout, args);
for (TestStep uftStep : uftSteps) {
TestStepManager.setCurrentRootTestStep(uftStep);
TestStepManager.logTestStep(TestStepManager.getCurrentRootTestStep());
if (Boolean.TRUE.equals(uftStep.getFailed())) {
throw new ScenarioException(String.format("UFT execution failed on script %s", uft.getScriptPath()));
}
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class TestPlanItemExecution method setResult.
public void setResult(ExecutionStatus result) {
JSONObject body = new JSONObject();
body.put("_type", "execution");
body.put("execution_status", result.toString());
try {
getJSonResponse(buildPatchRequest(url).body(body));
} catch (UnirestException e) {
throw new ScenarioException(String.format("Cannot set result for execution %d", id));
}
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class WebUIDriver method createRemoteWebDriver.
/**
* prepare driver:
* - create it
* - add listeners
* - create and start video capture
* - create and start network capture proxy
* - record driver and browser pid so that they can be deleted at the end of test session
* @return
*/
public WebDriver createRemoteWebDriver() {
webDriverBuilder = getWebDriverBuilderFactory();
logger.info("driver mode: " + config.getMode());
synchronized (createDriverLock) {
// get browser info used to start this driver. It will be used then for managing pids
BrowserInfo browserInfo = webDriverBuilder.getSelectedBrowserInfo();
List<Long> existingPids = new ArrayList<>();
// get pid pre-existing the creation of this driver. This helps filtering drivers launched by other tests or users
if (browserInfo != null) {
existingPids.addAll(browserInfo.getDriverAndBrowserPid(new ArrayList<>()));
}
TestStep cuurrentTestStep = TestStepManager.getCurrentRootTestStep();
long start = new Date().getTime();
long duration;
try {
driver = webDriverBuilder.createWebDriver();
} finally {
duration = new Date().getTime() - start;
if (cuurrentTestStep != null) {
cuurrentTestStep.setDurationToExclude(duration);
}
scenarioLogger.info(String.format("driver creation took: %.1f secs", duration / 1000.0));
}
WaitHelper.waitForSeconds(2);
List<Long> driverPids = new ArrayList<>();
// get the created PIDs
if (browserInfo != null) {
driverPids = browserInfo.getDriverAndBrowserPid(existingPids);
}
// issue #280: we use 'webDriverBuilder.getSelectedBrowserInfo()' as 'browserInfo' variable is null for grid, whereas, 'webDriverBuilder.getSelectedBrowserInfo()'
// gets an updated version once the driver has been created on grid
driver = handleListeners(driver, webDriverBuilder.getSelectedBrowserInfo(), driverPids);
if (driver != null) {
MutableCapabilities caps = ((CustomEventFiringWebDriver) driver).getInternalCapabilities();
caps.setCapability(DriverUsage.STARTUP_DURATION, duration);
caps.setCapability(DriverUsage.START_TIME, start);
// capability from IDestkopCapabilitiesFactory is not available when we request capabilities from driver.
if (config.getTestContext() != null && config.getTestContext().getTestNGResult() != null) {
String testName = TestNGResultUtils.getTestName(config.getTestContext().getTestNGResult());
caps.setCapability(DriverUsage.TEST_NAME, testName);
}
}
if (config.getBrowserMobProxy() != null) {
config.getBrowserMobProxy().newHar(SeleniumTestsContextManager.getThreadContext().getRelativeOutputDir());
}
if (config.getVideoCapture() != VideoCaptureMode.FALSE && videoRecorder.get() == null) {
try {
VideoRecorder recorder = CustomEventFiringWebDriver.startVideoCapture(SeleniumTestsContextManager.getThreadContext().getRunMode(), SeleniumTestsContextManager.getThreadContext().getSeleniumGridConnector(), new File(SeleniumTestsContextManager.getThreadContext().getOutputDirectory()), "videoCapture.avi");
videoRecorder.set(recorder);
TestStepManager.setVideoStartDate();
} catch (ScenarioException e) {
logger.warn("Video capture won't start: " + e.getMessage());
}
}
}
return driver;
}
use of com.seleniumtests.customexception.ScenarioException in project seleniumRobot by bhecquet.
the class TestTasks method createOrUpdateParam.
/**
* Method for creating or updating a variable. If variables are get from seleniumRobot server, this method will update the value on the server
* Moreover, created custom variable is specific to tuple (application, version, test environment)
* @param key name of the param
* @param newValue value of the parameter (or new value if we update it)
* @param specificToVersion if true, this param will be stored on server with a reference to the application version. This will have no effect if changing a
* current variable.
* @param timeToLive if > 0, this variable will be destroyed after some days (defined by variable). A positive value is mandatory if reservable is set to true
* because multiple variable can be created
* @param reservable if true, this variable will be set as reservable in variable server. This means it can be used by only one test at the same time
* True value also means that multiple variables of the same name can be created and a timeToLive > 0 MUST be provided so that server database is regularly purged
* @param localUpdateOnly it true, value won't be set on remote server
*/
public static void createOrUpdateParam(String key, String newValue, boolean specificToVersion, int timeToLive, boolean reservable, boolean localUpdateOnly) {
SeleniumRobotVariableServerConnector variableServer = SeleniumTestsContextManager.getThreadContext().getVariableServer();
if (reservable && timeToLive <= 0) {
throw new ScenarioException("When creating a variable as reservable, a positive timeToLive value MUST be provided");
}
// check if we update an existing variable
TestVariable variable = SeleniumTestsContextManager.getThreadContext().getConfiguration().get(key);
if (variable == null || reservable) {
variable = new TestVariable(key, newValue);
} else {
variable.setValue(newValue);
}
variable.setReservable(reservable);
variable.setTimeToLive(timeToLive);
if (variableServer != null && !localUpdateOnly) {
variable = variableServer.upsertVariable(variable, specificToVersion);
}
SeleniumTestsContextManager.getThreadContext().getConfiguration().put(variable.getName(), variable);
}
Aggregations