This is a migrated thread and some comments may be shown as answers.

data driven, various datasource and modular organization

5 Answers 113 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
karl
Top achievements
Rank 1
karl asked on 30 Nov 2010, 09:58 AM
hello


i already created some tests which use a datasource and also pass it along to "sub-tests", meaning to tests which are executed as a step inside a test. to make my tests modular and use the same test with different data i would like to create a test structure as follows:

i have one big test case which consists of some usual teststeps, custom coded steps and sub-tests.
for example the overall Testcase "mastertest" starts with a subtest "Login" which simply performs a login with given credentials.
the login data is passed from the mastertest to the subtest.
after login i do some some navigation and then call  a subtest called "createCategory".
the "createCategory" performs some actions and uses also data from an excel file but i would like to specific which excel file to use for this specific call. the data for createCategory consists of multiple columns and 3 rows to excecute it 3 times with different data.  this behavior will be used again in createCategory to call another subtest and so on.

for my automatic tests to run i would prepare 3 excel files for the mastertest to cover 3 different use cases. i start the mastertest once which each excel file. depending on the data provided in the excel file different data is passed to the subtests.

Can i set the datasource for each test dynamically? if so could you provide me with a short example?
If this specific approach is currently not possible is there any other way to create modular test with various datasources?
the other option would be to create one test with one datasource, copy this test and exchange the datasource but this would be hard to maintain if tests need to be adapted/extended.


Regards

5 Answers, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 01 Dec 2010, 10:51 PM
Hi karl,

Very interesting data driven test scenario! Unfortunately we don't have a good solution to this problem right now.

However I think there is a coded solution that wouldn't be too difficult to implement. The basic concept is to go ahead and bind your subtest(s) to one specific file, but dynamically swap out the physical file on disk with the right one during execution of the parent test. This would be performed in a coded step of the parent test. Do you need assistance writing this code? Keep in mind that when running tests in Visual Studio the test runs in an Out folder that VS dynamically creates during test execution. I can assist with how to handle this if you're not familiar with it.

In addition we are actively working on implementing a hook where you can override reading the data source of a data driven test and just pass back a DataTable which you populate yourself from any source you have access to. This will be added in a near future version.

Greetings,
Cody
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
karl
Top achievements
Rank 1
answered on 02 Dec 2010, 08:53 AM
hello

i hope i understood you correct:
for the sub-test i can only choose between a datasource itself (always the same no matter from which master test i call it) and/or to use the master test datasource ?

can i change the datasource of the master test with configuration files to start the same mastertest with different files ?

for the master - sub relationship:
if i use the inherit datasource option the master test is executed for every row and call the sub test once.
so if my master test file has 3 rows the whole master test is executed 3 times and calls the sub test every time.
can i use an if condition in the sub test (or the master test) in order to execute it only if certain conditions of the passed data are true?

another idea that just crosses my mind:
could i  use a relative filepath inside my master tests data file and use this information to load the data inside the subtest dynamically and set the data in code behind? this way i would have one column in the master test file for every sub test and load that data.
i would then use the loaded data and loops to execute the subtest the given number of times with the desired data.

i didn't start with the topic of build integration yet but my plan is to create some testcases, integrate them in build and source control  and run them  every night with different datasources as the data would grow huge if i use only one file.

regards
0
Cody
Telerik team
answered on 03 Dec 2010, 01:01 AM
Hello karl,

I forgot to clarify previously... yes it would have been more appropriate to post this in the Dev Edition forum. We actually prefer customers posting in the forum for the product they are actually using, even coding questions like this one.

Now back to your specific test scenario.

Correct, presently each test (both master and subtest) can be bound to only one explicit data source, or use the source of the parent test. I should explain a little how things work under the cover so we can successfully achieve the goal you are seeking.

When you bind a test to an Excel spreadsheet, the tool actually makes a copy of the file and places it into the Data folder that is contained in your test project folder. Thus in the end all data bound tests will draw from files contained in this specific folder. As a result, even relative paths won't work like you envision.

When a test starts it reads all of the data from the datasource, creates a .NET DataTable object out of it, then starts running the test iterating through the rows of data.

This is true for subtests as well. The good news is that the subtest doesn't read its data source until that subtest gains control. So while the parent test is executing, if it can adjust the data in the data source (e.g. swap out the physical file in the Data folder) for a subtest its about to call you can achieve the effect of parameterized data source for your subtests. Using your relative path and filename idea in a column of the parents test can be used here. Have a coded step that takes that string and performs a copy from that path to a static filename in the Data folder actually should work.

On another of your questions, unfortunately, no, data values cannot be used in one of our IF ELSE condition blocks. It will only accept element verifications at present for the IF condition.

Greetings,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
0
karl
Top achievements
Rank 1
answered on 03 Dec 2010, 09:45 AM
hello

ok, i will post my feature threads in the dev forum section.

i thought to use relative path so the test work on buildserver even if changes in the build definition occur.
as i didn't start the topic of build integration i don't know how the test sources and data is organized after checkout.

would it be possible to manipulate the DataTable directly?
for example save the paths of the excel files and later open them and assign the data to the test data table?

i try to gather as much information about the organization of the tests, data and so on to be able to plan a testing strategy.
the final goal i want to achieve is to have one test and feed it with different data so i can test the happy path, edge values, wrong values and so on.

can you provide me with a small code sample of how and when (in which event)  to exchange the data file for the master and sub test ?

regards
0
Cody
Telerik team
answered on 04 Dec 2010, 06:23 PM
Hi karl,

I attached a sample project as a demonstration how to swap out the data file being feed into the subtest. The main test is data driven and the data specifies which file to feed into subtest. It then performs a file copy to the right destination, then calls the subtest.

In a near future version you will be able to manipulate the DataTable directly, but not in the currently released version.

All the best,
Cody
the Telerik team
Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Tags
General Discussions
Asked by
karl
Top achievements
Rank 1
Answers by
Cody
Telerik team
karl
Top achievements
Rank 1
Share this question
or