fillFieldsOnOppCreatePage.java 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package genlitex_demo.automation_code;
  2. import java.io.File;
  3. import java.io.IOException;
  4. import java.time.Duration;
  5. import java.util.List;
  6. import org.apache.poi.EncryptedDocumentException;
  7. import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.JavascriptExecutor;
  10. import org.openqa.selenium.WebDriver;
  11. import org.openqa.selenium.WebElement;
  12. import org.openqa.selenium.support.FindBy;
  13. import org.openqa.selenium.support.PageFactory;
  14. import org.openqa.selenium.support.ui.ExpectedConditions;
  15. import org.openqa.selenium.support.ui.Select;
  16. import org.openqa.selenium.support.ui.WebDriverWait;
  17. import com.Utility.MethodFactory;
  18. import com.Utility.ReadExcel;
  19. import com.Utility.UtilMethods;
  20. public class fillFieldsOnOppCreatePage {
  21. private WebDriver driver;
  22. private WebDriverWait wait;
  23. private ReadExcel excel;
  24. public fillFieldsOnOppCreatePage(WebDriver driver) {
  25. this.driver = driver;
  26. this.wait = new WebDriverWait(driver, Duration.ofSeconds(30));
  27. PageFactory.initElements(driver, this);
  28. }
  29. public WebDriver fillFieldsOnOppCreatePage(String path, ExtentTest logger, String oppName, String crID,
  30. String closeDt, String sellingCountryval, String localCurrencyVal, String IndustrySubSegmentValue,
  31. String excelName, String sheetName, int row) throws InterruptedException, EncryptedDocumentException,
  32. InvalidFormatException, IOException {
  33. excel = ReadExcel.excel(path, excelName);
  34. String opportunityName = excel.getCellData(sheetName, oppName, row);
  35. String accountID = excel.getCellData(sheetName, crID, row);
  36. String closeDate = excel.getCellData(sheetName, closeDt, row);
  37. String sellingCountry = excel.getCellData(sheetName, sellingCountryval, row);
  38. String localCurrency = excel.getCellData(sheetName, localCurrencyVal, row);
  39. String IndustrySubSegment = excel.getCellData(sheetName, IndustrySubSegmentValue, row);
  40. // Set Opportunity Name
  41. UtilMethods.waitTillElementIsVisible(logger, driver, opportunityNameOnCreateOppPage);
  42. UtilMethods.setText(logger, driver.findElement(By.id("opportunityNameOnCreateOppPage")), opportunityName);
  43. // Set Customer Relationship
  44. UtilMethods.waitTillElementIsVisible(logger, driver, customerRelationshipOnCreateOppPage);
  45. UtilMethods.setText(logger, driver.findElement(By.id("customerRelationshipOnCreateOppPage")), accountID);
  46. UtilMethods.clickEnter(logger, driver.findElement(By.id("customerRelationshipOnCreateOppPage")), "Customer Relationship");
  47. // Set Close Date
  48. UtilMethods.waitTillElementIsVisible(logger, driver, closeDateOnCreateOppPage);
  49. UtilMethods.setText(logger, driver.findElement(By.id("closeDateOnCreateOppPage")), closeDate);
  50. // Set Selling Country
  51. WebElement sellingCountryDropdown = driver.findElement(By.id("sellingCountryDropdown"));
  52. ((JavascriptExecutor) driver).executeScript("arguments[0].click();", sellingCountryDropdown);
  53. WebElement sellingCountryOption = driver.findElement(By.xpath("//option[text()='" + sellingCountry + "']"));
  54. sellingCountryOption.click();
  55. // Set Local Currency
  56. WebElement localCurrencyDropdown = driver.findElement(By.id("localCurrencyDropdown"));
  57. ((JavascriptExecutor) driver).executeScript("arguments[0].click();", localCurrencyDropdown);
  58. WebElement localCurrencyOption = driver.findElement(By.xpath("//option[text()='" + localCurrency + "']"));
  59. localCurrencyOption.click();
  60. // Set Industry Sub Segment
  61. WebElement industrySubSegmentDropdown = driver.findElement(By.id("industrySubSegmentDropdown"));
  62. ((JavascriptExecutor) driver).executeScript("arguments[0].click();", industrySubSegmentDropdown);
  63. if (IndustrySubSegment.contains("'")) {
  64. String[] subSegments = IndustrySubSegment.split("'");
  65. for (String subSegment : subSegments) {
  66. WebElement subSegmentOption = driver.findElement(By.xpath("//option[text()='" + subSegment + "']"));
  67. subSegmentOption.click();
  68. }
  69. } else {
  70. WebElement industrySubSegmentOption = driver.findElement(By.xpath("//option[text()='" + IndustrySubSegment + "']"));
  71. industrySubSegmentOption.click();
  72. }
  73. return driver;
  74. }
  75. }