Forum Discussion

Vec84's avatar
Vec84
Contributor
8 years ago

Test result status not refreshing

I have this function which I have picked up from a few examples online and managed to get it to write to excel with the result of the test that run. However it seems that either it doesn't refresh aft...
  • tristaanogre's avatar
    8 years ago

    The reason being is that the current log MIGHT not be saved to disk at the time you go to access the Project.Logs object.   There is a setting to save the log every n minutes but that means that you might still have missing data of up to 60 seconds of time.

     

    So... taking your code as you have it, I would add the following (in bold)

     

    unction WriteDataToExcel(fname, sheetName,testTime, errorCount, warnCount)
    {
    var app = Sys.OleObject("Excel.Application");
    var book = app.Workbooks.Open(fname);
    var sheet = book.Sheets.Item(sheetName);
    var rowCount = sheet.UsedRange.Rows.Count+1;
    var columnCount = sheet.UsedRange.Columns.Count;
    var Logs;
    var Count;
    var Name;
    var Status = null;
    
    // Obtains the object that holds the list of project logs
    Log.SaveToDisk();
    Logs = Project.Logs;
    Count = Logs.LogItemsCount
    
    // Iterates through the list of project logs

    This will flush all log data that is in memory to disk before you start working with it.  

  • shankar_r's avatar
    shankar_r
    8 years ago

    So, I have changed some of the lines which are highlighted and added function to get properly enter the data into excel sheet.

    function WriteDataToExcel(fname, sheetName,testTime, errorCount, warnCount){
    
    var app = Sys.OleObject("Excel.Application");
    var book = app.Workbooks.Open(fname);
    var sheet = book.Sheets.Item(sheetName);
    var rowCount = sheet.UsedRange.Rows.Count+1;
    var columnCount = sheet.UsedRange.Columns.Count;
    
    var Logs;
    var Count;
    
    // Obtains the object that holds the list of project logs
    Logs = Project.Logs;
    Count = Logs.LogItemsCount;
    var TestResult = Logs.LogItem(Count-1).Status;
    
    switch (TestResult) //previously it is like Status which is undefined
    { case 0: TestResult = "Passed" break; case 1: TestResult = "Warnings" break; case 2: TestResult = "Failed" break; default : TestResult = "Error" break; } var arrayLogData = [aqConvert.DateTimeToFormatStr(aqDateTime.Now(), "%d/%m/%y %H:%M"), Logs.LogItem(Count-1).Name, TestResult, testTime, errorCount, warnCount] // When you need to add additional data, just add the new element here sheet.Range("A" + rowCount).Value = alignData(arrayLogData[0]); sheet.Range("B" + rowCount).Value = alignData(arrayLogData[1]); sheet.Range("C" + rowCount).Value = alignData(arrayLogData[2]); sheet.Range("D" + rowCount).Value = alignData(arrayLogData[3]); sheet.Range("E" + rowCount).Value = alignData(arrayLogData[4]); sheet.Range("F" + rowCount).Value = alignData(arrayLogData[5]); // If you want add more columns then you can add like below //sheet.Range("G" + inputRow).Value = alignData(arrayLogData[6]); book.Save(); app.Quit(); } function alignData(datatoEnter) { try { var tempValue = aqConvert.VarToStr(datatoEnter); if(tempValue != "") { return tempValue; } else { return ""; } } catch(ex) { return "ERROR FIELD"; } }

    Let me know your results.