Currently I am using Selenium 3.0 with the TestNG framework and a page factory setup for maintaining the page setup. I have been using wini for fetching data from the text file using section and option name.

  • What are alternative ways for a Data-Driven approach?
  • How can use I them for running same test case but with different set of data?

Please elaborate with examples Here is how i am currently accessing it with section and option name.

   @BeforeClass (alwaysRun=true)
   public void setup(ITestContext context) throws Exception{
            ClassLoader classLoader = getClass().getClassLoader();
            File file = new File(classLoader.getResource("datafile.txt").getFile());
            crmdatafile = new ReadData(file.getAbsolutePath());                          

   public void setcontact(){
     Section section= crmdatafile.data.get("Contact_Buyer");                                                                                                                             

This is how i have been fetching data from wini data text file where my datafile looks like

Title = Madam
Contact_language = French    

how can i achieve this using dataprovider to pass multiple values(many section and option names)

  • I have re-worded your question slightly so that it leads to less "opinionated" answers. Could you link to this wini library you are talking about? Jan 31 '17 at 11:20

If you are using TestNG have a look at DataProviders. This way you can repeat a test for each data point you have.

Example code:

public static var data:Array = [ [ 0, 0 ], [ 1, 2 ], [ 2, 4 ] ];

[Test( dataProvider="data")]
public function doubleTest( value1:int, value2:int ):void {
    assertEquals( value1, value2 * 2 );

If non-technical users need to update the data you could later move the data:Array to another source, like Excel or a Wiki-table (e.g. FitNesse).

  • I have added details on how i fetch the data from text file using wini, let me know how this can be achieved with dataprovider. Data proivder can pass section names , currently achieved by Section section= crmdatafile.data.get("Contact_Buyer"); and Section section= crmdatafile.data.get("Contact_owner"); now my testcase will read 2 keysets and run the same test twice with the values inside the keyset Feb 2 '17 at 11:46

You could try something like how the faker Gem does with locales?


example like: https://github.com/stympy/faker/blob/master/lib/locales/ca.yml

Have you different data sets as diff yml files and based on environment it picks the dif yml?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.