Search in sources :

Example 26 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class UpdateTestCaseExecution method updateTestCaseExecutionFromJsonArray.

/**
 * update Test case execution with testCaseJson and all the parameter belonging to it (action, control, step)
 * @param JSONObject testCaseJson
 * @param ApplicationContext appContext
 * @throws JSONException
 * @throws IOException
 * @throws CerberusException
 */
void updateTestCaseExecutionFromJsonArray(JSONObject testCaseJson, ApplicationContext appContext) throws JSONException, IOException, CerberusException {
    JSONArray stepArray = testCaseJson.getJSONArray("stepArray");
    long executionId = testCaseJson.getLong("executionId");
    ITestCaseExecutionService testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    String returnCodeOfTestCase = updateTestCaseStepExecutionFromJsonArray(stepArray, appContext);
    String returnMessage;
    if (returnCodeOfTestCase.equals("OK"))
        returnMessage = "The test case finished successfully";
    else if (returnCodeOfTestCase.equals("FA"))
        returnMessage = "The test case failed to be executed because of an action.";
    else if (returnCodeOfTestCase.equals("KO"))
        returnMessage = "The test case finished, but failed on validations.";
    else
        returnMessage = "";
    // get testCaseExecution
    TestCaseExecution executionToUpdate = testCaseExecutionService.findTCExecutionByKey(executionId);
    executionToUpdate.setControlStatus(returnCodeOfTestCase);
    executionToUpdate.setControlMessage(returnMessage);
    testCaseExecutionService.updateTCExecution(executionToUpdate);
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONArray(org.json.JSONArray) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService)

Example 27 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class RunTestCase method doGet.

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    PrintWriter out = response.getWriter();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Adding Log entry.
     */
    ILogEventService logEventService = appContext.getBean(ILogEventService.class);
    logEventService.createForPublicCalls("/RunTestCase", "CALL", "RunTestCase called : " + request.getRequestURL(), request);
    // Tool
    // Selenium IP
    String ss_ip = "";
    // Selenium Host (optional)
    String ss_ip_user = "";
    // Selenium Password (optional)
    String ss_ip_pass = "";
    // Selenium Port
    String ss_p = "";
    String browser = "";
    String robotDecli = "";
    String version = "";
    String platform = "";
    String robot = "";
    String active = "";
    String timeout = "";
    String userAgent = "";
    String screenSize = "";
    boolean synchroneous = true;
    int getPageSource = 0;
    int getSeleniumLog = 0;
    String manualExecution = "N";
    List<RobotCapability> capabilities = null;
    // Test
    String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Test"), "");
    String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("TestCase"), "");
    String country = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Country"), "");
    String environment = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Environment"), "");
    // Test Dev Environment
    boolean manualURL = ParameterParserUtil.parseBooleanParam(request.getParameter("manualURL"), false);
    String myHost = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myhost"), "");
    String myContextRoot = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("mycontextroot"), "");
    String myLoginRelativeURL = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myloginrelativeurl"), "");
    // TODO find another solution
    myLoginRelativeURL = myLoginRelativeURL.replace("&#61;", "=");
    String myEnvData = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("myenvdata"), "");
    // Execution
    String tag = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Tag"), "");
    String outputFormat = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("outputformat"), "compact");
    int screenshot = ParameterParserUtil.parseIntegerParam(request.getParameter("screenshot"), 1);
    int verbose = ParameterParserUtil.parseIntegerParam(request.getParameter("verbose"), 0);
    timeout = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("timeout"), "");
    synchroneous = ParameterParserUtil.parseBooleanParam(request.getParameter("synchroneous"), false);
    getPageSource = ParameterParserUtil.parseIntegerParam(request.getParameter("pageSource"), 1);
    getSeleniumLog = ParameterParserUtil.parseIntegerParam(request.getParameter("seleniumLog"), 1);
    manualExecution = ParameterParserUtil.parseStringParam(request.getParameter("manualExecution"), "N");
    int numberOfRetries = ParameterParserUtil.parseIntegerParam(request.getParameter("retries"), 0);
    screenSize = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("screenSize"), "");
    robot = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("robot"), "");
    ss_ip = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("ss_ip"), "");
    ss_p = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("ss_p"), "");
    browser = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("Browser"), ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("browser"), ""));
    version = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("version"), "");
    platform = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("platform"), "");
    // hidden parameters.
    long idFromQueue = ParameterParserUtil.parseIntegerParam(request.getParameter("IdFromQueue"), 0);
    String executor = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("executor"), ParameterParserUtil.parseStringParamAndSanitize(request.getRemoteUser(), null));
    String helpMessage = "\nThis servlet is used to start the execution of a test case.\n" + "Parameter list :\n" + "- Test [mandatory] : Test to execute. [" + test + "]\n" + "- TestCase [mandatory] : Test Case reference to execute. [" + testCase + "]\n" + "- Country [mandatory] : Country where the test case will execute. [" + country + "]\n" + "- Environment : Environment where the test case will execute. This parameter is mandatory only if manualURL is not set to Y. [" + environment + "]\n" + "- robot : robot name on which the test will be executed. [" + robot + "]\n" + "- ss_ip : Host of the Robot where the test will be executed. (Can be overwriten if robot is defined) [" + ss_ip + "]\n" + "- ss_p : Port of the Robot. (Can be overwriten if robot is defined) [" + ss_p + "]\n" + "- browser : Browser to use for the execution. (Can be overwriten if robot is defined) [" + browser + "]\n" + "- version : Version to use for the execution. (Can be overwriten if robot is defined) [" + version + "]\n" + "- platform : Platform to use for the execution. (Can be overwriten if robot is defined) [" + platform + "]\n" + "- screenSize : Size of the screen to set for the execution. [" + screenSize + "]\n" + "- manualURL : Activate or not the Manual URL of the application to execute. If activated the 4 parameters after (myhost, mycontextroot, myloginrelativeurl, myenvdata) are necessary. [" + manualURL + "]\n" + "- myhost : Host of the application to test (only used when manualURL is feed). [" + myHost + "]\n" + "- mycontextroot : Context root of the application to test (only used when manualURL is feed). [" + myContextRoot + "]\n" + "- myloginrelativeurl : Relative login URL of the application (only used when manualURL is feed). [" + myLoginRelativeURL + "]\n" + "- myenvdata : Environment where to get the test data when a manualURL is defined. (only used when manualURL is feed) [" + myEnvData + "]\n" + "- Tag : Tag that will be stored on the execution. [" + tag + "]\n" + "- outputformat : Format of the output of the execution. [" + outputFormat + "]\n" + "- screenshot : Activate or not the screenshots. [" + screenshot + "]\n" + "- verbose : Verbose level of the execution. [" + verbose + "]\n" + "- timeout : Timeout used for the action. If empty, the default value will be the one configured in parameter table. [" + timeout + "]\n" + "- synchroneous : Synchroneous define if the servlet wait for the end of the execution to report its execution. [" + synchroneous + "\n" + "- pageSource : Record Page Source during the execution. [" + getPageSource + "]\n" + "- seleniumLog : Get the SeleniumLog at the end of the execution. [" + getSeleniumLog + "]\n" + "- manualExecution : Execute testcase in manual mode. [" + manualExecution + "]\n" + "- retries : Number of tries if the result is not OK. [" + numberOfRetries + "]\n";
    boolean error = false;
    String errorMessage = "";
    // test, testcase and country parameters are mandatory
    if (StringUtils.isBlank(test)) {
        errorMessage += "Error - Parameter test is mandatory. ";
        error = true;
    }
    if (StringUtils.isBlank(testCase)) {
        errorMessage += "Error - Parameter testCase is mandatory. ";
        error = true;
    }
    if (!StringUtils.isBlank(tag) && tag.length() > 255) {
        errorMessage += "Error - Parameter tag value is too big. Tag cannot be larger than 255 Characters. Currently has : " + tag.length();
        error = true;
    }
    if (StringUtils.isBlank(country)) {
        errorMessage += "Error - Parameter country is mandatory. ";
        error = true;
    }
    // environment is mandatory when manualURL is not activated.
    if (StringUtils.isBlank(environment) && !manualURL) {
        errorMessage += "Error - Parameter environment is mandatory (or use the manualURL parameter). ";
        error = true;
    }
    // We check that execution is not desactivated by cerberus_automaticexecution_enable parameter.
    IParameterService parameterService = appContext.getBean(IParameterService.class);
    if (!(parameterService.getParameterBooleanByKey("cerberus_automaticexecution_enable", "", true))) {
        errorMessage += "Error - Execution disable by configuration (cerberus_automaticexecution_enable <> Y). ";
        error = true;
        LOG.info("Execution request ignored by cerberus_automaticexecution_enable parameter. " + test + " / " + testCase);
    }
    // If Robot is feeded, we check it exist. If it exist, we overwrite the associated parameters.
    if (!StringUtil.isNullOrEmpty(robot)) {
        IRobotService robotService = appContext.getBean(IRobotService.class);
        try {
            Robot robObj = robotService.readByKey(robot);
            // If Robot parameter is defined and we can find the robot, we overwrite the corresponding parameters.
            ss_ip = ParameterParserUtil.parseStringParam(robObj.getHost(), ss_ip);
            ss_ip_user = robObj.getHostUser();
            ss_ip_pass = robObj.getHostPassword();
            ss_p = ParameterParserUtil.parseStringParam(String.valueOf(robObj.getPort()), ss_p);
            browser = ParameterParserUtil.parseStringParam(robObj.getBrowser(), browser);
            robotDecli = ParameterParserUtil.parseStringParam(robObj.getRobotDecli(), "");
            if (StringUtil.isNullOrEmpty(robotDecli)) {
                robotDecli = robObj.getRobot();
            }
            version = ParameterParserUtil.parseStringParam(robObj.getVersion(), version);
            platform = ParameterParserUtil.parseStringParam(robObj.getPlatform(), platform);
            active = robObj.getActive();
            userAgent = robObj.getUserAgent();
            capabilities = robObj.getCapabilities();
            screenSize = robObj.getScreenSize();
        } catch (CerberusException ex) {
            errorMessage += "Error - Robot [" + robot + "] does not exist. ";
            error = true;
        }
    } else {
        robotDecli = browser;
    }
    // We cannot execute a testcase on a desactivated Robot.
    if (active.equals("N")) {
        errorMessage += "Error - Robot is not Active. ";
        error = true;
    }
    // verify the format of the ScreenSize. It must be 2 integer separated by a *. For example : 1024*768
    if (!"".equals(screenSize)) {
        if (!screenSize.contains("*")) {
            errorMessage += "Error - ScreenSize format is not Correct. It must be 2 Integer separated by a *. ";
            error = true;
        } else {
            try {
                String screenWidth = screenSize.split("\\*")[0];
                String screenLength = screenSize.split("\\*")[1];
                Integer.parseInt(screenWidth);
                Integer.parseInt(screenLength);
            } catch (Exception e) {
                errorMessage += "Error - ScreenSize format is not Correct. It must be 2 Integer separated by a *. ";
                error = true;
            }
        }
    }
    // check if the test case is to be executed in the specific parameters
    try {
        ITestCaseCountryService tccService = appContext.getBean(ITestCaseCountryService.class);
        TestCaseCountry tcc = tccService.findTestCaseCountryByKey(test, testCase, country);
        if (tcc == null) {
            error = true;
        }
    } catch (CerberusException ex) {
        error = true;
        errorMessage += "Error - Test Case is not selected for country. ";
    }
    // Create Tag when exist.
    if (!StringUtil.isNullOrEmpty(tag)) {
        // We create or update it.
        ITagService tagService = appContext.getBean(ITagService.class);
        tagService.createAuto(tag, "", executor);
    }
    if (!error) {
        // TODO:FN debug messages to be removed
        LOG.debug("STARTED: Test " + test + "-" + testCase);
        IRunTestCaseService runTestCaseService = appContext.getBean(IRunTestCaseService.class);
        IFactoryTestCase factoryTCase = appContext.getBean(IFactoryTestCase.class);
        IFactoryTestCaseExecution factoryTCExecution = appContext.getBean(IFactoryTestCaseExecution.class);
        IFactoryTestCaseExecutionQueue factoryTCExecutionQueue = appContext.getBean(IFactoryTestCaseExecutionQueue.class);
        ITestCaseExecutionService tces = appContext.getBean(ITestCaseExecutionService.class);
        ITestCaseService tcs = appContext.getBean(ITestCaseService.class);
        TestCase tCase = factoryTCase.create(test, testCase);
        // Building Execution Object.
        TestCaseExecution tCExecution = factoryTCExecution.create(0, test, testCase, null, null, null, environment, country, browser, version, platform, "", 0, 0, "", "", "", null, ss_ip, null, ss_p, tag, verbose, screenshot, getPageSource, getSeleniumLog, synchroneous, timeout, outputFormat, null, Infos.getInstance().getProjectNameAndVersion(), tCase, null, null, manualURL, myHost, myContextRoot, myLoginRelativeURL, myEnvData, ss_ip, ss_p, null, new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_TESTSTARTED), executor, numberOfRetries, screenSize, capabilities, "", "", "", "", "", manualExecution, userAgent, 0, "", robotDecli);
        tCExecution.setSeleniumIPUser(ss_ip_user);
        tCExecution.setSeleniumIPPassword(ss_ip_pass);
        /**
         * Set IdFromQueue
         */
        try {
            tCExecution.setQueueID(idFromQueue);
            TestCaseExecutionQueue queueExecution = factoryTCExecutionQueue.create(idFromQueue, test, testCase, country, environment, robot, ss_ip, ss_p, browser, version, platform, screenSize, 0, myHost, myContextRoot, myLoginRelativeURL, myEnvData, tag, screenshot, verbose, timeout, getPageSource, getSeleniumLog, 0, numberOfRetries, manualExecution, executor, null, null, null);
            tCExecution.setTestCaseExecutionQueue(queueExecution);
        } catch (FactoryCreationException ex) {
            LOG.error(ex);
        }
        /**
         * Set UUID
         */
        ExecutionUUID executionUUIDObject = appContext.getBean(ExecutionUUID.class);
        UUID executionUUID = UUID.randomUUID();
        executionUUIDObject.setExecutionUUID(executionUUID.toString(), tCExecution);
        tCExecution.setExecutionUUID(executionUUID.toString());
        LOG.info("Execution Requested : UUID=" + executionUUID);
        /**
         * Execution of the testcase.
         */
        LOG.debug("Start execution " + tCExecution.getId());
        tCExecution = runTestCaseService.runTestCase(tCExecution);
        /**
         * Clean memory in case testcase has not been launched(Remove all
         * object put in memory)
         */
        try {
            if (tCExecution.getId() == 0) {
                executionUUIDObject.removeExecutionUUID(tCExecution.getExecutionUUID());
                LOG.debug("Clean ExecutionUUID");
            }
        } catch (Exception ex) {
            LOG.error("Exception cleaning Memory: ", ex);
        }
        /**
         * Execution is finished we report the result.
         */
        long runID = tCExecution.getId();
        if (outputFormat.equalsIgnoreCase("gui")) {
            // HTML GUI output. either the detailed execution page or an error page when the execution is not created.
            if (runID > 0) {
                // Execution has been created.
                response.sendRedirect("TestCaseExecution.jsp?executionId=" + runID);
            } else {
                // Execution was not even created.
                response.setContentType("text/html");
                out.println("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\"><title>Test Execution Result</title></head>");
                out.println("<body>");
                out.println("<table>");
                out.println("<tr><td>RunID</td><td><span id='RunID'>" + runID + "</span></td></tr>");
                out.println("<tr><td>IdFromQueue</td><td><b><span id='IdFromQueue'>" + tCExecution.getQueueID() + "</span></b></td></tr>");
                out.println("<tr><td>Test</td><td><span id='Test'>" + test + "</span></td></tr>");
                out.println("<tr><td>TestCase</td><td><span id='TestCase'>" + testCase + "</span></td></tr>");
                out.println("<tr><td>Country</td><td><span id='Country'>" + country + "</span></td></tr>");
                out.println("<tr><td>Environment</td><td><span id='Environment'>" + environment + "</span></td></tr>");
                out.println("<tr><td>TimestampStart</td><td><span id='TimestampStart'>" + new Timestamp(tCExecution.getStart()) + "</span></td></tr>");
                out.println("<tr><td>TimestampEnd</td><td><span id='TimestampEnd'>" + new Timestamp(tCExecution.getEnd()) + "</span></td></tr>");
                out.println("<tr><td>OutputFormat</td><td><span id='OutputFormat'>" + outputFormat + "</span></td></tr>");
                out.println("<tr><td>Verbose</td><td><span id='Verbose'>" + verbose + "</span></td></tr>");
                out.println("<tr><td>Screenshot</td><td><span id='Screenshot'>" + screenshot + "</span></td></tr>");
                out.println("<tr><td>PageSource</td><td><span id='PageSource'>" + getPageSource + "</span></td></tr>");
                out.println("<tr><td>SeleniumLog</td><td><span id='SeleniumLog'>" + getSeleniumLog + "</span></td></tr>");
                out.println("<tr><td>Robot</td><td><span id='Robot'>" + robot + "</span></td></tr>");
                out.println("<tr><td>Selenium Server IP</td><td><span id='SeleniumIP'>" + ss_ip + "</span></td></tr>");
                out.println("<tr><td>Selenium Server Port</td><td><span id='SeleniumPort'>" + ss_p + "</span></td></tr>");
                out.println("<tr><td>Timeout</td><td><span id='Timeout'>" + timeout + "</span></td></tr>");
                out.println("<tr><td>Synchroneous</td><td><span id='Synchroneous'>" + synchroneous + "</span></td></tr>");
                out.println("<tr><td>Browser</td><td><span id='Browser'>" + browser + "</span></td></tr>");
                out.println("<tr><td>Version</td><td><span id='Version'>" + version + "</span></td></tr>");
                out.println("<tr><td>Platform</td><td><span id='Platform'>" + platform + "</span></td></tr>");
                out.println("<tr><td>Screen Size</td><td><span id='screenSize'>" + screenSize + "</span></td></tr>");
                out.println("<tr><td>Number of Retry</td><td><span id='nbretry'>" + numberOfRetries + "</span></td></tr>");
                out.println("<tr><td>ManualURL</td><td><span id='ManualURL'>" + tCExecution.isManualURL() + "</span></td></tr>");
                out.println("<tr><td>MyHost</td><td><span id='MyHost'>" + tCExecution.getMyHost() + "</span></td></tr>");
                out.println("<tr><td>MyContextRoot</td><td><span id='MyContextRoot'>" + tCExecution.getMyContextRoot() + "</span></td></tr>");
                out.println("<tr><td>MyLoginRelativeURL</td><td><span id='MyLoginRelativeURL'>" + tCExecution.getMyLoginRelativeURL() + "</span></td></tr>");
                out.println("<tr><td>myEnvironmentData</td><td><span id='myEnvironmentData'>" + tCExecution.getEnvironmentData() + "</span></td></tr>");
                out.println("<tr><td>ReturnCode</td><td><b><span id='ReturnCodeDescription'>" + tCExecution.getResultMessage().getCode() + "</span></b></td></tr>");
                out.println("<tr><td>ReturnCodeDescription</td><td><b><span id='ReturnCodeDescription'>" + tCExecution.getResultMessage().getDescription() + "</span></b></td></tr>");
                out.println("<tr><td>ControlStatus</td><td><b><span id='ReturnCodeMessage'>" + tCExecution.getResultMessage().getCodeString() + "</span></b></td></tr>");
                out.println("<tr><td></td><td></td></tr>");
                out.println("</table><br><br>");
                out.println("<table border>");
                out.println("<tr>" + "<td><input id=\"ButtonRetry\" type=\"button\" value=\"Retry\" onClick=\"window.location.reload()\"></td>" + "<td><input id=\"ButtonBack\" type=\"button\" value=\"Go Back\" onClick=\"window.history.back()\"></td>" + "<td><input id=\"ButtonOpenTC\" type=\"button\" value=\"Open Test Case\" onClick=\"window.open('TestCaseScript.jsp?test=" + test + "&testcase=" + testCase + "')\"></td>" + "</tr>");
                out.println("</table>");
                out.println("</body>");
                out.println("</html>");
            }
        } else if (outputFormat.equalsIgnoreCase("redirectToReport")) {
            // Redirect to the reporting page by tag.
            response.sendRedirect("./ReportingExecutionByTag.jsp?Tag=" + StringUtil.encodeAsJavaScriptURIComponent(tag));
        } else if (outputFormat.equalsIgnoreCase("verbose-txt")) {
            // Text verbose output.
            response.setContentType("text/plain");
            String separator = " = ";
            out.println("RunID" + separator + runID);
            out.println("QueueID" + separator + idFromQueue);
            out.println("Test" + separator + test);
            out.println("TestCase" + separator + testCase);
            out.println("Country" + separator + country);
            out.println("Environment" + separator + environment);
            out.println("Time Start" + separator + new Timestamp(tCExecution.getStart()));
            out.println("Time End" + separator + new Timestamp(tCExecution.getEnd()));
            out.println("OutputFormat" + separator + outputFormat);
            out.println("Verbose" + separator + verbose);
            out.println("Screenshot" + separator + screenshot);
            out.println("PageSource" + separator + getPageSource);
            out.println("SeleniumLog" + separator + getSeleniumLog);
            out.println("Robot" + separator + robot);
            out.println("Selenium Server IP" + separator + ss_ip);
            out.println("Selenium Server Port" + separator + ss_p);
            out.println("Timeout" + separator + timeout);
            out.println("Synchroneous" + separator + synchroneous);
            out.println("Browser" + separator + browser);
            out.println("Version" + separator + version);
            out.println("Platform" + separator + platform);
            out.println("ScreenSize" + separator + screenSize);
            out.println("Nb Of Retry" + separator + numberOfRetries);
            out.println("ManualURL" + separator + tCExecution.isManualURL());
            out.println("MyHost" + separator + tCExecution.getMyHost());
            out.println("MyContextRoot" + separator + tCExecution.getMyContextRoot());
            out.println("MyLoginRelativeURL" + separator + tCExecution.getMyLoginRelativeURL());
            out.println("myEnvironmentData" + separator + tCExecution.getEnvironmentData());
            out.println("ReturnCode" + separator + tCExecution.getResultMessage().getCode());
            out.println("ReturnCodeDescription" + separator + tCExecution.getResultMessage().getDescription());
            out.println("ControlStatus" + separator + tCExecution.getResultMessage().getCodeString());
        } else if (outputFormat.equalsIgnoreCase("verbose-json")) {
            // JSON verbose output.
            response.setContentType("application/json");
            TestCaseExecution t = (TestCaseExecution) tces.readByKeyWithDependency(tCExecution.getId()).getItem();
            out.print(tCExecution.toJson(true).toString());
        } else {
            // Default behaviour when not outputformat is defined : compact mode.
            response.setContentType("text/plain");
            DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);
            out.println(df.format(tCExecution.getStart()) + " - " + runID + " [" + test + "|" + testCase + "|" + country + "|" + environment + "] : '" + tCExecution.getResultMessage().getCodeString() + "' - " + tCExecution.getResultMessage().getCode() + " " + tCExecution.getResultMessage().getDescription());
        }
    } else {
        // Error occured in the servlet.
        if (outputFormat.equalsIgnoreCase("verbose-txt")) {
            // Text verbose output.
            response.setContentType("text/plain");
            String separator = " = ";
            out.println("RunID" + separator + 0);
            out.println("QueueID" + separator + idFromQueue);
            out.println("Test" + separator + test);
            out.println("TestCase" + separator + testCase);
            out.println("Country" + separator + country);
            out.println("Environment" + separator + environment);
            out.println("OutputFormat" + separator + outputFormat);
            out.println("Verbose" + separator + verbose);
            out.println("Screenshot" + separator + screenshot);
            out.println("PageSource" + separator + getPageSource);
            out.println("SeleniumLog" + separator + getSeleniumLog);
            out.println("Robot" + separator + robot);
            out.println("Selenium Server IP" + separator + ss_ip);
            out.println("Selenium Server Port" + separator + ss_p);
            out.println("Timeout" + separator + timeout);
            out.println("Synchroneous" + separator + synchroneous);
            out.println("Browser" + separator + browser);
            out.println("Version" + separator + version);
            out.println("Platform" + separator + platform);
            out.println("ScreenSize" + separator + screenSize);
            out.println("Nb Of Retry" + separator + numberOfRetries);
            out.println("ManualURL" + separator + manualURL);
            out.println("MyHost" + separator + myHost);
            out.println("MyContextRoot" + separator + myContextRoot);
            out.println("MyLoginRelativeURL" + separator + myLoginRelativeURL);
            out.println("myEnvironmentData" + separator + myEnvData);
            out.println("ReturnCode" + separator + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getCode());
            out.println("ReturnCodeDescription" + separator + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getDescription() + " " + errorMessage);
            out.println("ControlStatus" + separator + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getCodeString());
        } else {
            // In case of errors, we display the help message.
            response.setContentType("text/plain");
            DateFormat df = new SimpleDateFormat(DateUtil.DATE_FORMAT_DISPLAY);
            String errorMessageFinal = df.format(new Date()) + " - " + 0 + " [" + test + "|" + testCase + "|" + country + "|" + environment + "] : '" + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getCodeString() + "' - " + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getCode() + " " + MessageGeneralEnum.EXECUTION_FA_SERVLETVALIDATONS.getDescription() + " " + errorMessage;
            out.println(errorMessageFinal);
        }
    }
}
Also used : IParameterService(org.cerberus.crud.service.IParameterService) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) Timestamp(java.sql.Timestamp) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) FactoryCreationException(org.cerberus.exception.FactoryCreationException) ApplicationContext(org.springframework.context.ApplicationContext) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ILogEventService(org.cerberus.crud.service.ILogEventService) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) RobotCapability(org.cerberus.crud.entity.RobotCapability) UUID(java.util.UUID) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) PrintWriter(java.io.PrintWriter) CerberusException(org.cerberus.exception.CerberusException) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) IRunTestCaseService(org.cerberus.engine.execution.IRunTestCaseService) ServletException(javax.servlet.ServletException) FactoryCreationException(org.cerberus.exception.FactoryCreationException) IOException(java.io.IOException) CerberusException(org.cerberus.exception.CerberusException) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) Date(java.util.Date) IRobotService(org.cerberus.crud.service.IRobotService) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) ITagService(org.cerberus.crud.service.ITagService) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) Robot(org.cerberus.crud.entity.Robot) SimpleDateFormat(java.text.SimpleDateFormat)

Example 28 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class ReadCerberusDetailInformation method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    JSONObject jsonResponse = new JSONObject();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ExecutionUUID euuid = appContext.getBean(ExecutionUUID.class);
    SessionCounter sc = appContext.getBean(SessionCounter.class);
    Infos infos = new Infos();
    try {
        jsonResponse.put("simultaneous_execution", euuid.size());
        JSONArray executionArray = new JSONArray();
        for (Object ex : euuid.getExecutionUUIDList().values()) {
            TestCaseExecution execution = (TestCaseExecution) ex;
            JSONObject object = new JSONObject();
            object.put("id", execution.getId());
            object.put("test", execution.getTest());
            object.put("testcase", execution.getTestCase());
            object.put("system", execution.getApplicationObj().getSystem());
            object.put("application", execution.getApplication());
            object.put("environment", execution.getEnvironmentData());
            object.put("country", execution.getCountry());
            object.put("robotIP", execution.getSeleniumIP());
            object.put("tag", execution.getTag());
            object.put("start", new Timestamp(execution.getStart()));
            executionArray.put(object);
        }
        jsonResponse.put("simultaneous_execution_list", executionArray);
        jsonResponse.put("simultaneous_session", sc.getTotalActiveSession());
        jsonResponse.put("active_users", sc.getActiveUsers());
        cerberusDatabaseInformation = appContext.getBean(ICerberusInformationDAO.class);
        AnswerItem ans = cerberusDatabaseInformation.getDatabaseInformation();
        HashMap<String, String> cerberusInformation = (HashMap<String, String>) ans.getItem();
        // Database Informations.
        jsonResponse.put("DatabaseProductName", cerberusInformation.get("DatabaseProductName"));
        jsonResponse.put("DatabaseProductVersion", cerberusInformation.get("DatabaseProductVersion"));
        jsonResponse.put("DatabaseMajorVersion", cerberusInformation.get("DatabaseMajorVersion"));
        jsonResponse.put("DatabaseMinorVersion", cerberusInformation.get("DatabaseMinorVersion"));
        jsonResponse.put("DriverName", cerberusInformation.get("DriverName"));
        jsonResponse.put("DriverVersion", cerberusInformation.get("DriverVersion"));
        jsonResponse.put("DriverMajorVersion", cerberusInformation.get("DriverMajorVersion"));
        jsonResponse.put("DriverMinorVersion", cerberusInformation.get("DriverMinorVersion"));
        jsonResponse.put("JDBCMajorVersion", cerberusInformation.get("JDBCMajorVersion"));
        jsonResponse.put("JDBCMinorVersion", cerberusInformation.get("JDBCMinorVersion"));
        // Cerberus Informations.
        jsonResponse.put("projectName", infos.getProjectName());
        jsonResponse.put("projectVersion", infos.getProjectVersion());
        jsonResponse.put("environment", System.getProperty("org.cerberus.environment"));
        databaseVersionService = appContext.getBean(IDatabaseVersioningService.class);
        jsonResponse.put("databaseCerberusTargetVersion", databaseVersionService.getSQLScript().size());
        myVersionService = appContext.getBean(IMyVersionService.class);
        if (myVersionService.findMyVersionByKey("database") != null) {
            jsonResponse.put("databaseCerberusCurrentVersion", myVersionService.findMyVersionByKey("database").getValue());
        } else {
            jsonResponse.put("databaseCerberusCurrentVersion", "0");
        }
        // JAVA Informations.
        jsonResponse.put("javaVersion", System.getProperty("java.version"));
        Runtime instance = Runtime.getRuntime();
        int mb = 1024 * 1024;
        jsonResponse.put("javaFreeMemory", instance.freeMemory() / mb);
        jsonResponse.put("javaTotalMemory", instance.totalMemory() / mb);
        jsonResponse.put("javaUsedMemory", (instance.totalMemory() - instance.freeMemory()) / mb);
        jsonResponse.put("javaMaxMemory", instance.maxMemory() / mb);
        String str1 = getServletContext().getServerInfo();
        jsonResponse.put("applicationServerInfo", str1);
    } catch (JSONException ex) {
        LOG.warn(ex);
    }
    response.setContentType("application/json");
    response.getWriter().print(jsonResponse.toString());
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) HashMap(java.util.HashMap) SessionCounter(org.cerberus.crud.entity.SessionCounter) ExecutionUUID(org.cerberus.engine.entity.ExecutionUUID) ICerberusInformationDAO(org.cerberus.database.dao.ICerberusInformationDAO) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IMyVersionService(org.cerberus.crud.service.IMyVersionService) Timestamp(java.sql.Timestamp) AnswerItem(org.cerberus.util.answer.AnswerItem) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) JSONObject(org.json.JSONObject) IDatabaseVersioningService(org.cerberus.database.IDatabaseVersioningService) Infos(org.cerberus.version.Infos)

Example 29 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class FactoryTestCaseExecution method create.

@Override
public TestCaseExecution create(long id, String test, String testCase, String description, String build, String revision, String environment, String country, String browser, String version, String platform, String browserFullVersion, long start, long end, String controlStatus, String controlMessage, String application, Application applicationObj, String ip, String url, String port, String tag, int verbose, int screenshot, int pageSource, int seleniumLog, boolean synchroneous, String timeout, String outputFormat, String status, String crbVersion, TestCase tCase, CountryEnvParam countryEnvParam, CountryEnvironmentParameters countryEnvironmentParameters, boolean manualURL, String myHost, String myContextRoot, String myLoginRelativeURL, String myEnvData, String seleniumIP, String seleniumPort, List<TestCaseStepExecution> testCaseStepExecution, MessageGeneral resultMessage, String executor, int numberOfRetries, String screenSize, List<RobotCapability> capabilities, String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String manualExecution, String userAgent, int testCaseVersion, String system, String robotDecli) {
    TestCaseExecution newTce = new TestCaseExecution();
    newTce.setApplicationObj(applicationObj);
    newTce.setApplication(application);
    newTce.setBrowser(browser);
    newTce.setVersion(version);
    newTce.setPlatform(platform);
    newTce.setBrowserFullVersion(browserFullVersion);
    newTce.setBuild(build);
    newTce.setControlMessage(controlMessage);
    newTce.setControlStatus(controlStatus);
    newTce.setCountry(country);
    newTce.setCrbVersion(crbVersion);
    newTce.setEnd(end);
    newTce.setEnvironment(environment);
    newTce.setEnvironmentData(myEnvData);
    newTce.setId(id);
    newTce.setIp(ip);
    newTce.setPort(port);
    newTce.setRevision(revision);
    newTce.setStart(start);
    newTce.setStatus(status);
    newTce.setTag(tag);
    newTce.setTest(test);
    newTce.setTestCase(testCase);
    newTce.setUrl(url);
    newTce.setVerbose(verbose);
    newTce.setScreenshot(screenshot);
    newTce.setTestCaseObj(tCase);
    newTce.setCountryEnvParam(countryEnvParam);
    newTce.setCountryEnvironmentParameters(countryEnvironmentParameters);
    newTce.setManualURL(manualURL);
    newTce.setMyHost(myHost);
    newTce.setMyContextRoot(myContextRoot);
    newTce.setMyLoginRelativeURL(myLoginRelativeURL);
    newTce.setSeleniumIP(seleniumIP);
    newTce.setSeleniumPort(seleniumPort);
    if (testCaseStepExecution == null) {
        testCaseStepExecution = new ArrayList<>();
    }
    newTce.setTestCaseStepExecutionList(testCaseStepExecution);
    newTce.setResultMessage(resultMessage);
    newTce.setOutputFormat(outputFormat);
    newTce.setTimeout(timeout);
    newTce.setSynchroneous(synchroneous);
    newTce.setPageSource(pageSource);
    newTce.setSeleniumLog(seleniumLog);
    newTce.setExecutor(executor);
    newTce.setNumberOfRetries(numberOfRetries);
    newTce.setScreenSize(screenSize);
    newTce.setCapabilities(capabilities);
    newTce.setLastWebsocketPush(0);
    newTce.setConditionOper(conditionOper);
    newTce.setConditionVal1(conditionVal1);
    newTce.setConditionVal1Init(conditionVal1Init);
    newTce.setConditionVal2(conditionVal2);
    newTce.setConditionVal2Init(conditionVal2Init);
    newTce.setManualExecution(manualExecution);
    newTce.setUserAgent(userAgent);
    newTce.setDescription(description);
    newTce.setRobotDecli(robotDecli);
    newTce.setSystem(system);
    // List objects
    List<TestCaseExecutionFile> objectFileList = new ArrayList<>();
    newTce.setFileList(objectFileList);
    TreeMap<String, TestCaseExecutionData> hashTemp1 = new TreeMap<>();
    newTce.setTestCaseExecutionDataMap(hashTemp1);
    newTce.setNbExecutions(1);
    newTce.setTestCaseVersion(testCaseVersion);
    return newTce;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) IFactoryTestCaseExecution(org.cerberus.crud.factory.IFactoryTestCaseExecution) TestCaseExecutionData(org.cerberus.crud.entity.TestCaseExecutionData) ArrayList(java.util.ArrayList) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) TreeMap(java.util.TreeMap)

Example 30 with TestCaseExecution

use of org.cerberus.crud.entity.TestCaseExecution in project cerberus-source by cerberustesting.

the class ActionService method doAction.

@Override
public TestCaseStepActionExecution doAction(TestCaseStepActionExecution testCaseStepActionExecution) {
    MessageEvent res;
    TestCaseExecution tCExecution = testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution();
    AnswerItem<String> answerDecode = new AnswerItem();
    /**
     * Decode the object field before doing the action.
     */
    try {
        // When starting a new action, we reset the property list that was already calculated.
        tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
        answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue1(), tCExecution, testCaseStepActionExecution, false);
        testCaseStepActionExecution.setValue1((String) answerDecode.getItem());
        if (!(answerDecode.isCodeStringEquals("OK"))) {
            // If anything wrong with the decode --> we stop here with decode message in the action result.
            testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value1"));
            testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
            testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
            testCaseStepActionExecution.setEnd(new Date().getTime());
            LOG.debug("Action interupted due to decode 'Action Value1' Error.");
            return testCaseStepActionExecution;
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());
        testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        testCaseStepActionExecution.setEnd(new Date().getTime());
        return testCaseStepActionExecution;
    }
    try {
        // When starting a new action, we reset the property list that was already calculated.
        tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
        answerDecode = variableService.decodeStringCompletly(testCaseStepActionExecution.getValue2(), tCExecution, testCaseStepActionExecution, false);
        testCaseStepActionExecution.setValue2((String) answerDecode.getItem());
        if (!(answerDecode.isCodeStringEquals("OK"))) {
            // If anything wrong with the decode --> we stop here with decode message in the action result.
            testCaseStepActionExecution.setActionResultMessage(answerDecode.getResultMessage().resolveDescription("FIELD", "Action Value2"));
            testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(answerDecode.getResultMessage().getMessage()));
            testCaseStepActionExecution.setStopExecution(answerDecode.getResultMessage().isStopTest());
            testCaseStepActionExecution.setEnd(new Date().getTime());
            LOG.debug("Action interupted due to decode 'Action Value2' Error.");
            return testCaseStepActionExecution;
        }
    } catch (CerberusEventException cex) {
        testCaseStepActionExecution.setActionResultMessage(cex.getMessageError());
        testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(cex.getMessageError().getMessage()));
        testCaseStepActionExecution.setEnd(new Date().getTime());
        return testCaseStepActionExecution;
    }
    /**
     * Timestamp starts after the decode. TODO protect when property is
     * null.
     */
    testCaseStepActionExecution.setStart(new Date().getTime());
    String value1 = testCaseStepActionExecution.getValue1();
    String value2 = testCaseStepActionExecution.getValue2();
    String propertyName = testCaseStepActionExecution.getPropertyName();
    LOG.debug("Doing Action : " + testCaseStepActionExecution.getAction() + " with value1 : " + value1 + " and value2 : " + value2);
    // When starting a new action, we reset the property list that was already calculated.
    tCExecution.setRecursiveAlreadyCalculatedPropertiesList(new ArrayList());
    try {
        switch(testCaseStepActionExecution.getAction()) {
            case TestCaseStepAction.ACTION_CLICK:
                res = this.doActionClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSELEFTBUTTONPRESS:
                res = this.doActionMouseLeftButtonPress(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSELEFTBUTTONRELEASE:
                res = this.doActionMouseLeftButtonRelease(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_DOUBLECLICK:
                res = this.doActionDoubleClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_RIGHTCLICK:
                res = this.doActionRightClick(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MOUSEOVER:
                res = this.doActionMouseOver(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_FOCUSTOIFRAME:
                res = this.doActionFocusToIframe(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_FOCUSDEFAULTIFRAME:
                res = this.doActionFocusDefaultIframe(tCExecution);
                break;
            case TestCaseStepAction.ACTION_SWITCHTOWINDOW:
                res = this.doActionSwitchToWindow(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_MANAGEDIALOG:
                res = this.doActionManageDialog(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_OPENURLWITHBASE:
                res = this.doActionOpenURL(tCExecution, value1, value2, true);
                break;
            case TestCaseStepAction.ACTION_OPENURLLOGIN:
                testCaseStepActionExecution.setValue1(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getCountryEnvironmentParameters().getUrlLogin());
                res = this.doActionUrlLogin(tCExecution);
                break;
            case TestCaseStepAction.ACTION_OPENURL:
                res = this.doActionOpenURL(tCExecution, value1, value2, false);
                break;
            case TestCaseStepAction.ACTION_EXECUTEJS:
                res = this.doActionExecuteJS(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_OPENAPP:
                res = this.doActionOpenApp(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_CLOSEAPP:
                res = this.doActionCloseApp(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_SELECT:
                res = this.doActionSelect(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_KEYPRESS:
                res = this.doActionKeyPress(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_TYPE:
                res = this.doActionType(tCExecution, value1, value2, propertyName);
                break;
            case TestCaseStepAction.ACTION_HIDEKEYBOARD:
                res = this.doActionHideKeyboard(tCExecution);
                break;
            case TestCaseStepAction.ACTION_SWIPE:
                res = this.doActionSwipe(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_WAIT:
                res = this.doActionWait(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_WAITVANISH:
                res = this.doActionWaitVanish(tCExecution, value1);
                break;
            case TestCaseStepAction.ACTION_CALLSERVICE:
                res = this.doActionCallService(testCaseStepActionExecution, value1);
                break;
            case TestCaseStepAction.ACTION_EXECUTESQLUPDATE:
                res = this.doActionExecuteSQLUpdate(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_EXECUTESQLSTOREPROCEDURE:
                res = this.doActionExecuteSQLStoredProcedure(tCExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_CALCULATEPROPERTY:
                res = this.doActionCalculateProperty(testCaseStepActionExecution, value1, value2);
                break;
            case TestCaseStepAction.ACTION_DONOTHING:
                res = new MessageEvent(MessageEventEnum.ACTION_SUCCESS);
                break;
            // DEPRECATED ACTIONS FROM HERE.
            case TestCaseStepAction.ACTION_MOUSEOVERANDWAIT:
                res = this.doActionMouseOverAndWait(tCExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "mouseOverAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action mouseOverAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_REMOVEDIFFERENCE:
                res = this.doActionRemoveDifference(testCaseStepActionExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "removeDifference", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action removeDifference triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_GETPAGESOURCE:
                res = this.doActionGetPageSource(testCaseStepActionExecution);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "getPageSource", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action getPageSource triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_TAKESCREENSHOT:
                res = this.doActionTakeScreenshot(testCaseStepActionExecution);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "takeScreenshot", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action takeScreenshot triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_CLICKANDWAIT:
                res = this.doActionClickWait(tCExecution, value1, value2);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "clickAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action clickAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_ENTER:
                res = this.doActionKeyPress(tCExecution, value1, "RETURN");
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "enter", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action enter triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            case TestCaseStepAction.ACTION_SELECTANDWAIT:
                res = this.doActionSelect(tCExecution, value1, value2);
                this.doActionWait(tCExecution, StringUtil.NULL, StringUtil.NULL);
                res.setDescription(MESSAGE_DEPRECATED + " " + res.getDescription());
                logEventService.createForPrivateCalls("ENGINE", "selectAndWait", MESSAGE_DEPRECATED + " Deprecated Action triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "|" + testCaseStepActionExecution.getTestCase() + "']");
                LOG.warn(MESSAGE_DEPRECATED + " Deprecated Action selectAndWait triggered by TestCase : ['" + testCaseStepActionExecution.getTest() + "'|'" + testCaseStepActionExecution.getTestCase() + "']");
                break;
            default:
                res = new MessageEvent(MessageEventEnum.ACTION_FAILED_UNKNOWNACTION);
                res.setDescription(res.getDescription().replace("%ACTION%", testCaseStepActionExecution.getAction()));
        }
    } catch (final Exception unexpected) {
        LOG.error("Unexpected exception: " + unexpected.getMessage(), unexpected);
        res = new MessageEvent(MessageEventEnum.ACTION_FAILED_GENERIC).resolveDescription("DETAIL", unexpected.getMessage());
    }
    LOG.debug("Result of the action : " + res.getCodeString() + " " + res.getDescription());
    /**
     * In case 1/ the action is flaged as being Forced with a specific
     * return code = PE and 2/ the return of the action is stoping the test
     * --> whatever the return of the action is, we force the return to move
     * forward the test with no screenshot, pagesource.
     */
    if (testCaseStepActionExecution.getForceExeStatus().equals("PE") && res.isStopTest()) {
        res.setDescription(res.getDescription() + " -- Execution forced to continue.");
        res.setDoScreenshot(false);
        res.setGetPageSource(false);
        res.setStopTest(false);
        res.setMessage(MessageGeneralEnum.EXECUTION_PE_TESTEXECUTING);
    }
    testCaseStepActionExecution.setActionResultMessage(res);
    /**
     * Determine here the impact of the Action on the full test return code
     * from the ResultMessage of the Action.
     */
    testCaseStepActionExecution.setExecutionResultMessage(new MessageGeneral(res.getMessage()));
    /**
     * Determine here if we stop the test from the ResultMessage of the
     * Action.
     */
    testCaseStepActionExecution.setStopExecution(res.isStopTest());
    testCaseStepActionExecution.setEnd(new Date().getTime());
    return testCaseStepActionExecution;
}
Also used : CerberusEventException(org.cerberus.exception.CerberusEventException) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date) CerberusEventException(org.cerberus.exception.CerberusEventException) CerberusException(org.cerberus.exception.CerberusException)

Aggregations

TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)55 ArrayList (java.util.ArrayList)24 IFactoryTestCaseExecution (org.cerberus.crud.factory.IFactoryTestCaseExecution)20 MessageEvent (org.cerberus.engine.entity.MessageEvent)19 JSONObject (org.json.JSONObject)17 AnswerItem (org.cerberus.util.answer.AnswerItem)15 AnswerList (org.cerberus.util.answer.AnswerList)14 Connection (java.sql.Connection)13 PreparedStatement (java.sql.PreparedStatement)13 ResultSet (java.sql.ResultSet)13 SQLException (java.sql.SQLException)13 LinkedHashMap (java.util.LinkedHashMap)13 ITestCaseExecutionService (org.cerberus.crud.service.ITestCaseExecutionService)12 CerberusException (org.cerberus.exception.CerberusException)11 List (java.util.List)10 HashMap (java.util.HashMap)9 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)9 JSONArray (org.json.JSONArray)9 JSONException (org.json.JSONException)9 ApplicationContext (org.springframework.context.ApplicationContext)9