Search in sources :

Example 1 with WaitTeststepProperties

use of io.irontest.models.teststep.WaitTeststepProperties in project irontest by zheng-wang.

the class RegularTestcaseRunner method run.

@Override
public TestcaseRun run() throws JsonProcessingException {
    RegularTestcaseRun testcaseRun = new RegularTestcaseRun();
    preProcessingForIIBTestcase();
    startTestcaseRun(testcaseRun);
    if (isTestcaseHasWaitForProcessingCompletionAction()) {
        // milliseconds
        long secondFraction = getTestcaseRunContext().getTestcaseRunStartTime().getTime() % 1000;
        long millisecondsUntilNextSecond = 1000 - secondFraction;
        Teststep waitStep = getTestcase().getTeststeps().get(0);
        waitStep.setName("Wait " + millisecondsUntilNextSecond + " milliseconds");
        waitStep.setOtherProperties(new WaitTeststepProperties(millisecondsUntilNextSecond));
    }
    // run test steps
    for (Teststep teststep : getTestcase().getTeststeps()) {
        testcaseRun.getStepRuns().add(runTeststep(teststep));
    }
    // test case run ends
    testcaseRun.setDuration(new Date().getTime() - testcaseRun.getStartTime().getTime());
    LOGGER.info("Finish running test case: " + getTestcase().getName());
    for (TeststepRun teststepRun : testcaseRun.getStepRuns()) {
        if (TestResult.FAILED == teststepRun.getResult()) {
            testcaseRun.setResult(TestResult.FAILED);
            break;
        }
    }
    // persist test case run details into database
    getTestcaseRunDAO().insert(testcaseRun);
    // prepare return object for UI (reduced contents for performance)
    List<TeststepRun> teststepRunsForUI = new ArrayList<>();
    for (TeststepRun stepRun : testcaseRun.getStepRuns()) {
        TeststepRun teststepRunForUI = new TeststepRun();
        teststepRunForUI.setId(stepRun.getId());
        teststepRunForUI.setResult(stepRun.getResult());
        Teststep teststepForUI = new Teststep();
        teststepForUI.setId(stepRun.getTeststep().getId());
        teststepRunForUI.setTeststep(teststepForUI);
        teststepRunsForUI.add(teststepRunForUI);
    }
    RegularTestcaseRun testcaseRunForUI = new RegularTestcaseRun();
    testcaseRunForUI.setId(testcaseRun.getId());
    testcaseRunForUI.setResult(testcaseRun.getResult());
    testcaseRunForUI.setStepRuns(teststepRunsForUI);
    return testcaseRunForUI;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) WaitTeststepProperties(io.irontest.models.teststep.WaitTeststepProperties) TeststepRun(io.irontest.models.testrun.TeststepRun) ArrayList(java.util.ArrayList) RegularTestcaseRun(io.irontest.models.testrun.RegularTestcaseRun) Date(java.util.Date)

Example 2 with WaitTeststepProperties

use of io.irontest.models.teststep.WaitTeststepProperties in project irontest by zheng-wang.

the class DataDrivenTestcaseRunner method run.

@Override
public TestcaseRun run() throws JsonProcessingException {
    DataDrivenTestcaseRun testcaseRun = new DataDrivenTestcaseRun();
    Cloner cloner = new Cloner();
    preProcessingForIIBTestcase();
    startTestcaseRun(testcaseRun);
    for (int dataTableRowIndex = 0; dataTableRowIndex < dataTable.getRows().size(); dataTableRowIndex++) {
        LinkedHashMap<String, Object> dataTableRow = dataTable.getRows().get(dataTableRowIndex);
        TestcaseIndividualRun individualRun = new TestcaseIndividualRun();
        testcaseRun.getIndividualRuns().add(individualRun);
        // start test case individual run
        individualRun.setStartTime(new Date());
        LOGGER.info("Start individually running test case with data table row: " + individualRun.getCaption());
        individualRun.setResult(TestResult.PASSED);
        getTestcaseRunContext().setTestcaseIndividualRunStartTime(individualRun.getStartTime());
        if (isTestcaseHasWaitForProcessingCompletionAction()) {
            // milliseconds
            long secondFraction = individualRun.getStartTime().getTime() % 1000;
            long millisecondsUntilNextSecond = 1000 - secondFraction;
            Teststep waitStep = getTestcase().getTeststeps().get(0);
            waitStep.setName("Wait " + millisecondsUntilNextSecond + " milliseconds");
            waitStep.setOtherProperties(new WaitTeststepProperties(millisecondsUntilNextSecond));
        }
        getReferenceableStringProperties().put(IMPLICIT_PROPERTY_NAME_TEST_CASE_INDIVIDUAL_START_TIME, IMPLICIT_PROPERTY_DATE_TIME_FORMAT.format(individualRun.getStartTime()));
        individualRun.setCaption((String) dataTableRow.get(DataTableColumn.COLUMN_NAME_CAPTION));
        getReferenceableEndpointProperties().putAll(dataTable.getEndpointPropertiesInRow(dataTableRowIndex));
        getReferenceableStringProperties().putAll(dataTable.getStringPropertiesInRow(dataTableRowIndex));
        // run test steps
        for (Teststep teststep : getTestcase().getTeststeps()) {
            Teststep clonedTeststep = cloner.deepClone(teststep);
            individualRun.getStepRuns().add(runTeststep(clonedTeststep));
        }
        // test case individual run ends
        individualRun.setDuration(new Date().getTime() - individualRun.getStartTime().getTime());
        LOGGER.info("Finish individually running test case with data table row: " + individualRun.getCaption());
        for (TeststepRun teststepRun : individualRun.getStepRuns()) {
            if (TestResult.FAILED == teststepRun.getResult()) {
                individualRun.setResult(TestResult.FAILED);
                break;
            }
        }
    }
    // test case run ends
    testcaseRun.setDuration(new Date().getTime() - testcaseRun.getStartTime().getTime());
    LOGGER.info("Finish running test case: " + getTestcase().getName());
    for (TestcaseIndividualRun individualRun : testcaseRun.getIndividualRuns()) {
        if (TestResult.FAILED == individualRun.getResult()) {
            testcaseRun.setResult(TestResult.FAILED);
            break;
        }
    }
    // persist test case run details into database
    getTestcaseRunDAO().insert(testcaseRun);
    return testcaseRun;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) WaitTeststepProperties(io.irontest.models.teststep.WaitTeststepProperties) TeststepRun(io.irontest.models.testrun.TeststepRun) TestcaseIndividualRun(io.irontest.models.testrun.TestcaseIndividualRun) DataDrivenTestcaseRun(io.irontest.models.testrun.DataDrivenTestcaseRun) Date(java.util.Date) Cloner(com.rits.cloning.Cloner)

Example 3 with WaitTeststepProperties

use of io.irontest.models.teststep.WaitTeststepProperties in project irontest by zheng-wang.

the class WaitTeststepRunner method run.

protected BasicTeststepRun run(Teststep teststep) throws InterruptedException {
    WaitTeststepProperties teststepProperties = (WaitTeststepProperties) teststep.getOtherProperties();
    Thread.sleep(teststepProperties.getMilliseconds());
    return new BasicTeststepRun();
}
Also used : WaitTeststepProperties(io.irontest.models.teststep.WaitTeststepProperties)

Aggregations

WaitTeststepProperties (io.irontest.models.teststep.WaitTeststepProperties)3 TeststepRun (io.irontest.models.testrun.TeststepRun)2 Teststep (io.irontest.models.teststep.Teststep)2 Date (java.util.Date)2 Cloner (com.rits.cloning.Cloner)1 DataDrivenTestcaseRun (io.irontest.models.testrun.DataDrivenTestcaseRun)1 RegularTestcaseRun (io.irontest.models.testrun.RegularTestcaseRun)1 TestcaseIndividualRun (io.irontest.models.testrun.TestcaseIndividualRun)1 ArrayList (java.util.ArrayList)1