Professional Documents
Culture Documents
java
/* DO NOT CHANGE THIS CLASS. THIS CLASS IS FOR REFERENCE ONLY */
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.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
ExcelUtils.java
import java.io.*;
import java.io.FileInputStream;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.poi.ss.usermodel.CellType;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
public static String[][] readExcelData(String fileName, String sheetName) throws Exception { //Do not change th
e method signature
//Get the excel file path (note: the excel file is located under 'CustomerRegistration/src' directory)
//Using the fileName and sheetName passed to this method
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" >
<test name="Test">
<classes>
<!-- Add the class name to be tested -->
<class name="TestValidCustomerRegistration"/>
</classes>
</test>
</suite>
TestValidCustomerRegistration.java
import java.io.File;
import java.io.FileInputStream;
import java.util.Iterator;
import java.util.List;
import static org.testng.Assert.assertEquals;
import org.testng.TestNG;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import org.testng.collections.Lists;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
//return driver
return driver;
}
//Call the method 'readExcelData' in class 'ExcelUtils' using file name 'CustomerRegistration.xlsx' and sheet n
ame 'CustomerDetails'
//Return the value
return ExcelUtils.readExcelData("CustomerRegistration.xlsx","CustomerDetails");
}
//Using 'setFormValues' object set the form values passed as the parameter using DataProvider method 'getValid
CustomerData'
setformValues.setCustomerName(custname);
//Use 'setFormValues' object and call the method setCustomerName() and pass the 'custname' as parameter.
setformValues.setCustomerMobile(custmobile);
//Use 'setFormValues' object and call the method setCustomerMobile() and pass the 'custmobile' as parameter.
setformValues.setCustomerDOB(custdob);
//Use 'setFormValues' object and call the method setCustomerDOB() and pass the'custdob' as parameter.
setformValues.setCustomerGender(custgender);
//Use 'setFormValues' object and call the method setCustomerGender() and pass the 'custgender' as parameter.
setformValues.setCustomerAddress(custaddr);
//Use 'setFormValues' object and call the method setCustomerAddress() and pass the 'custaddr' as parameter.
setformValues.SubmitForm();
//Use 'setFormValues' object and call the method SubmitForm() to click the 'Register' button.
custnametxt = driver.findElement(By.xpath("//table/tbody/tr[1]/td[2]")).getText();
custmobiletxt = driver.findElement(By.xpath("//table/tbody/tr[2]/td[2]")).getText();
//Locate the submitted customer name displayed after form submit, retrieve and store customer name in a static v
ariable 'custnametxt'.
//Locate the submitted customer mobile displayed after form submit, retrieve and store customer mobile in a stati
c variable 'custmobiletxt'.
CustomerDetails.java
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.Listeners;
@Listeners
public class CustomerDetails { //Do not change the class name
//Constructors are already given. If required, you can add more code into it but do NOT remove the existing cod
e.
public CustomerDetails(){}
//locate and fill the input box of the 'Name' with 'name'
driver.findElement(By.id("name")).sendKeys(name);
}
public void setCustomerMobile(String mobile) {
//locate and fill the input box of the 'Mobile' with 'mobile'
driver.findElement(By.id("mobile")).sendKeys(mobile);
}
By dobElement = By.id("dob");
driver.findElement(dobElement).sendKeys(dob);
}
//locate and click the radio button 'Gender' based on 'gender' value
if(gender.equalsIgnoreCase("Male")){
driver.findElement(By.id("male")).click();
}
else if(gender.equalsIgnoreCase("Female")){
driver.findElement(By.id("female")).click();
}
//locate and fill the input box of the 'Address' with 'addr'
driver.findElement(By.id("address")).sendKeys(addr);
}