Automatic filtering of datasource

Class library usage, coding and language questions.
Posts: 3
Joined: Wed Mar 29, 2017 11:44 am

Automatic filtering of datasource

Post by rosta » Wed Aug 09, 2017 3:26 pm


our AUT supports several different database-systems (MS SQL Server, SQLite, even Access, you get the idea).
We are testing each functionality of our software for each possible database connection, using CSV-Connectors.

The CSV contains all information to connect to the desired data source, create the query and validate the result.

Simplified CSV example:

Code: Select all

Since these tests take some time, we would like to be able to filter out data sources which we do not want to test at this time (for example: only test where database = "mssql").

Considering that we have about 80 test cases, each with an individual CSV-file bound to it, manual filtering using the Ranorex Databinding GUI is not an option.

Our most promising attempt was to check the current data row in a code module in the test case setup and skip it if the data source should not be tested now.


Code: Select all

while (TestSuite.CurrentTestContainer.DataContext.Get("database") != "mssql") {
But we got stuck at this stage because the remaining number of test iterations is not updated when using the Next()-method.

Another attempt was to ignore test iterations using the conditional configuration from the databinding-dialog, but this allows only to skip a test case completely.

The easiest solution for us would be to either:
  • update the internal iteration counter, so that using Next() becomes possible,
  • find and use an API-function to ignore an iteration, much like the Test Case-condition would.
Can anyone point me in the right direction?

Hours of googling and getting lost in the API documentation could not solve this for us.
Maybe there is a much easier solution we simply missed out on?

Thank you very much!

Ranorex-Version: 7.1

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

Re: Automatic filtering of datasource

Post by odklizec » Mon Aug 14, 2017 2:42 pm


I think the easiest (and code less) way would be using recently (7.1) introduced conditionally running test cases/smart folders.

Basically, you should create 3 test cases/smart folders, each using the same data connector, but each should have its own data range for mssql, sqlite and access rows. Then each TC/SF should have defined a condition, which would enable/disable TC/SM based of Global/Parent Parameter or DataConnector value. Hope this helps?

BTW, since you are using DB, I think it would be logical to use a DB-based data connector, in which you can "easily" define (don't ask me how ;)) a DB query, which should return only records of given value (mssql, sqlite or access). I think this approach should be even easier for you?
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

Posts: 3
Joined: Wed Mar 29, 2017 11:44 am

Re: Automatic filtering of datasource

Post by rosta » Tue Aug 22, 2017 12:15 pm

Dear Pavel,

thank you very much for your input!

The conditional execution introduced with the latest Ranorex would indeed be the ideal solution.
The major drawback of this approach is the multiplication of our test cases that would ensue, resulting in a bloated test suite.

At the moment, our test structure is like this:
  • TestFunctionA
  • TestFunctionB
  • TestFunctionC
Each test case is run for multiple database connections.
If we would restructure for conditional execution, we would have to split the tests cases to test each function for each database connection separately, like this:
  • TestFunctionAForSQL
  • TestFunctionAForAccess
  • TestFunctionAForSQLite
  • TestFunctionBForSQL
  • TestFunctionBForAccess
  • TestFunctionBForSQLite
  • TestFunctionCForSQL
  • TestFunctionCForAccess
  • TestFunctionCForSQLite
Following this approach, our number of test cases exceed 700. We have actually been there, using and maintaining this test suite was no fun at all.

We can easily determine if a data row should be skipped, we simply lack (or have not found yet) the correct way to actually skip it.

Maybe I simply miss out on something?

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

Re: Automatic filtering of datasource

Post by McTurtle » Wed Aug 23, 2017 1:40 pm

Hello rosta,

I have built a small example from which you can see how to set a custom data range. With this example you can "skip" lines in a data connector :)
void ITestModule.Run()
        	//Pass the name of the test container which data source should get modified. 
        	//Key is to do it before the test container is getting executed
            var CurrentTestCase=TestSuite.Current.GetTestContainer(Name_of_current_container);
            //Get all the rows of the data source that is currently set
			Ranorex.Core.Data.RowCollection rows=CurrentTestCase.DataContext.Source.Rows;
			//Create a string for data range set
			string s="";
			int i=0;
			//for each row that has an element value "Yes" in column [1] add te value of i to the string
			foreach (Ranorex.Core.Data.Row element in rows)
				if (element.Values[1]=="Yes")
			//remove the last character from the string since you dont want ',' to be at the end
			//Parse as per ... _Parse.htm
			DataRangeSet new_data_range=DataRangeSet.Parse(s);
			//Set new data range set
What you would need to do is to exchange the Name_of_current_container for your actual test container name. Furthermore, you need to change (element.Values[1]=="Yes") into (element.Values[0]=="mssql") and this example should be good to go for your use case.

I have also attached the example with a data source to this post. My data source looks like this:
2017-08-23 14_36_54-Datasource.xlsx - Excel.png
2017-08-23 14_36_54-Datasource.xlsx - Excel.png (4.79 KiB) Viewed 2310 times
Ranorex should report 1,3,4,5,9,10 and ignore 2,6,7,8.

Please do test this solution and let me know if this is what you needed.

(20.15 KiB) Downloaded 75 times

Posts: 3
Joined: Wed Mar 29, 2017 11:44 am

Re: Automatic filtering of datasource

Post by rosta » Tue Aug 29, 2017 2:45 pm

Dear McTurtle,

thank you very much for your suggestion, it is exactly what we needed :D
Following your advice we were able to reconfigure the DataRange and skip undesired data rows easily.

Thank you again for the valuable input!


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

Re: Automatic filtering of datasource

Post by McTurtle » Wed Aug 30, 2017 11:08 am

Hello rosta,

Thank you very much for your feedback.
I am glad to hear that I could help.


Posts: 4
Joined: Mon Mar 05, 2018 7:51 am

Re: Automatic filtering of datasource

Post by bhargav » Tue Apr 17, 2018 10:07 am

Could you also tell me how to send the range as a command line parameter? I need this to execute different ranges based on conditions in Git Lab CI.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12169
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: Automatic filtering of datasource

Post by Support Team » Thu Apr 19, 2018 1:40 pm

Hi bhargav,

Thank you for your post.

In order to set the data range via command line, please use the following argument:
/tcdr:<name or guid of test case or smart folder>=<data range>

As an example, the following command will execute only line 3 and 4 of a data connector
command_tcdr.png (1.61 KiB) Viewed 1690 times
More info command line arguments can be found in the following section of our user guide in Lesson 4