Search in sources :

Example 6 with ScenarioException

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");
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Base64OutputStream(org.apache.commons.codec.binary.Base64OutputStream) BufferedImage(java.awt.image.BufferedImage) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 7 with ScenarioException

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()));
        }
    }
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 8 with ScenarioException

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));
    }
}
Also used : JSONObject(kong.unirest.json.JSONObject) UnirestException(kong.unirest.UnirestException) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 9 with ScenarioException

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;
}
Also used : TestStep(com.seleniumtests.reporter.logger.TestStep) BrowserInfo(com.seleniumtests.browserfactory.BrowserInfo) ArrayList(java.util.ArrayList) VideoRecorder(com.seleniumtests.util.video.VideoRecorder) Date(java.util.Date) MutableCapabilities(org.openqa.selenium.MutableCapabilities) File(java.io.File) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Example 10 with ScenarioException

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);
}
Also used : SeleniumRobotVariableServerConnector(com.seleniumtests.connectors.selenium.SeleniumRobotVariableServerConnector) ScenarioException(com.seleniumtests.customexception.ScenarioException)

Aggregations

ScenarioException (com.seleniumtests.customexception.ScenarioException)68 ArrayList (java.util.ArrayList)17 WebElement (org.openqa.selenium.WebElement)14 UnirestException (kong.unirest.UnirestException)13 GenericPictureElement (com.seleniumtests.uipage.htmlelements.GenericPictureElement)12 IOException (java.io.IOException)12 JSONObject (kong.unirest.json.JSONObject)12 CheckBoxElement (com.seleniumtests.uipage.htmlelements.CheckBoxElement)11 Element (com.seleniumtests.uipage.htmlelements.Element)11 HtmlElement (com.seleniumtests.uipage.htmlelements.HtmlElement)11 LinkElement (com.seleniumtests.uipage.htmlelements.LinkElement)11 RadioButtonElement (com.seleniumtests.uipage.htmlelements.RadioButtonElement)11 File (java.io.File)10 List (java.util.List)9 HashMap (java.util.HashMap)8 ConfigurationException (com.seleniumtests.customexception.ConfigurationException)7 AWTException (java.awt.AWTException)7 Robot (java.awt.Robot)6 Map (java.util.Map)5 TestStep (com.seleniumtests.reporter.logger.TestStep)4