Map Global Parameter with a property files or something else

Ranorex Spy, Recorder, and Studio.
l.ruggeri
Posts: 4
Joined: Tue Jun 18, 2019 9:58 am

Map Global Parameter with a property files or something else

Post by l.ruggeri » Thu Sep 24, 2020 6:27 am

i have a project that contains 50 test suites . each test Suit have a Global Parameter id .
My question is :
There is the way to map the global parameter with something like property files? because each time that i run it i need to change the id, so it will be nice to change it only in one place .
BR

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

Re: Map Global Parameter with a property files or something else

Post by odklizec » Thu Sep 24, 2020 6:56 am

Hi,

I'm afraid there is no "out of the box" solution for this. Luckily, it can be done with some API magic. This is what we are using in on of our projects:

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]);
				}
			}
		}
		
		/// <summary>
		/// Gets current TC iteration number
		/// </summary>
		/// <returns>iteration number</returns>
		public int getIterationNumber()
		{
			int curIterationIndex = TestCaseNode.Current.DataContext.CurrentRowIndex-1;
			return curIterationIndex;
		}
Basically, it uses Excel Data connector (you can use also csv or db connector), prefilled with global parameters. Then the code simply erases all global parameters in the test suite and fills them up from the excel data connector of given name. Hope this helps? Well, the project is a bit old and no longer developed, so I'm not quite sure the code is 100% compilable ;)
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