Hi,
Is there any easy way of exporting all data from an UltraGrid programmatically? I have been toying with ...Object.Export and although QTP does not error on that line, it's not saving anything; I have tried various parameters such as filename etc as detailed in the NetAdvantage help (which is much more useful than the TestAdvantage help!) but I can't seem to quite nail it. Do you have any suggestions?
The reason I want to do this is that I have a grid that changes dynamically every time a field is changed on a form and as such there is no set number of sibling rows, and as trying to navigate an unknown number of sibling rows is proving a nightmare through QTP, I've decided to dump the grid to excel and use the Excel Object Model to do the work, which I'm much more familiar with!
Best regards, Ryan
Hi Ryan,
You need an "UltraGridExcelExporter" object to export grid content to an Excel file. Here is how its done in VS (using C#)
ExcelExporter = new Infragistics.Win.UltraWinGrid.ExcelExport.UltraGridExcelExporter(); ExcelExporter.Export(ultraGrid1,"FilterRows.xls");
I'm not sure how (or even if its possible to) do this in QTP.
For the original problem, if you can explain a little more I can try to provide a code snip-it that might help you.
Regards,
Ammar
Hi Ammar, thanks for the repsonse. Sorry about my delayed reply.
I think you are right, there seems no way to use the exporter in QTP, but that's not the end of the world as the AUT provides a menu option to do it anyway.
Anyhow, the reason I want to export to excel is partly bourne out of my frustration in not being able to fashion the right code in QTP to navigate through a UltraGrid reliably in the manner I want. Here is my situation: I have an Ultragrid that has many columns, and the user is allowed to group the data in the grid by whatever and however many columns they choose. They can then export their view to Excel. What I need to be able to test is that the data in Excel matches the data as displayed in the UltraGrid.
So my ultimate problem is creating some code that can navigate through all the rows of an Ultragrid, and is able to account for any number of parent/child rows. Now I know the kind of things I should be using; for example, initially doing a row count on the table, which returns the number of top level parent rows. Then going through those parent rows, querying if each one has a sibling, and so on recursively, until I get to any data rows. Sometimes there can be 5 levels of parent rows before you get to any data (but of course this can change as the data can be grouped by anything!), so of course to get data out of a cell in that row would require ...GetCellData("a;b;c;d;e;f;g", "somecolumnname"), where a-f represent the parent levels above data row 'g', so as QTP is recursively drilling down it needs to 'build up' (and remember) the path to 'g'.
I hope this explanation is clear, I'm sure it's been done before but it's proving quite tricky for me. Do you have any useful code Ammar?
Best regards,
Ryan
There are a number of means to Export data, then question being is what is the exact purpose so that the means of export can be tailored to your exact needs. The reason I imagine there is a lack of response on this forum is, in most cases this is not neccesary for testing. If you are going to be testing an application, you typically want to be in a controlled as possible environment, and test each small change. All the input should be pre-determined, and therefore all the output should be predetermined. One change should only have a limited predetermined number of changes, that you can specifically test for. So the question is, is one cell change going to change every other cell in your grid?
If this is really your case, I would probably do your test on the NetAdvantage side, because it's not only exporting that's going to be your issue with QTP but importing. As to properly test the data using QTP you will have to export the controlled base data. Then during replay, export test data, and then import your base data, then run through some long comparitive logic to import it. This is why I suggest doing it on the NetAdvantage side, because this way you will be working more directly with the object model, you can create a button that will dump your data, then another one to compare it with a loaded file.
If you are really determined to do this entirely in QTP in this manner with an undetermined set of variables. I won't go into direct code specifics, as it would be too time consuming but I can go into the basics. In a nutshell you are going to create a recursive function that does the following:
Checks to see if the Rows Count is > 0
Loop through the Rows Foreach Row: Add the data as a row to a temporary DataTable sheet, (QTP offers the ability to add data dynamically to a sheet). By: Storing the Band depth / Row number likely as a delimited set of integers, the complexity of which varies depending on if you can have multiple child bands per row, and different child bands independant of the previous rows. Loop through the cells and store each value Check to see if a row has ChildBands if yes, For each child band Get the Rows collection and feed back into the loop.
Loop through the Rows
Foreach Row: Add the data as a row to a temporary DataTable sheet, (QTP offers the ability to add data dynamically to a sheet). By: Storing the Band depth / Row number likely as a delimited set of integers, the complexity of which varies depending on if you can have multiple child bands per row, and different child bands independant of the previous rows. Loop through the cells and store each value Check to see if a row has ChildBands if yes, For each child band Get the Rows collection and feed back into the loop.
Foreach Row:
Add the data as a row to a temporary DataTable sheet, (QTP offers the ability to add data dynamically to a sheet). By: Storing the Band depth / Row number likely as a delimited set of integers, the complexity of which varies depending on if you can have multiple child bands per row, and different child bands independant of the previous rows. Loop through the cells and store each value Check to see if a row has ChildBands if yes, For each child band Get the Rows collection and feed back into the loop.
Add the data as a row to a temporary DataTable sheet, (QTP offers the ability to add data dynamically to a sheet). By:
Storing the Band depth / Row number likely as a delimited set of integers, the complexity of which varies depending on if you can have multiple child bands per row, and different child bands independant of the previous rows. Loop through the cells and store each value
Storing the Band depth / Row number likely as a delimited set of integers, the complexity of which varies depending on if you can have multiple child bands per row, and different child bands independant of the previous rows.
Loop through the cells and store each value
Check to see if a row has ChildBands
if yes, For each child band Get the Rows collection and feed back into the loop.
Most of the functions you will need to use the .NET object model via something like:
SET rows = SwfWindow("Root").SwfTable("ultraGrid1").Object.Rows
rows.Count ' equals the number of rows
rows.GetItem(0) ' is an object for the first row
rows.GetItem(0).Cells.Count ' equals the number of cells
rows.GetItem(0).Cells.GetItem(0).Value ' Value Cell 0
rows.GetItem(0).HasChild() ' Does the row have ChildBands
SET childRows = rows.GetItems(0).ChildBands.GetItem(0).Rows
Now while this in theory should work fine, on large scale I am not sure how well QTP's DataTable will hold out for either a large number of rows or creating and deleting data, as I imagine for each test you'll likely need to create and delete two Temporary DataTables, the one that represents the current state, and the second one read in from a file that is the control. Is it possible sure, I would highly recommend though doing more controlled tests.
Hi Mike,
I also trying to export data from the SwfTable in to Excel file. I can't use standart QTP Checkpoints because it is Not allowing to set tolerance for rounding of floating point numbers. So I want to export data in to Excel file and round data before comparing it with the expected data. I also can't loop though SwfTable because it takes forever. Any suggestion how to resolve this issue?
Thanks,
Dmitry