package automation_admin; import java.io.File; import java.io.IOException; import java.time.Duration; import java.util.ArrayList; import java.util.List; import java.util.Set; import org.apache.poi.EncryptedDocumentException; import org.apache.poi.openxml4j.exceptions.InvalidFormatException; import org.openqa.selenium.By; import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.WindowType; import org.openqa.selenium.interactions.Actions; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import org.testng.annotations.Test; import org.testng.asserts.SoftAssert; import com.Utility.MethodFactory; import com.Utility.ReadExcel; import com.Utility.TakeScreenshot; import com.Utility.TestNGCreation; import com.Utility.UtilMethods; import com.relevantcodes.extentreports.ExtentTest; import com.relevantcodes.extentreports.LogStatus; public class fillFieldsOnOppCreatePage { public static WebDriver fillFieldsOnOppCreatePage(WebDriver driver, String path, ExtentTest logger, String oppName, String crID, String closeDt, String sellingCountryval, String localCurrencyVal, String IndustrySubSegmentValue, String excelName, String sheetName, int row) throws InterruptedException, EncryptedDocumentException, InvalidFormatException, IOException { ReadExcel excel = ReadExcel.readExcel(System.getProperty("user.dir") + "/ExcelFiles/" + excelName + ".xlsx", sheetName, row); String opportunityName = excel.getCellData(oppName); String accountID = excel.getCellData(crID); String closeDate = excel.getCellData(closeDt); String sellingCountry = excel.getCellData(sellingCountryval); String localCurrency = excel.getCellData(localCurrencyVal); String IndustrySubSegment = excel.getCellData(IndustrySubSegmentValue); logger.log(LogStatus.INFO, "closeDate from excel is:" + closeDate); // Setting Value for Opportunity Name field UtilMethods.waitTillElementIsVisible(logger, driver, opportunityNameOnCreateOppPage); UtilMethods.setText(logger, opportunityNameOnCreateOppPage, opportunityName); // Setting Value for Customer relationship field Thread.sleep(4000); UtilMethods.waitTillElementIsVisible(logger, driver, customerRelationshipOnCreateOppPage); Thread.sleep(4000); UtilMethods.setText(logger, customerRelationshipOnCreateOppPage, accountID); Thread.sleep(4000); UtilMethods.clickEnter(logger, customerRelationshipOnCreateOppPage, "Customer Relationship"); Thread.sleep(4000); UtilMethods.waitTillElementIsVisible(logger, driver, RT_WinLossSurveyFindingsPage.cRSelection); Thread.sleep(3000); UtilMethods.clickOn(logger, cRSelection, "CR"); Thread.sleep(3000); // Setting Value for Close Date UtilMethods.waitTillElementIsVisible(logger, driver, closeDateOnCreateOppPage); Thread.sleep(3000); UtilMethods.setText(logger, closeDateOnCreateOppPage, closeDate); Thread.sleep(5000); JavascriptExecutor executor = (JavascriptExecutor) driver; WebElement element1 = driver.findElement( By.xpath("//label[text()='Selling Country/Location']/ancestor::lightning-combobox//input | //label[text()='Selling Country/Location']/ancestor::lightning-combobox//button[@name='SellingCountry__c']")); Thread.sleep(2000); UtilMethods.waitTillElementIsVisible(logger, driver, element1); UtilMethods.clickTheRespectiveButtonByJavaScriptExecutor(driver, logger, element1, "Selling Country"); WebElement selectionElement = driver.findElement(By .xpath("//label[text()='Selling Country/Location']//ancestor::div[1]//div[@role='listbox']//span/span[text()='" + sellingCountry + "']")); executor.executeScript("arguments[0].click();", selectionElement); // local currency WebElement element2 = driver .findElement(By.xpath("//label[text()='Local Currency']/ancestor::lightning-combobox//button")); UtilMethods.waitTillElementIsVisible(logger, driver, element2); UtilMethods.clickTheRespectiveButtonByJavaScriptExecutor(driver, logger, element2, "Local Currency"); WebElement selectionElement1 = driver.findElement( By.xpath("//label[text()='Local Currency']//ancestor::div[1]//div[@role='listbox']//span/span[text()='" + localCurrency + "']")); executor.executeScript("arguments[0].click();", selectionElement1); UtilMethods.waitTillElementIsVisible(logger, driver, industrySubSegmentOnCreateOppPage); UtilMethods.clickTheRespectiveButtonByJavaScriptExecutor(driver, logger, industrySubSegmentOnCreateOppPage, "ISS"); Thread.sleep(2000); if (IndustrySubSegment.equals("H&PS HEALTH-COMM'L PAYER") || IndustrySubSegment.equals("H&PS HEALTH-COMM'L PROVIDER")) { String IndustrySubSegmentData[] = IndustrySubSegment.split("'"); UtilMethods.clickTheRespectiveButtonByJavaScriptExecutor(driver, logger, driver.findElement(By .xpath("//span[text()='Industry Sub Segment']/../../following-sibling::div//div[contains(text(),'" + IndustrySubSegmentData[0] + "') and contains(text(),'" + IndustrySubSegmentData[1] + "')]")), "industry sub segment"); } else { UtilMethods.clickTheRespectiveButtonByJavaScriptExecutor(driver, logger, driver.findElement( By.xpath("//span[text()='Industry Sub Segment']/../../following-sibling::div//div[text()='" + IndustrySubSegment + "']")), "industry sub segment"); } return driver; } }