How to bind module groups variables programmatically?

Class library usage, coding and language questions.
slw
Posts: 9
Joined: Mon Apr 15, 2013 6:32 pm

How to bind module groups variables programmatically?

Post by slw » Fri Jun 07, 2013 4:19 pm

Hello,

I try to do data binding of my test suite fully dynamically. I managed to do data-binding for individual modules (recordings), but cannot do it for module groups (see solution attached, Ranorex 4.0.3).

I have a test suite with 3 Test cases:
  • InitializeData - here I do all the data binding
  • TestCase1 and TestCase2 - sample test cases where I use the data
As input data I use a list of dictionaries:
//Sample test cases data. Here: data for 2 test cases: 
//1 iteration for TestCase1, and 2 iterations for TestCase2
IDictionary<string, IList<IDictionary<string, string>>> data = new Dictionary<string, IList<IDictionary<string, string>>>();
data.Add("TestCase1", new System.Collections.Generic.List<IDictionary<string, string>>(){
 	new Dictionary<string, string>(){{"var1", "VARIABLE 11-1"}, {"var2", "VARIABLE 11-2"}}
});
data.Add("TestCase2", new System.Collections.Generic.List<IDictionary<string, string>>(){
 	new Dictionary<string, string>(){{"var1", "VARIABLE 21-1"}, {"var2", "VARIABLE 21-2"}},
 	new Dictionary<string, string>(){{"var1", "VARIABLE 22-1"}, {"var2", "VARIABLE 22-2"}}
});
Then I create a CustomConnector (I took a sample from topic " http://www.ranorex.com/forum/how-to-int ... t3511.html ") and do data-binding:
IList<TestCase> tcases = TestSuite.Current.SelectedRunConfig.GetActiveTestCases();
foreach(TestCase tc in tcases){
	...
	//Do data binding for all modules of the test case
	IList<TestSuiteModule> modules = tc.AllModules;
	foreach(TestSuiteModule module in modules){
		ColumnCollection columns = dataCache.Columns;
		BindVariables(tc, module, columns);
	}
}
Data binding is done using this function:
void BindVariables(TestCase tc, TestSuiteModule module, ColumnCollection columns){
	Report.Warn("Doing data binding for module: " + module.Name + " : " + module.Type);
	//bind variables dor all column names of the test case's data connector
	foreach(Ranorex.Core.Data.Column column in columns){
		module.AddDataBinding(new ModuleVarItem(column.Name, Guid.NewGuid().ToString(), module.Name, ""),
		                      new  DataConnectorBindingInfo(column.Name, tc.Id, tc.DataContext));
	}
}
I also tried to do data binding not for the module group as a whole by for individual modules, but moduleGroup.AllModules is always empty.
//if the module is TestSuiteModule, do data binding for it
//if the module is TestSuiteModuleGroup, do data binding for all its submodules
if (module.GetType() == typeof(TestSuiteModule)) {
	BindVariables(tc, module, columns);
} else if (module.GetType() == typeof(TestSuiteModuleGroup)) {
	TestSuiteModuleGroup moduleGroup = (TestSuiteModuleGroup)module;
	//PROBLEM: moduleGroup.AllModules is always empty!
	IList<TestSuiteModule> modulesInGroup = moduleGroup.AllModules;
	foreach(TestSuiteModule moduleInGroup in modulesInGroup){
		BindVariables(tc, moduleInGroup, columns);
	}
}
Current situation: Data binding for modules works correctly. Data binding for module groups does not. I always get warning in the report: "The following module group variables are not bound to a data column: var1, var2"
Ranorex_Data_Binding.png
Ranorex_Data_Binding.png (64.9 KiB) Viewed 3709 times
  • Could you please take a look at the code and advise me where the problem with module groups is?
  • Could you please also tell me why although data binding for individual modules works, I still get warnings: "The following module variables are not bound to a data column: var1, var2" (variables values are then passed correctly)
Attachments
CustomDataSource.zip
(17.4 KiB) Downloaded 246 times

slw
Posts: 9
Joined: Mon Apr 15, 2013 6:32 pm

Re: How to bind module groups variables programmatically?

Post by slw » Mon Jun 10, 2013 10:10 am

I have attached a screenshot (Ranorex_Data_Binding.png) to the original post to clarify the problem.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to bind module groups variables programmatically?

Post by Support Team » Mon Jun 10, 2013 4:17 pm

Hi,

The methods you are using are internal methods of Ranorex. These methods can change every time a new version of Ranorex is released and that's the reason why they are not documented and not supported anymore.
It is not recommended to use non supported API methods (internal methods) and therefore we could not provide further support for these methods.

Is it absolutely necessary to bind the variable in code?
Why aren't you using the binding mechanism of the test suite?

Regards,
Markus
.
Image

slw
Posts: 9
Joined: Mon Apr 15, 2013 6:32 pm

Re: How to bind module groups variables programmatically?

Post by slw » Tue Jun 11, 2013 5:30 pm

>Why aren't you using the binding mechanism of the test suite?

You mean like it is described here: http://www.ranorex.com/support/user-gui ... html#c2978 ?

The reason for our attempt to do the data binding in code, are repetitive actions for manual data binding. E.g. we have test suite structure like
TestSuite
-TestCase1
--ModuleGroup1
---Recording1
---Recording2
-TestCase2
--ModuleGroup2
---Recording1
---Recording3
So that we can use "Auto-Bind" button everywhere, variables in all our recordings and module groups have corresponding (same) names. E.g. a variable is called VAR1 in the Recording1, ModuleGroup1, and in CSV data source as well.

Now we add a new variable to Recording1: NEW_VAR and add it to CSV data source as well. The problem is that after this for our simple test suite we need do 4 additional data bindings:
  • Open ModuleGroup1, add new module groups variable NEW_VAR, bind it to Recording1:NEW_VAR
  • Open TestCase1 and bind data source NEW_VAR to ModuleGroup1:NEW_VAR (using "Auto-Bind")
  • Open ModuleGroup2, add new module groups variable NEW_VAR, bind it to Recording1:NEW_VAR
  • Open TestCase2 and bind data source NEW_VAR to ModuleGroup2:NEW_VAR (using "Auto-Bind")
These steps are rather time consuming since many of our test cases reuse the same module groups.

Certainly, possibility to manually bind variables with different names on different levels is very flexible, but in cases like ours, where only Auto-Bind is used, it is really very repetitive and time consuming.

So, the question is: since the use of the internal API is not recommended, is there some possibility (now or planned in the future) to apply Auto-Bind to the whole TestSuite at once so there is no need to open each individual test case and module group and click Auto-Bind everywhere when a new variable to just 1 recording is added?

E.g. for the test suite above, we would like to right click on the test suite, click there Auto-Bind and this will lead to:
  • All module groups which have unbound variables of its member-modules will get new variables with the same names
  • For all test cases automatic Auto-Bind will be triggered

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to bind module groups variables programmatically?

Post by Support Team » Tue Jun 18, 2013 3:58 pm

Hello,

Thank you for the detailed description.
As Markus said, it is not recommended to use these methods because they can be changed in the new version. That's the reason that they are not added to the API Documentation.
I will treat this as feature request and we will discuss internally how we can make it easier to handle the data binding in module groups.

Regards,
Bernhard
.
Image

slw
Posts: 9
Joined: Mon Apr 15, 2013 6:32 pm

Re: How to bind module groups variables programmatically?

Post by slw » Wed Jun 19, 2013 8:24 am

Thank you very much!