How To: Dynamically Create Test Containers for Report

Class library usage, coding and language questions.
Bumler
Posts: 3
Joined: Mon Nov 20, 2017 8:16 pm

How To: Dynamically Create Test Containers for Report

Post by Bumler » Thu Jun 21, 2018 1:45 am

In a case where I have something like

Code: Select all

for (int i = 0; i < 10; i++){
    //some test logic
}
How could I set it up so that in the report test logic is in it's own test container (so you would have 10 containers each with a pass or fail). Unfortunately,
I cannot do this by iterating over data as the list of things to iterate over is determined at run-time.

Thanks for any help!

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

Re: How To: Dynamically Create Test Containers for Report

Post by odklizec » Thu Jun 21, 2018 1:21 pm

Hi,

What I'm doing, in a similar situation, is changing and reloading data connector of an already existing SmartFolder.

Here is the sample code:

Code: Select all

			string csvOutputPath = @".\Data\datafile.csv";
			string[] strArray = new string[] { "1", "2", "3", "4", "5", "6", "7"};

			//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[1]{"dataConnectorValue"});  
  
			foreach (string strArrayVal in strArray)
			{
				//write new line to csv  
				propTableRowsCSV.Add(new string[1]{strArrayVal});
			}
  
			// save CSV connector to file  
			csvConnector.StoreData(propTableColumnsCSV, propTableRowsCSV); 
			
			var tc = (TestCaseNode) TestSuite.Current.GetTestContainer("TestCase1");
			var source = DataSources.Get("DataConnector1"); 
			tc.DataContext.Source=source; 
			tc.DataContext.Source.Load(); 
And here is the structure of my (sample) test suite:
DataConnectorReload.png
DataConnectorReload.png (7.64 KiB) Viewed 264 times
Basically, the above code changes the content/number of rows in DataConnector1 and reloads it. The UserCode must be placed before the smart folder you need to change. And of course, you need to change the path to csv and content of strArray with your number of iterations.
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

Bumler
Posts: 3
Joined: Mon Nov 20, 2017 8:16 pm

Re: How To: Dynamically Create Test Containers for Report

Post by Bumler » Thu Jun 21, 2018 7:35 pm

@odklizec

Hmm that makes sense. I'd considered that but was hoping there might be a more lightweight way to do it using Report. Looks like that might be the best way to go about it though.

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

Re: How To: Dynamically Create Test Containers for Report

Post by odklizec » Fri Jun 22, 2018 7:31 am

Hi,

I don't think there is a report-based way to achieve what you want. Using smart folder, with dynamically filled and loaded data connector, looks like the best option.
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