Validate SQL data during test run

Ranorex Spy, Recorder, and Studio.
ayestyles
Posts: 1
Joined: Tue Jul 22, 2014 3:58 pm

Validate SQL data during test run

Post by ayestyles » Tue Jul 22, 2014 5:31 pm

Hello all,

I am a complete newbie to RanoRex and I am attempting to learn my first test. Instead of just clicking on stuff and watching it fly by I am wanting to actually validate data generated by the system. My application writes information to a sqlite database in a table called accounts.

So, to validate that data I don't need to reference a UI element or anything that I can click- but rather verify it through the data source by defining the data as a variable. All the stuff I have seen so far gives me an example of how to get information from an excel spreadsheet which isn't what I am doing. Rather than explain more I can show you what I am trying to do...

Here is the data source I am working with it is an ODBC connection to the SQLite database. I use a query to populate the data source with the 'view' I want to pull the data from for my test.

Image

Here is my data binding. The idea is that I would use a 'validate' action here to basically look at "BalanceInCents" for "AccountId 1":

Image

Since I am looking for a static value (not in a UI element) I specifically want to look for the value I inputted into the application (which is putty). The value is simply 10000. So how would I write my validate action to get this data? The best I can come up with is this- which does not work....it is also not bound to a repository element which makes RanoRex think I don't know what I am doing- which is sort of true! Do I need to use code here?

Image

Tnimni
Posts: 49
Joined: Thu Jan 02, 2014 4:03 pm

Re: Validate SQL data during test run

Post by Tnimni » Wed Jul 23, 2014 11:28 am

Hi,

You will need to write your own Code module and connect to the SQL with it.

I attached a code snippet of somthing i created, My class knows how to read the Connection string from excel file, and than execute a Select command on Oracle DB. The results are returned as a data table.

The reason I'm reading the Connection string from Excel file is for flexability, i perfer to use XML or app.config file but I have to use excel due to company policy.

Code: Select all

public class DBHandler
    {
    	//generate an instance of genericTestData which will read from excel
        private GenericTestData _dbData = new GenericTestData("oracle");

        //getter to get the connection string from excel in order to connect to the database
        private  string ConnectionString
        {
            get { return _dbData.GetString("Common", "connectionString"); }
        }

        /// <summary>
        /// this method takes a select command and return the query result as a DataTable
        /// </summary>
        /// <param name="oracleCommandText">select command</param>
        /// <returns>DataTable</returns>
        public DataTable ExecuteReader(string oracleCommandText)
        {
        	var myConnection = new OracleConnection(ConnectionString);
        		
        	OracleCommand myCommand = new OracleCommand(oracleCommandText, myConnection);
            DataTable dt = new DataTable();
        	
            try
            {
            	myConnection.Open();
            	OracleDataAdapter da = new OracleDataAdapter(myCommand);;
                da.Fill(dt);
                
            }
            catch (OracleException ex)
            {
            	Report.Failure(ex.Message.ToString());
            }
            finally
            {
                myConnection.Close();
            }
            return dt;
            
        }