Passing test parameters to SQL data connector query

Ask general questions here.
Posts: 1
Joined: Sat Aug 27, 2016 12:59 pm

Passing test parameters to SQL data connector query

Post by WSGMSST » Sat Aug 27, 2016 1:19 pm

We’re using Ranorex to test a new application that posts data in widgets from a DB source from a search by an identifier.
from an excel file without resorting to multiple test recordings with corresponding data connectors for each identifier.

We made a global parameter for the identifier and variable can bind it to the test case and SQL data connector.

We next would use a table with a list of identifiers we want to test that would pass the identifier for each iteration.

The main question is how to pass the variable to the query in the data connector of each iteration of the identifier to avoid using multiple data connectors for each identifier.

Are there code examples for passing these parameters to the data connector?

Thank You,

Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Passing test parameters to SQL data connector query

Post by krstcs » Mon Aug 29, 2016 2:47 pm

There is no out-of-the-box way to do it with Ranorex. However, I do it all the time with the following code:

Code: Select all

DataCache dc = DataSources.Get("<DataCache name>");
((SqlDataConnector)dc.Connector).Query = "<Query>";
You would have to put this code in a user-code module and place the module at a point in the parent test case right before the use of the named connector. You could then add module variables to the module and bind them to the parameter or data connector value of the parent that you need.

So, if I wanted to change my connector that is named "DBConnector1" and insert the query "select * from myTable where id=12", I would do the following:

Code: Select all

DataCache dc = DataSources.Get("DBConnector1");
((SqlDataConnector)dc.Connector).Query = "select * from myTable where id=" + varMyId;
This assumes you named your module variable "varMyId".

I actually have this in a library that I use constantly. This does mean that you would need a "manipulator" module (what I call them) for each connector you need to manipulate at runtime.

Note, there are changes planned for how data connectors are handled. According to the Ranorex road map, these should be happening in 6.1 or 6.2, depending on what the Ranorex team can do with them and whether they think it's ready. This may allow for a more out-of-the-box way to handle this.
Shortcuts usually aren't...