Write recorder-retrieved values to existing excel worksheet

Ask general questions here.
areiplinger
Posts: 3
Joined: Mon Aug 03, 2015 10:58 pm

Write recorder-retrieved values to existing excel worksheet

Post by areiplinger » Tue Sep 01, 2015 11:16 pm

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

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Write recorder-retrieved values to existing excel worksheet

Post by odklizec » Wed Sep 02, 2015 12:37 pm

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?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

areiplinger
Posts: 3
Joined: Mon Aug 03, 2015 10:58 pm

Re: Write recorder-retrieved values to existing excel worksheet

Post by areiplinger » Wed Sep 02, 2015 5:57 pm

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!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3930
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: Write recorder-retrieved values to existing excel worksheet

Post by odklizec » Wed Sep 02, 2015 6:51 pm

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).
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration