AutomationCodeGenerator.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.WebDriver;
  3. import org.openqa.selenium.WebElement;
  4. import org.openqa.selenium.support.ui.ExpectedConditions;
  5. import org.openqa.selenium.support.ui.WebDriverWait;
  6. public class AutomationCodeGenerator {
  7. public WebDriver fillFieldsOnOppCreatePage(WebDriver driver, String path, Logger logger, String oppName, String crID, String closeDt, String sellingCountryval, String localCurrencyVal, String IndustrySubSegmentValue) {
  8. // Data Preparation
  9. // Get input data from Excel
  10. // Implement the logic for filling fields on the "Create Opportunity" page based on the pseudo code provided
  11. // Step 1: Fill Opportunity Name
  12. WebElement opportunityNameField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("opportunityName")));
  13. opportunityNameField.sendKeys(oppName);
  14. // Step 2: Fill Customer Relationship
  15. WebElement customerRelationshipField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("customerRelationship")));
  16. customerRelationshipField.sendKeys(crID);
  17. customerRelationshipField.sendKeys(Keys.RETURN); // Trigger autocomplete or dropdown selection
  18. new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeSelected(By.cssSelector("option[value='" + crID + "']")));
  19. // Step 3: Fill Close Date
  20. WebElement closeDateField = new WebDriverWait(driver, 10).until(ExpectedConditions.visibilityOfElementLocated(By.id("closeDate")));
  21. closeDateField.sendKeys(closeDt);
  22. // Step 4: Select Selling Country
  23. ((JavascriptExecutor) driver).executeScript("document.querySelector('#sellingCountry').click();");
  24. new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + sellingCountryval + "']"))).click();
  25. // Step 5: Select Local Currency
  26. ((JavascriptExecutor) driver).executeScript("document.querySelector('#localCurrency').click();");
  27. new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + localCurrencyVal + "']"))).click();
  28. // Step 6: Select Industry Sub Segment
  29. ((JavascriptExecutor) driver).executeScript("document.querySelector('#industrySubSegment').click();");
  30. new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("option[value='" + IndustrySubSegmentValue + "']"))).click();
  31. // Return modified WebDriver instance
  32. return driver;
  33. }
  34. }