Global Param in Data Source

Experiences, small talk, and other automation gossip.
Posts: 116
Joined: Tue Jun 03, 2014 10:15 am
Location: Hamburg, Germany

Global Param in Data Source

Post by BCTest » Fri Aug 22, 2014 3:03 pm

Is it possible to use Global Param in Data Source (SQL-Connector) like

Code: Select all

SELECT * FROM Data WHERE Id=[$Global Param]

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

Re: Global Param in Data Source

Post by krstcs » Fri Aug 22, 2014 4:19 pm

Not directly.

You would need to create a code module that would edit the connector's SQL query. This is how I do my data, so that the data actually drives the test.

Basically, you would have a module that takes the Global Parameter as a variable, and then you grab that and insert it into the query string of the connector the way you want it. This module would then be run right before the test case that you are using that connector for. Bind the variable and you should be set. I always use stored procedures in my db. I set the SPs to have default values for the variables that will force them to return an empty set so I can use the blank SP in my connector in Ranorex and it will still return the columns that need to be bound.

The code looks like this: (I have it in a library project that I can call from any other project.)

Code: Select all

((SqlDataConnector)DataSources.Get("<Data Connector Name>").Connector).Query = "<queryString>";

//My function:
public static void SetupSqlDataConnector(string dataCacheName, string queryString) {
    ((SqlDataConnector)DataSources.Get(dataCacheName).Connector).Query = queryString;

//I call it like this:
// You need to declare a test variable in the module that will be bound at runtime.  I call it KeyVariable here.

<Library>.<Data Class>.SetupSqlDataConnector("MySqlConnector", string.Format("exec GetMySqlConnectorInfo_for_Key @Key=N'{0}'", KeyVariable));
Shortcuts usually aren't...