Question: Customer Registration - TestNG with Data Provider Objectives : To understand the concept behind TestNG and working with data providers . URL : http://webapps.tekstac.com/CustomerRegistration_4284/ Test

Customer Registration - TestNG with Data Provider

Objectives :

To understand the concept behindTestNGand working withdata providers.

URL: http://webapps.tekstac.com/CustomerRegistration_4284/

Test Procedure:

Use the template code.

Only in the suggested section add the code to,

In classCustomerRegistration,

1) Method 'createDriver'

create the driver using class DriverSetup Assign it to static variable 'driver'.


2) Method, 'usersData'

This method should parse data fromCustomers.xlsx.

Annotate this method withdata provider name as "Customers".Store the parsed data in a 2-D array variable,'excelData'and return it.

3) Method 'testUser'

Annotate this method withdata provider name as "Customers". Locate the form web elements. Send the excel data as value. Submit the form.


4) Use the below methods to assert their respective values located on the "Registered Successfully" pageagainst the excel data,

  • testName
  • testDOB
  • testPhone
  • testGender

If case of assert failure, add the custom failure message mentioned in the code snippet.

5) Method 'checkUser'=>Invoke the TestNG ONLY using this method

Excel Sheet Name :customers


F15 fx A B C 1 Johnson 9876543456 12/10/1982 male 2 3

===============================================================

/* IMPORTANT:- DriverSetup --getWebDriver()

-------------------------------------------------

PLEASE DO NOT MAKE ANY CHANGES OR MOFICATIONS IN THIS PROGRAM */


import org.openqa.selenium.WebDriver;

import org.openqa.selenium.By;


import org.openqa.selenium.firefox.FirefoxBinary;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.firefox.FirefoxOptions;

import org.openqa.selenium.firefox.FirefoxProfile;

import org.openqa.selenium.firefox.*;

import org.testng.annotations.AfterClass;

import org.testng.annotations.BeforeClass;

import org.testng.annotations.Parameters;

public class DriverSetup

   private static WebDriver driver;

   public static WebDriver getWebDriver()

   {

      System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");

      FirefoxBinary firefoxBinary = new FirefoxBinary();

      firefoxBinary.addCommandLineOptions("--headless");

      FirefoxProfile profile=new FirefoxProfile();

      //profile.setPreference("marionette.logging", "TRACE");

      FirefoxOptions firefoxOptions = new FirefoxOptions();

      firefoxOptions.setBinary(firefoxBinary);

      firefoxOptions.setProfile(profile);

      driver=new FirefoxDriver(firefoxOptions);

      String baseUrl = "http://webapps.tekstac.com/CustomerRegistration_4284/";

      driver.get(baseUrl);

      return driver;

   }

}


==========================================================

 

   

     

   

 


==============================================

import static org.junit.Assert.assertEquals;


import java.io.File;

import java.io.FileInputStream;

import java.util.ArrayList;

import java.util.Iterator;

import java.util.List;


import org.apache.poi.ss.usermodel.DataFormatter;

import org.apache.poi.ss.usermodel.DateUtil;

import org.apache.poi.xssf.usermodel.XSSFCell;

import org.apache.poi.xssf.usermodel.XSSFRow;

import org.apache.poi.xssf.usermodel.XSSFSheet;

import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.support.ui.Select;

import org.testng.TestNG;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.BeforeSuite;

import org.testng.annotations.DataProvider;

import org.testng.annotations.Listeners;

import org.testng.annotations.Test;

import org.testng.collections.Lists;

import j..>@Listeners(FeatureTest.class)           //DO NOT remove or alter this line. REQUIRED FOR TESTING

public class CustomerRegistration{     //DO NOT Change the class Name


   //Use the below declarations

   static WebDriver driver;

   static String[][] excelData = null;



   public void createDriver(){ //DO NOT change the method signature

      //Annotate this with BeforeSuite

      //Create driver and assign it to 'static' driver variable

   }


   public Object[][] usersData(){         //DO NOT change the method signature

      //Annotate this method with data provider name as "Customers".

      //Parse data from Customers.xlsx, store in excelData variable and return the 2-dimensional array

   }      


   void testUser (String Uname, String Uphoneno, String Udob, String gender, String Uaddr){  //DO NOT change the method signature

      //Annotate this method with data provider name as "Customers". Add 'priority=0'

      //Fill the form using data parsed from excel and submit

   }


   @Test(testName="testName",priority=1)

   void testName (){  //DO NOT change the method signature

       // Locate the name in "Registered Successfully page". Assert it against the excel data.Set 'Name doesnt match 'custom failure message in assert 

   }

   @Test(testName="testPhone",priority=2)

   void testPhone(){    //DO NOT change the method signature

         // Locate the phone in "Registered Successfully page". Assert it against the excel data.Set 'Name doesnt match 'custom failure message in assert 

   }

   @Test(testName="testDOB",priority=3)

   void testDOB (){ //DO NOT change the method signature

         // Locate the date of birth in "Registered Successfully page". Assert it against the excel data.Set 'Name doesnt match 'custom failure message in assert 

   }

   @Test(testName="testGender",priority=4)

   void testGender(){ //DO NOT change the method signature

         // Locate the gender in "Registered Successfully page". Assert it against the excel data.Set 'Name doesnt match 'custom failure message in assert 

   }


   public void checkUser() {  //DO NOT change the method signature

      //Invoke the test using TestNG ONLY HERE.

   }


   public static void main(String[] args) {

      CustomerRegistration = new CustomerRegistration();

      //Implement code here   

   }

}

F15 fx A B C 1 Johnson 9876543456 12/10/1982 male 2 3 D E F Mumbai

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!