Forum Discussion

kishore_konka's avatar
kishore_konka
Occasional Contributor
17 years ago

Data Driven from Excel

HI ,I am trying to do Data drivn  from Excel sheet , when I run the test ,test is running only fro the last row record set.Please let me know how to loop the test for all the rows in the data sheet.

I am trying to paramatrize the test like in the following steps

1)Crated Project
2)Created test Suit and test Case
3)Created Test Request
4)Create data source from Excel and Paramatrized the test rquest
5)Created data source loop like  data source step as "Excel" and  Target step as Test Request.

4 Replies

  • Hi,

    in order to loop through all data source (excel) rows you should do the following :
    1. create DataSource step and add properties which you will use in later request TestStep like 'name' and 'address'
    2. create Test Request step and use property expansion like ${DataSource#name} and ${DataSource#address}
    3. create DataSource Loop , for source choose DataSource and for target Test Request

    let us know if this helps

    regards
    Nebojsa
    eviware.com
  • kishore_konka's avatar
    kishore_konka
    Occasional Contributor
    Thanks for timely Help , now the test is looping for  all the rows in the data sheet. I am having one more issue.

    I need to add more than 500 property names for each test case ,but is  tedious process to add that many property’s  for each test case by clicking. Please let me know is there any option in tool to import  the  properties names from external source like Excel. I will be having all property name's in excel.

    Please let me know way to achieve the above .
  • Hi,
    I am getting null pointer exception when i follow the above steps mentioned steps.Test is running for 1st row and for second iteration it is showing testcase failed due to null pointer exception.
    Can any body help me in this....
  • kishore.konka wrote:
    I need to add more than 500 property names for each test case ,but is  tedious process to add that many property’s  for each test case by clicking. Please let me know is there any option in tool to import  the  properties names from external source like Excel.


    There isn't a way to do it using the tool itself, but you can do it with a Groovy TestStep a bit like this:

    Assume you have a dataSource for your property names, called something like 'propertyNames', that exports each row as a property on itself called 'name'.

    def dataSource = testRunner.testCase.testSteps['propertyNames'];

    getNewProperty = {

        if (!dataSource.next(testRunner, context)) {
            dataSource.run(testRunner, context);
        }

        return dataSource.properties['name'].value;

    }

    getNewValue = {
        // Put whatever you want in here!
        // You could even have your Excel datasource export the name/value pairs, and fold this in.
    }

    for (int i = 0; i < 500; i++) {
        testRunner.testCase.setPropertyValue(getNewProperty(), getNewValue());
    }


    NOTE that this is cribbed from my own projects but I haven't run the code precisely as written - should be fine though.