Can you export data at the end of the run?

Ask general questions here.
DHartley
Posts: 2
Joined: Thu Aug 03, 2017 9:47 am

Can you export data at the end of the run?

Post by DHartley » Thu Aug 03, 2017 9:53 am

We are using .csv data sources in our tests. We're capturing and updating values to these data columns during the test run and then we want to export what's been written to the columns at the end of the test.

Is there an inbuilt way to do this? I did have a search around but couldn't find anything myself.

Thanks

Dave

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

Re: Can you export data at the end of the run?

Post by odklizec » Thu Aug 03, 2017 1:11 pm

Hi,

There is no action (code-less way) to do this. But you can export data to CSV file using pretty simple CsvDataConnector code. Please follow this post, where you can find an example code...
https://www.ranorex.com/forum/writing-i ... tml#p34657
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

DHartley
Posts: 2
Joined: Thu Aug 03, 2017 9:47 am

Re: Can you export data at the end of the run?

Post by DHartley » Mon Aug 14, 2017 10:50 am

Thank you, that pointed me in the right direction. In the end I came up with this which seems to do the trick.

This might need tweaking if you're trying to work with multiple iterations, all my tests are single iteration so I haven't had to factor that in:

Code: Select all

        [UserCodeMethod]
        public static void ExportData()
        { 
        	
        	string csvPath = @"C:\output\" + TestCaseNode.Current.Name + "_" + System.DateTime.Now.ToString("yyyyMMdd_hhmmss") + ".csv";        	
        	string headings = "";
        	string rowData = "";
        	
        	foreach (var heading in TestCaseNode.Current.DataContext.AvailableDataColumnNames){    
				headings = headings + heading.ToString() + ",";
        	}
        	if (headings.Length > 0){
        		headings = headings.Substring(0,headings.Length-1);
        	}
        	
        	foreach (string cell in TestCaseNode.Current.DataContext.EffectiveRow.Values){
        		rowData = rowData + cell + ",";
        	}
        	if (rowData.Length > 0){
        		rowData = rowData.Substring(0,rowData.Length-1);  
        	}      	
        	
        	StreamWriter sw = File.AppendText(csvPath);
        	sw.WriteLine(headings);
        	sw.WriteLine(rowData);
        	sw.Close();
        }