It looks like you are reading the nodes in the log file and trying to ensure a new node is created after each test case to obtain the result to write to Excel as the test project runs. If you are scripting the test cases adding a few Excel calls in a function you can call from your scrips may be the best way to go. The log will only be updated at the end of the run or at intervals you define in the project.
These are a few JavaScript functions to check for existence and write data to Excel. You can mod this and call it as needed. In your case, I would add a call at test start, in a catch to log failures, and in the last line when the test case completes.
function Write2Excel(_valuesObj,_fileName,_sheetName)
{
let excelFile = undefined;
let excelSheet = undefined;
if (!aqFile.Exists(_fileName))
{
// Create a new Excel file and add a new empty sheet to it
Log.Message(aqString.Format("The %s file does not exist and will be created.", _fileName));
excelFile = Excel.Create(_fileName);
excelSheet = excelFile.AddSheet(_sheetName);
excelFile.Save();
}
if (aqFile.Exists(_fileName))
{
// Open the existing Excel file
excelFile = Excel.Open(_fileName);
if(SheetWithTitleExists(excelFile,_sheetName) == false)
{
excelSheet = excelFile.AddSheet(_sheetName);
}
else
{
excelSheet = excelFile.SheetByTitle(_sheetName);
}
Object.entries(_valuesObj).forEach(([key, value]) =>
{
if(excelSheet.RowCount == 0)
{
// Write the header row
Object.entries(value).forEach(([key, value]) =>
{
//Write Line Item Values to rows.
let cellData = "";
Object.entries(value).forEach(([key, value]) =>
{
cellHeader = key;
cellData = value;
});
excelSheet.Cell(key, 1).Value = cellHeader;
excelSheet.Cell(key, 2).Value = cellData;
});
}
else
{
rowIndex = excelSheet.RowCount + 1;
Object.entries(value).forEach(([key, value]) =>
{
//Write Line Item Values to rows.
let cellData = "";
Object.entries(value).forEach(([key, value]) =>
{
cellData = value;
});
excelSheet.Cell(key, rowIndex).Value = cellData;
});
}
});
}
// Save the file to apply the changes
excelFile.Save();
//Excel.Close(fileName);
}
function SheetWithTitleExists(_fileName,_sheetName)
{
if (! equal(_fileName, null))
{
if (_fileName.SheetCount > 0)
{
for (let i = 0; i < _fileName.SheetCount; i++)
{
if (equal(_fileName.SheetByIndex(i).Title, _sheetName))
{
return true;
}
}
return false;
}
else
{
return false;
}
}
}
module.exports.Write2Excel = Write2Excel;
module.exports.SheetWithTitleExists = SheetWithTitleExists;