Datadriven Testing

Hii all Good Morning,

How to use multiple testcases in single excel sheet , i was using datadriver for datadriven testing .

Hi Siva,

There are various approaches to data driven tests as covered in the User Guide:

you mentioned you were using datadriver which is the suggested approach for when using excel sheet, is there a reason you’ve stopped using datadriver?

It’s not clear from your question what information your after or what problem you might be having, can you clarify?

Dave.

Hi Dave

Requirement: we have multiple testcase.robot file and we want to maintain only one data sheet for the same xlsx file

But while using data driver to achive data driven approch we not able to execute it on conditional bassed it is iterating each row and making it a testcase

so we need how we can customize data driver library so that it work on condition

to make more clear

let suppose we have 5 row but 2 row has the test data of testcase one and remaining three row has test data for testcases 2 we want the execution should perform on respective data

but while using data driver it is iterating all row

Hi,

The Datadriver has written that " These tests are very useful when there is a need to test the same scenario with different input and/or output data ."

What you describe are two tests cases (input lines 1 and 2 for test1, then input lines 3 to 5 for test2).

I think the Datadriver will just iterate based on the Template keyword given.
But I assume your question is due to the fact that test1 and test2 are near?
What you could eventually do, is add a variable in your excel file (test1 or test2), and in your template use a IF statement based on this value to execute respectively what’s test1, test2 or both.

Regards
Charlie

Hi Amit,

In your case, as @CharlieScene pointed out, Datadriver is not the tool for your requirement.

There’s a number of ways you can manage it:

  • use a ExcelLibrary, there appear to be several, this one robotframework-excellib appears to be the most recently miantained
    • with this approach you’ll probably want to have a column to flag the data as consumed and have each test mark the data as consumed as it uses it
  • Use a database with Database Library, again have a column that marks the data consumed, with this approach you could potentially have a sql view that when queried, just returns the first unused result and makes it consumed for you
  • Use TestDataTable, this approach is like the previous one, though a little simpler as TestDataTable as when you request the data from a column it automatically removes (consumes) the value for you.

There’s no best answer for everyone, so I’ve given you a few options,

Dave.

1 Like