AutomationCodeGenerator.java 2.6 KB

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