Looping module in a Test Case

Ranorex Spy, Recorder, and Studio.
nkarora
Posts: 12
Joined: Mon Dec 05, 2016 12:54 am

Looping module in a Test Case

Post by nkarora » Wed Feb 01, 2017 4:31 am

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.
Attachments
Loop issue.PNG
Loop issue.PNG (8.02 KiB) Viewed 1370 times

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

Re: Looping module in a Test Case

Post by odklizec » Wed Feb 01, 2017 8:26 am

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?
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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Looping module in a Test Case

Post by krstcs » Thu Feb 02, 2017 3:15 pm

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.
Shortcuts usually aren't...

nkarora
Posts: 12
Joined: Mon Dec 05, 2016 12:54 am

Re: Looping module in a Test Case

Post by nkarora » Tue Feb 07, 2017 2:51 am

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.

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

Re: Looping module in a Test Case

Post by odklizec » Tue Feb 07, 2017 8:57 am

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?
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

pansujit
Posts: 18
Joined: Mon Apr 18, 2016 2:56 pm

Re: Looping module in a Test Case

Post by pansujit » Fri Feb 24, 2017 2:44 pm

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

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Looping module in a Test Case

Post by McTurtle » Tue Feb 28, 2017 1:43 pm

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

pansujit
Posts: 18
Joined: Mon Apr 18, 2016 2:56 pm

Re: Looping module in a Test Case

Post by pansujit » Mon Apr 24, 2017 12:56 pm

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
Attachments
multipleDataSource.png
multiple data source for test case
multipleDataSource.png (92.25 KiB) Viewed 1138 times

McTurtle
Posts: 191
Joined: Thu Feb 23, 2017 10:37 am
Location: Benedikt, Slovenia

Re: Looping module in a Test Case

Post by McTurtle » Thu Apr 27, 2017 3:26 pm

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
Attachments
ChangeDataConnector.zip
(30.41 KiB) Downloaded 29 times