I have 3 dropdowns with multiple components in the UI. Have incorporated data driven java selenium framework, data is fetched from excel sheet:
Excel sheet- where data is fetched
This data I am taking in to main class:
public class TC01_newDesign extends TestBase{
login obj_login;
createNewDesign obj_CreateNewDesign;
saveDesign obj_SaveDesign;
capacitorUnit obj_capacitorUnit;
logout obj_logout;
@Test (priority=1, description = "Login Functionality")
public void login() {
log.info("Open CapDes URL.");
driver.get(data.getProperty("base.url"));
obj_login = new login (driver);
ExcelBase.setExcelFileSheet("Capacitor_unit");
obj_login.enter_username(ExcelBase.getCellData(3,1));
obj_login.enter_password(ExcelBase.getCellData(3,2));
obj_login.select_login();
}
@Test (priority=2, description = "Create new Design")
public void createNewDesign() {
log.info("Create New Design");
obj_CreateNewDesign = new createNewDesign (driver);
obj_CreateNewDesign.select_newButton();
obj_CreateNewDesign.select_productDropDown();
obj_CreateNewDesign.wait_dropdown();
obj_CreateNewDesign.choose_productDropDown(ExcelBase.getCellData(3,4));
obj_CreateNewDesign.select_powerQCDropDown();
obj_CreateNewDesign.wait_dropdown();
obj_CreateNewDesign.choose_powerQCDropDown(ExcelBase.getCellData(3,5));
obj_CreateNewDesign.select_FeederFactoryDropDown();
obj_CreateNewDesign.wait_dropdown();
obj_CreateNewDesign.choose_FeederFactoryDropDown(ExcelBase.getCellData(3,6));
obj_CreateNewDesign.select_okButton();
obj_CreateNewDesign.wait_ok();
}
Then control goes to Page class - Here I want your valuable suggestion to improve the code
public class createNewDesign extends PageBase {
public createNewDesign(WebDriver driver) {
super(driver);
}
WebDriver driver;
// Web Element for New button in left panel
@FindBy(xpath = "//div[@class='v-panel-content v-scrollable']//div[2]//div[1]//div[1]//div[1]//span[1]//img[1]")
WebElement newButton;
// Web Element for Product drop down button
@FindBy(xpath = "//div[@class='v-filterselect v-widget v-filterselect-required v-required v-filterselect-prompt']//div[@class='v-filterselect-button']")
WebElement productDropDown;
/*******************************************************************************************/
// Web Element for chosen product(s) - Capacitor Unit
@FindBy(xpath = "//span[contains(text(),\"Capacitor Unit\")]")
WebElement productChoose1;
// Web Element for chosen product(s) - Capacitor Unit SC
@FindBy(xpath = "//span[contains(text(),\"Capacitor Unit SC\")]")
WebElement productChoose2;
// Web Element for chosen product(s) - Capacitor DC Unit
@FindBy(xpath = "//span[contains(text(),\"Capacitor DC Unit\")]")
WebElement productChoose3;
// Web Element for chosen product(s) - Surge Cap
@FindBy(xpath = "//span[contains(text(),\"Surge Cap\")]")
WebElement productChoose4;
// Web Element for chosen product(s) - QBank-A
@FindBy(xpath = "//span[contains(text(),\"QBank-A\")]")
WebElement productChoose5;
// Web Element for chosen product(s) - QBank-A SC
@FindBy(xpath = "//span[contains(text(),\"QBank-A SC\")]")
WebElement productChoose6;
// Web Element for chosen product(s) - QBank-AS
@FindBy(xpath = "//span[contains(text(),\"QBank-AS\")]")
WebElement productChoose7;
// Web Element for chosen product(s) - QBank-BS
@FindBy(xpath = "//span[contains(text(),\"QBank-BS\")]")
WebElement productChoose8;
// Web Element for chosen product(s) - QBank-CS
@FindBy(xpath = "//span[contains(text(),\"QBank-CS\")]")
WebElement productChoose9;
// Web Element for chosen product(s) - QBank-B
@FindBy(xpath = "//span[contains(text(),\"QBank-B\")]")
WebElement productChoose10;
// Web Element for chosen product(s) - QBank-C
@FindBy(xpath = "//span[contains(text(),\"QBank-C\")]")
WebElement productChoose11;
// Web Element for chosen product(s) - Q-Pole
@FindBy(xpath = "//span[contains(text(),\"Q-Pole\")]")
WebElement productChoose12;
// Web Element for chosen product(s) - QBank-PLC
@FindBy(xpath = "//span[contains(text(),\"QBank-PLC\")]")
WebElement productChoose13;
// Web Element for chosen product(s) - QBank-H
@FindBy(xpath = "//span[contains(text(),\"QBank-H\")]")
WebElement productChoose14;
/*******************************************************************************************/
// Web Element for Power Quality Center drop down
@FindBy(xpath = "//div[@class='v-filterselect v-widget v-filterselect-required v-required v-filterselect-prompt']//div[@class='v-filterselect-button']")
WebElement powerQCDropDown;
/*******************************************************************************************/
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose1;
// Web Element for Power Quality Center Option - 10th Of Ramadan, Egypt
@FindBy(xpath = "//span[contains(text(),\"10th Of Ramadan, Egypt\")]")
WebElement powerQCChoose2;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose3;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose4;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose5;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose6;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose7;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose8;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose9;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose10;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose11;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose12;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose13;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose14;
// Web Element for Power Quality Center Option - Ludvika, Sweden
@FindBy(xpath = "//span[contains(text(),\"Ludvika, Sweden\")]")
WebElement powerQCChoose15;
/*******************************************************************************************/
// Web Element for Feeder factory drop down
@FindBy(xpath = "//div[@class='v-filterselect v-widget v-filterselect-required v-required v-filterselect-prompt']//div[@class='v-filterselect-button']")
WebElement FeederFactoryDropDown;
// Web Element for Feeder factory Option - TBA
@FindBy(xpath = "//span[contains(text(),\"Xi'an, China\")]")
WebElement FeederFactoryChoose;
// Web Element for OK (Submit) button
@FindBy(xpath = "//div[@class='v-button v-widget primary v-button-primary']")
WebElement okButton;
// Web Element for waiting for drop down element
@FindBy(xpath = "//div[@class='v-filterselect-suggestmenu']")
WebElement waitdropdown;
// Web Element for waiting for OK
@FindBy(xpath = "//td[@class='v-formlayout-captioncell']//span[contains(text(),'Unit voltage (V)')]")
WebElement waitok;
/*******************************************************************************************
* All Methods for performing actions
* @return
*******************************************************************************************/
public void select_newButton(){
log.info("Select New design button");
newButton.click();
}
public void select_productDropDown(){
productDropDown.click();
}
public void choose_productDropDown(String data){
log.info("Product Selected: " + data);
if(data.contains("Capacitor Unit"))
{
productChoose1.click();
}
if(data.contains("Capacitor Unit SC"))
{
productChoose2.click();
}
if(data.contains("Capacitor DC Unit"))
{
productChoose3.click();
}
if(data.contains("Surge Cap"))
{
productChoose4.click();
}
if(data.contains("QBank-A"))
{
productChoose5.click();
}
if(data.contains("QBank-A SC"))
{
productChoose6.click();
}
if(data.contains("QBank-AS"))
{
productChoose7.click();
}
if(data.contains("QBank-BS"))
{
productChoose8.click();
}
if(data.contains("QBank-CS"))
{
productChoose9.click();
}
if(data.contains("QBank-B"))
{
productChoose10.click();
}
if(data.contains("QBank-C"))
{
productChoose11.click();
}
if(data.contains("Q-Pole"))
{
productChoose12.click();
}
if(data.contains("QBank-PLC"))
{
productChoose13.click();
}
if(data.contains("QBank-H"))
{
productChoose14.click();
}
else
log.error("Enter valid Product name");
}
public void select_powerQCDropDown(){
powerQCDropDown.click();
}
public void choose_powerQCDropDown(String data){
log.info("Power Quality Centre selected: "+ data);
if(data.contains("Ludvika, Sweden"))
{
powerQCChoose1.click();
}
if(data.contains("10th Of Ramadan, Egypt"))
{
powerQCChoose2.click();
}
}
public void select_FeederFactoryDropDown(){
FeederFactoryDropDown.click();
}
public void choose_FeederFactoryDropDown(String data){
log.info("Feeder Factory selected: "+data);
FeederFactoryChoose.click();
}
public void select_okButton(){
log.info("Select Ok button");
okButton.click();
}
public void wait_dropdown(){
TestBase.wait.until(ExpectedConditions.visibilityOf(waitdropdown));
}
public void wait_ok(){
TestBase.wait.until(ExpectedConditions.visibilityOf(waitok));
}
}
As I am again taking the same name in both xpaths of the drop down and in If loop for different drop down.
Basically what I want is the value from Excel once taken as input, has to be handled efficiently in the code.
Disclaimer: I am new to Java-Selenium, hence asking for this.