Accessing the Ranorex provided dataconnectors from code

Ranorex Studio, Spy, Recorder, and Driver.
mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Accessing the Ranorex provided dataconnectors from code

Post by mzperix » Mon Jun 03, 2013 9:54 am

Hi,

We are using a lot of slightly different SQL query statements to get the required data for our testcases. We like the way Ranorex provides SQL dataconnectors, but we would like to be able to parametrize the query or sometimes replace the whole query.
As I see, accessing the sql dataconnectors' query part can be done from user code, but I don't know how. Can you help me in this topic, please?

What I want to do is, to create a code module to manipulate the dataconnectors' query and after run a testcase which will use the modified dataconnector.

Regards,
Zoltan Major

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

Re: Accessing the Ranorex provided dataconnectors from code

Post by krstcs » Tue Jun 04, 2013 2:38 pm

Zoltan,

I have had issues with the simplicity of the data connectors in Ranorex as well. Normally having a very simple connector is not a problem, but there are times when you might need to parameterize the queries.

What I finally had to do was create my own connector using the database drivers that are appropriate for what you are working with, but passing in test parameters so I could tailor the results as needed. I then import these results into a simple data table that I use for the actual test case data set.

Create a new simple data table with the fields you need. Then assign those fields to the variables in the test case. Do not add any rows to the table, leave it blank.

So, your process in the test suite would be:
1. Clear the simple data table. (Always do this first so you don't have corrupted data in the table.)
2. Do your custom query through SQL or Oracle drivers and save the result set into the simple data table.
3. Run your test case.
4. Repeat as needed.


Ranorex staff: Could we add a feature request for passing test parameters into the data connectors? Currently the filters in the SQL data connectors are static and it would be very handy to allow us to use test variables in those connector filters.

krs

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

Re: Accessing the Ranorex provided dataconnectors from code

Post by Support Team » Tue Jun 04, 2013 3:03 pm

Hello

You can use the SqlDataConnector class in order to set the query.
You can get access to a specific data connector in the Test Suite by using the following code snippet.
foreach (var dataCache in TestSuite.Current.DataConnectorCaches)
 {
   var conn = dataCache.Connector as SqlDataConnector;
   if (conn.Name == "SQLConnector")
       conn.Query = "select * from Table";
}
Please note that this is only an example, but it shows how you can work with the SqlDataConnector class.
Please read the online API documentation in order to get more information about the SqlDataConnector class.

Regards,
Bernhard

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: Accessing the Ranorex provided dataconnectors from code

Post by mzperix » Wed Jun 05, 2013 9:23 am

Thank you for your answers. I will update on what I have achieved.