How to bind global parameter to datasheet

Ask general questions here.
hbattjes
Posts: 2
Joined: Wed Nov 09, 2016 12:53 pm

How to bind global parameter to datasheet

Post by hbattjes » Wed Nov 09, 2016 2:41 pm

i created a testsuite with several testcases. To be able to execute testcases at different url's I would like to use one datasheet. So I created a global parameter "par_URL". I also created testcases with the variable "var_URL". In an Excel datasheet I created also a column "sheet_URL".

My thought was to bind the datasheet to the par_URL and bind also the var_URL to par_URL. But I do not know how to bind the datasheet to the global parameter. So I started to bind the datasheet column to the var_URL in the 'Set_up_environment' testcase, like the situation below:

Testsuite (global parameter: par_URL)
- Set_up_environment (variable: var_URL bound to a datasheet column)
- Testcase_1 (variable: var_URL bound to par_URL)
- Testcase_2 (variable: var_URL bound to par_URL)

Can someone help me to solve this issue, because I know I am missing some connections.
I tried to create an extra variable (set "x_URL" with value of var_URL) which needs to be bound to par_URL but my coding knowledge limited.

Thanx Hilbert

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

Re: How to bind global parameter to datasheet

Post by odklizec » Thu Nov 10, 2016 10:23 am

Hi,

At first, I would strongly recommend using the same data connector and variable names, so then you can use Auto-Bind feature to automatically bind variables to appropriate data connectors. Otherwise, you need to bind everything manually, which could be a pain with larger projects with too many variables and data connectors.

As for binding data connector with global parameters, you will have to do this via code. We have used it in the past in some of your projects, but honestly, I'm not big fan of filling Global Params from data connector. Here is the code we used at time, but I did not tested it with 6.x, so I don't guarantee it still works ;)

Code: Select all

		/// <summary>
		/// Set Up global parameters from excel file
		/// </summary>
		/// <param name="scDataConnectorName">Name of excel data conector defined in data source</param>
		public void setUpGlobalParameters(string scDataConnectorName)
		{
			if (DataSources.Get(scDataConnectorName) != null)
			{
				Ranorex.Core.Data.DataCache MyDataCache = DataSources.Get(scDataConnectorName);
				MyDataCache.Load();
				int curIterationNum = getIterationNumber();
				if (MyDataCache.Rows.Count == 1)
				{
					curIterationNum = 0;
				}
				TestSuite.Current.Parameters.Clear();
				foreach(var col in MyDataCache.Columns)
				{
					TestSuite.Current.Parameters.Add(col.Name, MyDataCache.Rows[curIterationNum].Values[col.Index]);
					Report.Info("Param. name: " + col.Name + " " + "Param. value: " + MyDataCache.Rows[getIterationNumber()].Values[col.Index]);
				}
			}
		}
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