Search in sources :

Example 11 with TestCaseExecutionFile

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

the class RecorderService method recordTestDataLibProperty.

@Override
public TestCaseExecutionFile recordTestDataLibProperty(Long runId, String property, int propertyIndex, List<HashMap<String, String>> result) {
    TestCaseExecutionFile object = null;
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    try {
        JSONArray jsonResult = null;
        jsonResult = dataLibService.convertToJSONObject(result);
        // RESULT.
        Recorder recorder = this.initFilenames(runId, null, null, null, null, null, null, property, propertyIndex, "result", "json", false);
        recordFile(recorder.getFullPath(), recorder.getFileName(), jsonResult.toString());
        // Index file created to database.
        object = testCaseExecutionFileFactory.create(0, runId, recorder.getLevel(), "Result", recorder.getRelativeFilenameURL(), "JSON", "", null, "", null);
        testCaseExecutionFileService.save(object);
    } catch (CerberusException | JSONException ex) {
        LOG.error(logPrefix + "TestDataLib file was not saved due to unexpected error." + ex.toString());
    }
    return object;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) JSONArray(org.json.JSONArray) Recorder(org.cerberus.engine.entity.Recorder) JSONException(org.json.JSONException) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 12 with TestCaseExecutionFile

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

the class RecorderService method recordPageSource.

@Override
public TestCaseExecutionFile recordPageSource(TestCaseExecution testCaseExecution, TestCaseStepActionExecution testCaseStepActionExecution, Integer control) {
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    LOG.debug(logPrefix + "Starting to save Page Source File.");
    TestCaseExecutionFile object = null;
    String test = testCaseExecution.getTest();
    String testCase = testCaseExecution.getTestCase();
    String step = String.valueOf(testCaseStepActionExecution.getStep());
    String index = String.valueOf(testCaseStepActionExecution.getIndex());
    String sequence = String.valueOf(testCaseStepActionExecution.getSequence());
    String controlString = control.equals(0) ? null : String.valueOf(control);
    try {
        Recorder recorder = this.initFilenames(testCaseStepActionExecution.getTestCaseStepExecution().gettCExecution().getId(), test, testCase, step, index, sequence, controlString, null, 0, "pagesource", "html", false);
        File dir = new File(recorder.getFullPath());
        dir.mkdirs();
        File file = new File(recorder.getFullFilename());
        try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
            fileOutputStream.write(this.webdriverService.getPageSource(testCaseExecution.getSession()).getBytes());
            fileOutputStream.close();
            // Index file created to database.
            object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Page Source", recorder.getRelativeFilenameURL(), "HTML", "", null, "", null);
            testCaseExecutionFileService.save(object);
        } catch (FileNotFoundException ex) {
            LOG.error(logPrefix + ex.toString());
        } catch (IOException ex) {
            LOG.error(logPrefix + ex.toString());
        }
        LOG.debug(logPrefix + "Page Source file saved in : " + recorder.getRelativeFilenameURL());
    } catch (CerberusException ex) {
        LOG.error(logPrefix + ex.toString());
    }
    return object;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Recorder(org.cerberus.engine.entity.Recorder) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) IOException(java.io.IOException) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) File(java.io.File) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 13 with TestCaseExecutionFile

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

the class RecorderService method recordSeleniumLog.

@Override
public TestCaseExecutionFile recordSeleniumLog(TestCaseExecution testCaseExecution) {
    TestCaseExecutionFile object = null;
    // Used for logging purposes
    String logPrefix = Infos.getInstance().getProjectNameAndVersion() + " - ";
    if (testCaseExecution.getApplicationObj().getType().equals(Application.TYPE_GUI)) {
        if (testCaseExecution.getSeleniumLog() == 2 || (testCaseExecution.getSeleniumLog() == 1 && !testCaseExecution.getControlStatus().equals("OK"))) {
            LOG.debug(logPrefix + "Starting to save Selenium log file.");
            try {
                Recorder recorder = this.initFilenames(testCaseExecution.getId(), null, null, null, null, null, null, null, 0, "selenium_log", "txt", false);
                File dir = new File(recorder.getFullPath());
                dir.mkdirs();
                File file = new File(recorder.getFullFilename());
                try (FileOutputStream fileOutputStream = new FileOutputStream(file)) {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    DataOutputStream out = new DataOutputStream(baos);
                    for (String element : this.webdriverService.getSeleniumLog(testCaseExecution.getSession())) {
                        out.writeBytes(element);
                    }
                    byte[] bytes = baos.toByteArray();
                    fileOutputStream.write(bytes);
                    out.close();
                    baos.close();
                    fileOutputStream.close();
                    // Index file created to database.
                    object = testCaseExecutionFileFactory.create(0, testCaseExecution.getId(), recorder.getLevel(), "Selenium log", recorder.getRelativeFilenameURL(), "TXT", "", null, "", null);
                    testCaseExecutionFileService.save(object);
                } catch (FileNotFoundException ex) {
                    LOG.error(logPrefix + ex.toString());
                } catch (IOException ex) {
                    LOG.error(logPrefix + ex.toString());
                }
                LOG.debug(logPrefix + "Selenium log recorded in : " + recorder.getRelativeFilenameURL());
            } catch (CerberusException ex) {
                LOG.error(logPrefix + ex.toString());
            }
        }
    } else {
        LOG.debug(logPrefix + "Selenium Log not recorded because test on non GUI application");
    }
    return object;
}
Also used : CerberusException(org.cerberus.exception.CerberusException) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Recorder(org.cerberus.engine.entity.Recorder) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IFactoryTestCaseExecutionFile(org.cerberus.crud.factory.IFactoryTestCaseExecutionFile) File(java.io.File) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 14 with TestCaseExecutionFile

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

the class TestCaseStepActionExecutionService method readByVarious1WithDependency.

@Override
public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase, int step, int index) {
    AnswerList actions = this.readByVarious1(executionId, test, testcase, step, index);
    AnswerList response = null;
    List<TestCaseStepActionExecution> tcsaeList = new ArrayList();
    for (Object action : actions.getDataList()) {
        TestCaseStepActionExecution tcsae = (TestCaseStepActionExecution) action;
        AnswerList controls = testCaseStepActionControlExecutionService.readByVarious1WithDependency(executionId, test, testcase, step, index, tcsae.getSequence());
        tcsae.setTestCaseStepActionControlExecutionList((List<TestCaseStepActionControlExecution>) controls.getDataList());
        AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tcsae.getTest() + "-" + tcsae.getTestCase() + "-" + tcsae.getStep() + "-" + tcsae.getIndex() + "-" + tcsae.getSequence());
        tcsae.setFileList((List<TestCaseExecutionFile>) files.getDataList());
        tcsaeList.add(tcsae);
    }
    response = new AnswerList(tcsaeList, actions.getTotalRows());
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Example 15 with TestCaseExecutionFile

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

the class TestCaseStepExecutionService method readByVarious1WithDependency.

@Override
public AnswerList readByVarious1WithDependency(long executionId, String test, String testcase) {
    AnswerList steps = this.readByVarious1(executionId, test, testcase);
    AnswerList response = null;
    List<TestCaseStepExecution> tcseList = new ArrayList();
    for (Object step : steps.getDataList()) {
        TestCaseStepExecution tces = (TestCaseStepExecution) step;
        AnswerList actions = testCaseStepActionExecutionService.readByVarious1WithDependency(executionId, tces.getTest(), tces.getTestCase(), tces.getStep(), tces.getIndex());
        tces.setTestCaseStepActionExecutionList((List<TestCaseStepActionExecution>) actions.getDataList());
        AnswerList files = testCaseExecutionFileService.readByVarious(executionId, tces.getTest() + "-" + tces.getTestCase() + "-" + tces.getStep() + "-" + tces.getIndex());
        tces.setFileList((List<TestCaseExecutionFile>) files.getDataList());
        tcseList.add(tces);
    }
    response = new AnswerList(tcseList, steps.getTotalRows());
    return response;
}
Also used : TestCaseStepExecution(org.cerberus.crud.entity.TestCaseStepExecution) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) TestCaseExecutionFile(org.cerberus.crud.entity.TestCaseExecutionFile)

Aggregations

TestCaseExecutionFile (org.cerberus.crud.entity.TestCaseExecutionFile)28 IFactoryTestCaseExecutionFile (org.cerberus.crud.factory.IFactoryTestCaseExecutionFile)15 ArrayList (java.util.ArrayList)13 MessageEvent (org.cerberus.engine.entity.MessageEvent)8 AnswerList (org.cerberus.util.answer.AnswerList)7 Recorder (org.cerberus.engine.entity.Recorder)6 CerberusException (org.cerberus.exception.CerberusException)6 IOException (java.io.IOException)5 AnswerItem (org.cerberus.util.answer.AnswerItem)5 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 TestCaseExecutionData (org.cerberus.crud.entity.TestCaseExecutionData)4 TestCaseStepActionControlExecution (org.cerberus.crud.entity.TestCaseStepActionControlExecution)4 TestCaseStepActionExecution (org.cerberus.crud.entity.TestCaseStepActionExecution)4 Connection (java.sql.Connection)3 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)3 FactoryTestCaseExecutionFile (org.cerberus.crud.factory.impl.FactoryTestCaseExecutionFile)3