How to limit data driven tests frm parent test to child test

Ranorex Studio, Spy, Recorder, and Driver.
cruzez
Posts: 24
Joined: Thu Jan 27, 2011 3:03 am
Location: London, UK

How to limit data driven tests frm parent test to child test

Post by cruzez » Tue Jun 03, 2014 11:58 am

Hi Group members, Sorry I adding another query to the list (being fairly new to this I am having queries on daily basis)

My question is with data driven iterations
I have structured Tests like this

1. Setup[launch and login]
2. Group[to perform few tests say ] I have added 5 data driven values in a test say 2a
3. Teardown[Log off and close]


Problem Test suit executes 1+2+2a+3 for each of data

How can I limit this? I want to execute 1,2 and 3 only once and 2a to be done five times.
Test 2a runs only on a perticular module, I don't think I need to run rest of the tests all the times as it only adding repeated test and takes longer test execution

I have added snapshot of my tests.

I have seen recent post http://www.ranorex.com/forum/iteration- ... t6243.html

By mine is slightly complicated
I have used Test cases and Groups, I have used different data source like csv and ranorex builtin

In the snapshot as you see, Groups I have used ranorex simple data and top level tests have csv file to include user name password etc.. I need to isolate group iterations from Top level iterations :(
You do not have the required permissions to view the files attached to this post.

cruzez
Posts: 24
Joined: Thu Jan 27, 2011 3:03 am
Location: London, UK

Re: How to limit data driven tests frm parent test to child test

Post by cruzez » Tue Jun 03, 2014 12:28 pm

I have figured out, I guess I can raise new feature request:

Provide data source facility for Group Modules as well. I can currently see it is possible with only on Test Case basis.

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

Re: How to limit data driven tests frm parent test to child test

Post by krstcs » Tue Jun 03, 2014 1:48 pm

Groups are only containers for test recording modules, nothing more. They have no logic. They are used just like modules, which means there is no way to bind data connectors to them. Just like modules, they have to be in a test case in order to have a data connector bound to them. That is how Ranorex is designed.


If you need to bind a data set to a group, put the group in its own test case and add the data connector to that test case. You can nest groups as deep as needed.



Also, if you are using data with any complexity at all, I strongly recommend using SQL Server Express to store your data. You can use SQL queries to structure the data however you need it. It is much better in the long run than using simple data tables, text, csv, or XLS files.
Shortcuts usually aren't...

cruzez
Posts: 24
Joined: Thu Jan 27, 2011 3:03 am
Location: London, UK

Re: How to limit data driven tests frm parent test to child test

Post by cruzez » Tue Jun 03, 2014 2:11 pm

Thanks krstcs!
You are absolutely right, I will start using sql, I have already sort of lost the track of my own so many variety of connectors files, builtin ect getting messy :(

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

Re: How to limit data driven tests frm parent test to child test

Post by krstcs » Tue Jun 03, 2014 2:47 pm

Sure thing!

If you need help with the SQL stuff, let me know. The only problem I have with the Ranorex SQL data connector is that it is static, which means it runs the same SQL every time unless you change the SQL query right before the test case runs. So, if you have a truly data-driven test, you would need a lot of modules that change the specific query you are about to run.


I use a custom library that has a module that does this for me. I just pass the module the name of the connector I am changing and the query string I want to use now. My test module has variables that hold the information that limits the query (such as a CustomerID or ENVIRONMENT, etc.). It looks like this for my query that gets the different URLs for each environment we might run tests against (TEST, PROD, PREVIEW, etc.):

Code: Select all

    public class Set_WEBInfoSQL_for_ENVIRONMENT : ITestModule
    {
        /// <summary>
        /// Constructs a new instance.
        /// </summary>
        public Set_WEBInfoSQL_for_ENVIRONMENT()
        {
            // Do not delete - a parameterless constructor is required!
        }

        string _ENVIRONMENT = "TEST";
        [TestVariable("F400087E-BE86-4E24-A2AF-E6EEDC382599")]
        public string ENVIRONMENT
        {
        	get { return _ENVIRONMENT; }
        	set { _ENVIRONMENT = value; }
        }
        
        /// <summary>
        /// Performs the playback of actions in this module.
        /// </summary>
        /// <remarks>You should not call this method directly, instead pass the module
        /// instance to the <see cref="TestModuleRunner.Run(ITestModule)"/> method
        /// that will in turn invoke this method.</remarks>
        void ITestModule.Run()
        {
            Mouse.DefaultMoveTime = 300;
            Keyboard.DefaultKeyPressTime = 100;
            Delay.SpeedFactor = 1.0;
            
            TCS_LIB.Data.SetupSqlDataConnector("WEBInfoSQL", string.Format("exec GetWEBInfo_for_ENVIRONMENT @ENVIRONMENT=N'{0}'", ENVIRONMENT));
        }
    }
I uses string.Format because it is easier to read than <"exec GetWEBInfo_for_ENVIRONMENT @ENVIRONMENT=N'" + ENVIRONMENT + "'">.

Then TCS_LIB.Data.SetupSqlDataConnector(string, string) looks like this:

Code: Select all

        public static void SetupSqlDataConnector(string dataCacheName, string queryString) {
            ((SqlDataConnector)DataSources.Get(dataCacheName).Connector).Query = queryString;
        }
Just drop the module with the code from the top part above into the test suite right before the test case you will be using the data for. Then, you will need to bind the variable just like any other recording module.

This allows you to get results at runtime instead of having to structure the data completely at design time.

Also, I put ALL of my queries inside stored procedures in the DB, so all I have to call from Ranorex is the stored procedure. That way the DB handles data stuff and Ranorex handles test stuff.
Shortcuts usually aren't...

cruzez
Posts: 24
Joined: Thu Jan 27, 2011 3:03 am
Location: London, UK

Re: How to limit data driven tests frm parent test to child test

Post by cruzez » Tue Jun 03, 2014 5:32 pm

Once again, thank you so much krstcs, this is great help
I have already moved all into DB and grouped values types into one table and just use filter to drive data for each test case and I was about to fire another question and noticed your reply, using SQL gave me more flexibility and limit number of tables for similar values or scenarios.

I will implement your method, its only right thing to do I dont want to add connection string to add each possibly will come back with more queries :)
You gave me lot of hints for me to try out.