This is a migrated thread and some comments may be shown as answers.
Multi-level Data Driven Source Sql Order and OrderLines
7 Answers 36 Views
This is a migrated thread and some comments may be shown as answers.
olof
Top achievements
Rank 1
olof asked on 23 Nov 2012, 06:21 AM
Hi,

I have a requirement for data driven tests with the following scenario
I need to be able to populate the screen with

Example Queries
Order
SELECT CustomerID FROM dbo.[Order]
OrderLine
SELECT [ProductID], [Qty] FROM [Sandbox].[dbo].[OrderLine] WHERE CustomerID = [@Parameter]

Order CustomerID: 100
OrderLine ProductID: 100 Qty: 1
 
Order CustomerID: 101
OrderLine ProductID: 201 Qty: 1
OrderLine ProductID: 300 Qty: 2

Order CustomerID: 102
OrderLine ProductID: 100 Qty: 1
OrderLine ProductID: 200 Qty: 1
OrderLine ProductID: 300 Qty: 13

I would like to setup the tests as a parent(order)/child(orderline).

I can't use "InheritParentDataSource" because that would cause an order to always have one orderline.

If I have to do code behind to set up the datasource for child. Please show how to pass parameter from parent to child and then how I override the datasource for child

Current Steps
Add Order Test(Parent)

Type '' into TxtCusomterTextbox - DataDriven: [$(CustomerID)]
Click BtnOrderButton
Execute test 'AddOrderLine'

Add OrderLine Test(Child)
Type '' into TxtOrderLineProductIDTextbox - DataDriven: [$(ProductID)]
Type '' into TxtOrderLineQtyTextbox - DataDriven: [$(Qty)]
Click BtnOrderButton

Any help would be appreciated.


7 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 23 Nov 2012, 12:34 PM
Hi Olof,

Thank you for trying Test Studio.
 
You can add the child test as "test as step" in the parent test. Now on one Order iteration the Order line test as step will be executed as many times as you need, depends on your data source.

Please read more about "Test as Step" here.

Let me know whether it helps.

Greetings,
Boyan Boev
the Telerik team
Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
Vote now
0
Olof
Top achievements
Rank 1
answered on 25 Nov 2012, 11:33 PM
Hi,

I have already set up the tests to be modularized.
Parent Order (Bind Test using Parent Order Query)
    Child OrderLine (Bind Test using Child OrderLine Query)

My issue is how do I pass CustomerID from Parent Order Query CusomterID to Child OrderLine Query

Parent Order Query
    SELECT CustomerID FROM dbo.[Order]
Child OrderLine Query
    SELECT [ProductID], [Qty] FROM [Sandbox].[dbo].[OrderLine] WHERE CustomerID = 100
need to change to
    SELECT [ProductID], [Qty] FROM [Sandbox].[dbo].[OrderLine] WHERE CustomerID = @CusomterID
but can't do this via Bind test to data source dialog so some code needs to be written to override the dataset in Child OrderLine Test and to filter on CustomerID.

Hopefuly this clarifies what I'm trying to do.

Olof
0
Boyan Boev
Telerik team
answered on 27 Nov 2012, 10:56 AM
Hello Olof,

Thanks for clarifying the scenario.

You can achieve this by implementing an execution extension. This model helps integrate Test Studio better into your environment that contains custom results reporting and code defect tracking. You should implement OnInitializeDataSource method. Please follow this article in order to learn how to implement execution extension.

Regards,

Boyan Boev
the Telerik team
Are you enjoying Test Studio? We’d appreciate your vote in the ATI automation awards.
Vote now
0
olof
Top achievements
Rank 1
answered on 30 Nov 2012, 02:55 AM
Hi,

I have implmented OnInitializeDataSource here is the following code

        public DataTable OnInitializeDataSource(ExecutionContext executionContext)
        {
            if (executionContext.Test.ToString() == "AddOrderLine")
            {
                DataSet ds = new DataSet();

                using (
                    SqlConnection sqlConn =
                        new SqlConnection("Data Source=localhost;Initial Catalog=Sandbox;Integrated Security=SSPI;"))
                {
                    SqlCommand command = new SqlCommand("SELECT * FROM OrderLine", sqlConn);
                    SqlDataAdapter da = new SqlDataAdapter();
                    da.SelectCommand = command;

                    sqlConn.Open();

                    da.Fill(ds);
                }

                if (ds.Tables.Count > 0)
                {
                    return ds.Tables[0];
                }
            }            
            return null; //Return null for all other tests
        }

the next problem I have is where do I set the Parent Test OrderID so that I can retrieve it in OnInitializeDataSource. The sql statement will look like this
"SELECT * FROM OrderLine WHERE OrderID = " + Parent.OrderID.ToString()

Can I access the current DataRow from the Parent Test something like this Parent.Data["OrderID"].

Thanks




0
Cody
Telerik team
answered on 30 Nov 2012, 08:38 PM
Hello olof,

No I am sorry but code like this "Parent.Data["OrderID"]" is not possible. Instead what I recommend you do is, in the parent test, create a coded step that saves the OrderID into a global variable. Then when OnInitializeDataSource is called for the child test, it can reference the value stored in this global variable. If you need assistance implementing this, let us know.

All the best,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
olof
Top achievements
Rank 1
answered on 03 Dec 2012, 05:15 AM
Hi,

Thanks for all the help. I have attached the solution.

CustomDataLoad.dll - custom data load. Drop in C:\Program Files (x86)\Telerik\Test Studio\Bin\Plugins  
SampleOrderForm - WPF form
SampleOrderForm.Tests - Tests
Create.sql - create schema and load data

Hopefully this helps other people.

PS One of the zip files has a bug in it the correct one has this line in it
CustomDataLoad.OrderLine.cs
string filePath = System.IO.Path.Combine(str, executionContext.Test.DataInfo.DataProvider);
0
Cody
Telerik team
answered on 03 Dec 2012, 11:48 PM
Hello olof,

Thanks for sharing your solution! I've granted you Telerik Points for allowing other customers to use it.

Regards,
Cody
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Asked by
olof
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Olof
Top achievements
Rank 1
olof
Top achievements
Rank 1
Cody
Telerik team
Share this question
or