Page 1 of 1

Global Param in Data Source

Posted: Fri Aug 22, 2014 3:03 pm
by BCTest
Is it possible to use Global Param in Data Source (SQL-Connector) like

Code: Select all

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

Re: Global Param in Data Source

Posted: Fri Aug 22, 2014 4:19 pm
by krstcs
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));