how to implement data provider

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to implement data provider

Kritika Gupta

I am new to TESTNG, and want to implement my project on TESTNG framework.
I have created one OR CLASS ( All the page elements), One Excel sheet ( Test data for all the page elements), Test method( calling the page elemnents), One excel method( to pass the test data to OR via Test method).

Now I have written belwo code -

1) read the test data excel sheet to get the total no of rows
2) if test case Flag is set as M it will take the case and pass the row no to the specific test case based on the category 
3) Test case is using OR which will pass the specific data set
4) If Flag is N it will check the next excel sheet row
5) Meanwhile if some error comes during execution it should jump to next test case quiting the driver

How can I achive it using data provider or TESTNG. Can anyone please guide me .

 public static void findtestcase() throws Exception {
  EOTdata.setExcelFile("somepath //EOT_TestData.xlsx");
  int totalrows = EOTdata.ExcelWSheet.getPhysicalNumberOfRows();
  System.out.println("total rows" + totalrows);
  for (int i = 1; i < totalrows; i++) {
   System.out.println(i);
   try {
    System.out.println("M or N - " + EOTdata.ExcelWSheet.getRow(i).getCell(0).getStringCellValue());
    if (EOTdata.ExcelWSheet.getRow(i).getCell(0).getStringCellValue().equalsIgnoreCase("M")) {

     String TCName = EOTdata.ExcelWSheet.getRow(i).getCell(1).getStringCellValue();
     int firstNchars = 5;
     TCName = TCName.substring(0, Math.min(TCName.length(), firstNchars));
     System.out.println(TCName);
     switch (TCName) {
     case "TC001":
      EATradeCreation.CreationEATrade(i); //Test case which is uding OR class and passing the row no of excel sheet to get that row data
      System.out.println("Completed " + i + "th case");
      break; // EATradeCreation.CreationEATrade();
     case "TC002":
      System.out.println("20");
      break;
     case "TC003":
      System.out.println("30");
      break;
     default:
      System.out.println("Not in 10, 20 or 30");
     }

    }

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.