Verifying data in Excel file
My tested application outputs the reports as excel files. These files have user and date information which does not lend them well to a file comparison. I'd like to be able to verify data contained in a range of rows and columns contained in selected sheets of the excel file.
This topic has been broached previously, and I believe Robert was on the right track in this post, however, it does not have enough detail for me. https://community.smartbear.com/t5/TestComplete-General-Discussions/How-to-test-the-content-of-an-Excel-spreadsheet/td-p/140671
I am able to use the following script routine to get the data from select sheets of my outputted excel file. Can I now use this information that is contained in the Test Log to compare to baseline values? How is that done? How can I specify the rows and columns?
var RecNo;
// Posts data to the log (helper routine)
function ProcessData()
{
var Fldr, i;
Fldr = Log.CreateFolder("Record: " + aqConvert.VarToStr(RecNo));
Log.PushLogFolder(Fldr);
for(i = 0; i < DDT.CurrentDriver.ColumnCount; i++)
Log.Message(DDT.CurrentDriver.ColumnName(i) + ": " + aqConvert.VarToStr(DDT.CurrentDriver.Value(i)));
Log.PopLogFolder();
RecNo = RecNo + 1;
}
// Creates the driver (main routine)
function TestDriver()
{
var Driver;
// Creates the driver
// If you connect to an Excel 2007 sheet, use the following method call:
// Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", true);
Driver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1");
// Iterates through records
RecNo = 0;
while (! Driver.EOF() )
{
ProcessData(); // Processes data
Driver.Next(); // Goes to the next record
}
// Closes the driver
DDT.CloseDriver(Driver.Name);
}
It seems that this is where the data driven loop comes in, but I don't know how to make use of that to confirm values.
Apologies if this is a duplicate post in some way. I tried to post this question previously but was not able to find record of it, so I am posting again.
Thanks,
Mike
Gotcha... OK, then... rewriting your code a bit. Note that I'm removing the ProcessData function as all that is doing is going through the driver an writnig to the log.
function TestDriver() { var Driver; // Creates the driver // If you connect to an Excel 2007 sheet, use the following method call: // Driver = DDT.ExcelDriver("C:\\MyFile.xlsx", "Sheet1", true); TestDriver = DDT.ExcelDriver("C:\\MyFile.xls", "Sheet1"); BaseDriver = DDT.ExcelDriver("C:\\BaselineFile.xls", "Sheet1"): // Iterates through records RecNo = 0; while (!TestDriver.EOF() && !BaseDriver.EOF()) { for (var i = 0, i < TestDriver.ColumnCount, i++) { if (TestDriver.Value(i) <> BaseDriver.Value(i)) { Log.Warning("Test file column " + TestDriver.ColumnName(i) + " does not match baseline") } } TestDriver.Next(); // Goes to the next record BaseDriver.Next(); } // Closes the driver DDT.CloseDriver(TestDriver.Name); DDT.CloseDriver(BaseDriver.Name); }
In side the for loop is where you do all your comparisons, etc. I only included a very basic log warning but you could detail it out more with the values of test versus the values of baseline, etc. Generally, this is what you're looking for... looping through BOTH files in parallel, one row at a time, comparing column values.