Forum Discussion

adithyancr's avatar
adithyancr
Occasional Visitor
2 years ago

write test result to database table

Is there anyway to write the test summary report that is the test status , whether passed or failed to an external database table automatically after test script execution?

1 Reply

  • You can dump the outcomes of each executed test case to a file in a tab-separated format (kind of like a CSV), then pick it from an Excel and play with the pivot tables/graphs. 

    Or you can read that file with another program/script and process the content to dump it into your external table. This would be easier than configuring TestComplete to do it from the script, given that doing anything inside TC is highly complicated.

    How to dump the outcomes to a file? Use the OnStopTestCase event. 

    Example:

     

    function OnStopTestCase(Sender, StopTestCaseParams) {
        let hostName = Sys.HostName;
        let testDurationInSeconds = Math.round(StopTestCaseParams.Duration / 1000);
        let error = "";
        let timestamp = Date.now();
        let date = new Date(timestamp);
        date = `${date.getMonth() + 1}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${date.getMinutes()}`;
        if (StopTestCaseParams.StatusAsText == "Warning") {
            error = StopTestCaseParams.FirstWarningMessage;
        }
        if (StopTestCaseParams.StatusAsText == "Error") {
            error = StopTestCaseParams.FirstErrorMessage;
        }
        let columnNames = ["Timestamp", "Date", "Host", "Title", "Outcome", "Message", "Duration"];
        columnNames = columnNames.join("\t") + "\n";
        let columns = [timestamp, date, hostName, StopTestCaseParams.Name, StopTestCaseParams.StatusAsText, error, testDurationInSeconds];
        let line = "";
        columns.forEach(col => { line += col + "\t" });
        line = line.slice(0, -1) + "\n";
        let filePath = "C:\\outcomes.txt";
        if (!aqFile.Exists(filePath)) {
            aqFile.WriteToTextFile(filePath, columnNames, aqFile.ctUTF8, true)
        }
        try {
            aqFile.WriteToTextFile(filePath, line, aqFile.ctUTF8)
        }
        catch (e) {
            Delay(Math.round(Math.random() * 12));
            aqFile.WriteToTextFile(filePath, line, aqFile.ctUTF8)
        }
    }