Page 1 of 1

Call data source connection from user code

Posted: Fri Dec 27, 2013 1:10 pm
by ElSticky
I'm looking for the best way to validate if some newly added value is added to my database. So I tought of binding my project with a data source containing the select which returns a table that contains the newly added item. Is it possible to call this data source from user code and add the returned items from the data source to an array? So I can loop through the items returned by the data source and check if the new created one is in there.

Re: Call data source connection from user code

Posted: Mon Dec 30, 2013 2:47 pm
by mebner
Hi,

You could use a data source to validate the values.
Each row of the data source represents one iteration, so you need to design your test case in a way that each iteration validates one value of your database.
You could also define the range for the data source, you can define that just the newly added row should be used for the validation, used as data value.
Do you already now the section about data driven testing?

Regards,
Markus

Re: Call data source connection from user code

Posted: Sun Nov 16, 2014 7:58 pm
by Vic
Hello,

I am having similar problem.

The scenario is as follow :

1. Begin the execution by opening a browser (and a web page)
2. In the user code, initialize a variable with a data from the repository (e.g. varA = "AAAA")
3. Call the select in the data source with the variable varA and return a specific data from the database table

It seems like that the data source is the first thing called during the execution. At that point the webpage is not opened yet and varA has no value.

How to have a specific data from a database from the user code?

Thanks

Attached the datasource used.

Windows XP
Ranorex 5.0.3

Re: Call data source connection from user code

Posted: Mon Nov 17, 2014 3:30 pm
by krstcs
You cannot pass test variables into the data connectors directly. Data connectors are static.

The only thing you can do is to manipulate the SQL query right before the data connector is used. You will have to do this in user code.

1. Create your data connector with a default data set. This will allow you to bind the connector to the variables.
2. Create a user-code module.
3. Add a test variable to the module and name it the same as the variable you want to use in the query (varA).
4. In the Run() method, change the sql query for the specific data connector you are wanting to manipulate.

Code: Select all

((SqlDataConnector)DataSources.Get("<Your Data Connector's name here>).Connector).Query = "select * from myTable where name=" + varA;

//my method...
        public static void SetupSqlDataConnector(string dataCacheName, string queryString) {
            ((SqlDataConnector)DataSources.Get(dataCacheName).Connector).Query = queryString;
        }
I actually have this in method in a DLL that I use for all of my tests, as you can see in the second part above.

Place the user-code module RIGHT BEFORE the test case that uses the data connector and bind the variable.