2

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());                          
   }

   @Test   
   public void setcontact(){
     Section section= crmdatafile.data.get("Contact_Buyer");                                                                                                                             
     ContactsPage.Select_Profile_Title(section.get("Title"));
     ContactsPage.Select_Profile_Contactlanguage(section.get("Contact_language")); 
   }

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

[Contact_Buyer]
Title = Madam
Contact_language = French    
etc

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

1
  • 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? Commented Jan 31, 2017 at 11:20

2 Answers 2

0

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).

1
  • 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 Commented Feb 2, 2017 at 11:46
0

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

https://github.com/stympy/faker

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 and acknowledge you have read our privacy policy.

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