Page 1 of 1

Write recorder-retrieved values to existing excel worksheet

Posted: Tue Sep 01, 2015 11:16 pm
by areiplinger
Good afternoon all,

So I'm breaking my head trying to figure out how to persist gathered values from a test case into a local simple data table, or an excel spreadsheet. I've been trying to scour the forums, but haven't found anything that fits my scenario (write to and read from) or that is modern enough to use the Ranorex provided libraries for data source/sink connectivity.

Running through my test case/suite I retrieve values from a webpage, and I'm trying to store them, but everything I've read is for reading from, not necessarily writing to. Any help would be greatly appreciated.

Thanks

Re: Write recorder-retrieved values to existing excel worksheet

Posted: Wed Sep 02, 2015 12:37 pm
by odklizec
Hi and welcome here,

I'm afraid, there is currently no way to write to Ranorex Excel data connector. So you will have to find a 3rd party solution (C# or VB .NET based) to write to excel. There can be found several discussions regarding writing values to Excel.

I'm personally using Ranorex CSV data connector to store (and later read) obtained data. It's relative easy to use and does not require Excel to be installed on target machine. Here is a quick&dirty sample code:
string csvOutputPath = 'c:\path\to\file.csv';

//create CSV data connector
string connector = "CSVConnector";
			
//get data from CSV
Ranorex.Core.Data.CsvDataConnector csvConnector = new Ranorex.Core.Data.CsvDataConnector(connector,csvOutputPath,true);
csvConnector.SeparatorChar = ',';
Ranorex.Core.Data.ColumnCollection propTableColumnsCSV = new Ranorex.Core.Data.ColumnCollection();
Ranorex.Core.Data.RowCollection propTableRowsCSV = new Ranorex.Core.Data.RowCollection(propTableColumnsCSV);

//create CSV column headers
propTableRowsCSV.Add(new string[3]{"ElementName","ElementIndex","ElementValue"});

//write new line to csv
propTableRowsCSV.Add(new string[3]{variable_1,variable_2,variable_3});

// save CSV connector to file
csvConnector.StoreData(propTableColumnsCSV, propTableRowsCSV);
Basically, the above code creates new CSV file, with 3 column headers and one row, filling these 3 columns. It's just a rough sample, without the practical use ;) You need to adapt it according your needs. Hope this helps?

Re: Write recorder-retrieved values to existing excel worksheet

Posted: Wed Sep 02, 2015 5:57 pm
by areiplinger
Thanks for the quick reply, so I've got options for writing to CSV, is it possible to validate by writing to the Simple Data Table that is built-in to the test suite?

Your reply does help very much, thanks!

Re: Write recorder-retrieved values to existing excel worksheet

Posted: Wed Sep 02, 2015 6:51 pm
by odklizec
I don't think there is a way to dynamically write results to Simple Data table, but to be quite honest, I never tried that. I found no good reason to use simple data table over CSV files. You see, with CSV files, you can have as many ref. CSV files as you want and for example validate each of them during each test case iteration. If I'm not mistaken, Simple Data Table content is written directly to Test Case, so you would have to use multiple Test Cases to achieve the same result as with multiple CSV files. Not very practical approach ;)

In my tests, I'm using CSV files a lot. If some program data changes (due to changes in tested application), I simply set a global parameter "RefreshRefData" to "true" and my test calls another method (instead of CSV validation method), which simply writes new ref. CSV files (using the above code).