How to set your solution to use different data environments

Best practices, code snippets for common functionality, examples, and guidelines.
User avatar
Certified Professional
Certified Professional
Posts: 29
Joined: Tue Nov 04, 2014 4:18 pm

How to set your solution to use different data environments

Post by Broadnick » Mon Apr 25, 2016 2:30 pm

Here is a solution to use different data Excel files in multi database environments :

1) Create different working Excel Data Files, one for each data environment you want to use. If you want to add columns, data ranges, etc, you have to modify this one (see image 1).

2) Create a generic Excel data file on which you will create data binding in your modules. This one has to be copied to output directory when you run your testsuite. So, you have to set his property to "Always" (see image 1).

3) In Ranorex Build options, create a Debug and/or Release build configuration for each data environment (see image 1).

4) For each of build configurations, create a Pre-build event (in project options) that copies the working Excel data file (related to the configuration chosen) and overwrite the generic Data file (see image 2).

5) If you need to use different global parameters, depending of the data environment, simply add a specific worksheet in the working excel file, which contains global parameters and values. Then, use a code module in the TestSuite SETUP section to read global parameters when you start the test (you should add Try-Catch clauses to this code to trap exceptions) :

Code: Select all

        public void ReadParamFromData()
			//Initialize working variables
			string environmentDataPath = TestSuite.WorkingDirectory + "\\EnvironmentData\\";
			string genericDataFileName = TestSuite.Current.Parameters["genericDataFileName"];
			string dataFileCompletePath = environmentDataPath+genericDataFileName;
			string globalSettingsTab = 	TestSuite.Current.Parameters["globalSettingsTab"];
			string globalSettingsRange = TestSuite.Current.Parameters["globalSettingsRange"];
			string serverIP=null;
			string webContext=null;
			string webPage=null;
			string fullURL=null;
			string eBrowser=null;
			string localization=null;
			//Initialize Excel Connector
			ExcelDataConnector myExcelConnector = new Ranorex.Core.Data.ExcelDataConnector("excelConnector",dataFileCompletePath,globalSettingsTab,globalSettingsRange,System.Windows.Forms.CheckState.Unchecked);
			// Load all Data from the Excel file
			Ranorex.Core.Data.ColumnCollection columnCollection;
			Ranorex.Core.Data.RowCollection rowCollection;
			myExcelConnector.LoadData(out columnCollection, out rowCollection);
			//Report reading operations
			foreach(Ranorex.Core.Data.Row dataRow in rowCollection)
				Report.Info("Server IP:"+dataRow["serverIP"].ToString());
				serverIP = dataRow["serverIP"].ToString();
				Report.Info("Web Context:"+dataRow["webContext"].ToString());
				webContext = dataRow["webContext"].ToString();
				Report.Info("Web Page:"+dataRow["webPage"].ToString());
				webPage = dataRow["webPage"].ToString();
				Report.Info("Full URL to Web App:"+dataRow["fullURL"].ToString());
				fullURL = dataRow["fullURL"].ToString();
				eBrowser = dataRow["eBrowser"].ToString();
				localization = dataRow["localization"].ToString();
			//Assign value to TestSuite Global Parameters
6) If you need to use data from another referenced project, use a second generic data file and add another Pre-build event that copies the second Excel data file (using a relative path to the second project data directory) and overwrite the second generic Data file.
You do not have the required permissions to view the files attached to this post.