Page 1 of 1

Looping module in a Test Case

Posted: Wed Feb 01, 2017 4:31 am
by nkarora
Hi,
Can you guide me How to loop Module in a Test Case.
I have created small modules in a test case but I want to repeat a single module again but the issue is the data-source, it only uses first column. I want to use different Column for next Iteration.

Re: Looping module in a Test Case

Posted: Wed Feb 01, 2017 8:26 am
by odklizec
Hi,

The TC data connector does looping via rows, not columns. I'm quite sure there is no GUI way to achieve what you want. You may check this post for some examples of binding module variables to data connector in runtime:
http://www.ranorex.com/forum/how-to-bin ... t4745.html
However, the methods used in this posts are internal methods, therefore not recommended for public use. Not to mention they may not work with latest Ranorex 6.x. And even if they work, they may stop working in future versions ;)

Could you please explain, why do you need to loop the module via columns and not via rows? Maybe a small sample app and example of data connector you want to use would help us to understand your problem and offer a better solution?

Re: Looping module in a Test Case

Posted: Thu Feb 02, 2017 3:15 pm
by krstcs
I would suggest that you need to re-work your data structure so that each row contains the data needed for an iteration of the test case. That is how Ranorex works. It is not a good idea to try to do it the other way, using columns instead of rows.

Each row is an iteration. Each column is a data point in that iteration.

You may need to pivot your data so that the rows are the columns and the columns are the rows.

Re: Looping module in a Test Case

Posted: Tue Feb 07, 2017 2:51 am
by nkarora
Thanks for the response but due to limitation of ranorex I can't use 2 source data for a test case therefore I am trying to use workaround by creating sub-test case.

In my test case I have to use 'Network' (as Data Source 1).
Depend of Data Value from the source 1, I have to use the location(s) to select on the screen.
'Location(s)' as Data Source 2 but since In this case there are multiple location (different list for each source 1) which I need to select on the screen therefore I am using same code to select multiple location(s).

Please suggest.

Re: Looping module in a Test Case

Posted: Tue Feb 07, 2017 8:57 am
by odklizec
Hi,

What you can do is to set a custom data range (per each network source) via code. All you need is a list of Network sources (data source 1) and a list of Locations (data source 2), plus one code module placed before the TC with data source 2. In this code module you have to set a new range of data source 2. As per your screenshot, this code module should be placed before [Select_Sites] TC.

And here is the code you can use to set the custom data range:

Code: Select all

	string curTCName = TestCase.Current.Name;
	var curTC = TestSuite.Current.GetTestCase(curTCName);
	var sitesTC = TestSuite.Current.GetTestCase("Select_Sites");
	
	string networkSource = curTC.DataContext.CurrentRow.Values[curTC.DataContext.Source.Columns["ColumnName"].Index]; //get value from current data range - e.g. network source								
	if (networkSource == "something")
	{
		sitesTC.DataRange.MinRange = 0;
		sitesTC.DataRange.MaxRange = 4;
		sitesTC.DataContext.SetRange(sitesTC.DataRange.MinRange,sitesTC.DataRange.MaxRange); // sets first 5 rows of Select_Sites TC data source
	
	} 
	else if (networkSource == "something_else")
	{
		sitesTC.DataContext.SetRange(DataRangeSet.Parse("5-7,9")); // sets rows 6-8 and 10 
	}
Hope this helps?

Re: Looping module in a Test Case

Posted: Fri Feb 24, 2017 2:44 pm
by pansujit
Hello,
Thank you very much for your reply. This seems to be one data source and selecting different data range but my problem is different data source. Parent have one data source depending upon the data in row, the data source for the child should be changed.
Please help me, do someone have some idea please?

Thanking you
Sincerely
Sujit Pandey

Re: Looping module in a Test Case

Posted: Tue Feb 28, 2017 1:43 pm
by McTurtle
Hello Pansujit,

Is it possible to provide a snapshot of your application and a compressed solution? If no compressed solution can be provided than at least provide a few screenshots of what you are trying to do. Instructions on how this can be done are under the following link: http://www.ranorex.com/support/user-gui ... tions.html

I hope that with more information provided someone will come up with a simpler solution to your problem.

Regards,
McTurtle

Re: Looping module in a Test Case

Posted: Mon Apr 24, 2017 12:56 pm
by pansujit
Hello,
Please forgive me if the explanation is unclear.
1. I have multiple names in row which runs once in one iteration in whole suite.
suppose: lets choose Systran 8 Translation Professional en-fr.
2. Now in the second, there will DictManager smart folder which contains the testCases. In which the currently DictionaryManagerENFR is assigned (filtered some are given one row and some multiple for each test case).

My question is if in the second iteration, there will be systran 8 professsional en-ko and in second, DictMnager, The data source should be changed with (DictionaryManagerENKO) by replacing the same(data source and connection) which means exactly as 1.

Thanking you and I am sorry if it is not clear.
sincerely
Sujit Pandey

Re: Looping module in a Test Case

Posted: Thu Apr 27, 2017 3:26 pm
by McTurtle
Hello pansujit,

I think I understand now:

- While the value from the data connector "SearchDesktopPackage" is "Systran 8 Translation Professional en-fr" the data connector "DictionaryManagerENFR" is to be used
- While the value from the data connector "SearchDesktopPackage" is "Systran 8 Translation Professional en-ko" the data connector "DictionaryManagerENKO" is to be used

I have written a short sample solution that you can check out, it is attached to this post.

In short:
1. Add a code module before the smart folder "DictManager"
2. Create a module variable in the code module by right clicking inside the code module an and choosing "Add new variable"
3. Place the following code into the Run() method of the code module
if (value_from_master=="Systran 8 Translation Professional en-fr")
			{
				ITestContainer smartfolder = (ITestContainer) TestSuite.Current.GetTestContainer("SmartFolder");
				var source =  DataSources.Get("DictionaryManagerENFR");
				smartfolder.DataContext.Source = source;
				source.Load();
				Report.Log(ReportLevel.Info,"Selected DictionaryManagerENFR");​
			}
			else
			{
				ITestContainer smartfolder = (ITestContainer) TestSuite.Current.GetTestContainer("SmartFolder");
				var source =  DataSources.Get("DictionaryManagerENKO");
				smartfolder.DataContext.Source = source;
				source.Load();
				Report.Log(ReportLevel.Info,"Selected DictionaryManagerENKO");​
			}
4. Go to the test suite view and bind the variable that you created in the code module to the primary data connector

In my sample code I have changed the data connector for only 1 smart folder, you need to do it for each of your smart folders.

Also, it is very important that the name of the column in the excel file is identical for DictionaryManagerENFR and DictionaryManagerENKO.

Now the test suite should on every iteration check what the value from "SearchDesktopPackage" is and according to this change the connector for the smart folders.

I hope this helps.

Regards,
McTurtle