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
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.
Boyan Boev
the Telerik team
Vote now
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
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,
the Telerik team
Vote now
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
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
Test Studio Trainings
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);
Thanks for sharing your solution! I've granted you Telerik Points for allowing other customers to use it.
Regards,Cody
the Telerik team
Test Studio Trainings