public static void navigate(String object, String data) { try { Log.info("Navigating to URL"); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get(Constants.URL); } catch (Exception e) { Log.info("Not able to navigate --- " + e.getMessage()); DriverScript.bResult = false; } }
public static WebElement prospectList_saveProspect(WebDriver driver) throws Exception { WebDriverWait wait = new WebDriverWait(driver, 60); element = driver.findElement(By.xpath("//input[@value='Create prospect']")); element.click(); Log.info("Click on Save to Create New Prospect"); // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Constant.logOutXpath))); Log.info("Waiting for prospect page title to contain id"); wait.until(ExpectedConditions.urlContains("id")); return element; }
public static WebElement prospectList_AddProspectToList( WebDriver driver, String randomName, String emailID) throws Exception { WebDriverWait wait = new WebDriverWait(driver, 60); // Assumption - The newly created Prospect List is always on 1st Row wait.until( ExpectedConditions.textToBePresentInElementLocated( By.xpath(".//*[@id='prospect_row_a0']/td[3]/a"), emailID)); Log.info(driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getText()); Log.info( driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getAttribute("href")); String ProspectID = driver.findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")).getAttribute("href"); Log.info(ProspectID); int endIndex = ProspectID.lastIndexOf("/"); int length = driver .findElement(By.xpath(".//*[@id='prospect_row_a0']/td[3]/a")) .getAttribute("href") .length(); System.out.println("endIndex is " + endIndex); String ActProspectID = ProspectID.substring(endIndex + 1); System.out.println("ActProspectID is " + ActProspectID); if (endIndex != -1) { if (!(ActProspectID.contains("#"))) { // ProspectID = driver.getCurrentUrl().substring(endIndex+1, length); Log.info("Prospect id doesn't contain # " + ProspectID); } } driver.get("https://pi.pardot.com/list/prospect/prospect_id/" + ActProspectID); wait.until( ExpectedConditions.visibilityOfElementLocated( By.xpath("//span[contains(.,'Select a list to add...')]"))); WebElement listDropDown = driver.findElement(By.xpath("//span[contains(.,'Select a list to add...')]")); listDropDown.click(); driver.findElement(By.xpath("//li[text()='" + randomName + "']")).click(); wait.until( ExpectedConditions.textToBePresentInElement(listDropDown, "Select a list to add...")); driver.findElement(By.xpath("//span[contains(.,'Select a list to add...')]")).submit(); return element; }
public static WebElement prospectList_fillFormList(WebDriver driver, String emailID) throws Exception { // Wait for the Add New Prospect form to load WebDriverWait wait = new WebDriverWait(driver, 60); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='email']"))); Log.info("Waiting for Prospect->List->AddProspect New form"); // Fill out Add New Prospect Form element = driver.findElement(By.xpath("//input[@id='email']")); element.sendKeys(emailID); Log.info("--- Filling AddProspect form ---- "); // Select a campaign option Log.info("Filling AddProspect form Selecting Campaign"); Select campaignDropdown = new Select(driver.findElement(By.xpath("//select[@id='campaign_id']"))); List<WebElement> campaignWeblist = campaignDropdown.getOptions(); int cCnt = campaignWeblist.size(); Log.info("Total campaignWeblist is " + cCnt); Random cnum = new Random(); int cSelect = cnum.nextInt(cCnt); campaignDropdown.selectByIndex(cSelect); Log.info("Selected campaignWeblist " + cSelect); Thread.sleep(10); // Select a profile option Select profileDropdown = new Select(driver.findElement(By.xpath("//select[@id='profile_id']"))); List<WebElement> profileWeblist = profileDropdown.getOptions(); int pCnt = profileWeblist.size(); Log.info("Total profileWeblist is " + pCnt); Random pnum = new Random(); int pSelect = pnum.nextInt(pCnt); profileDropdown.selectByIndex(pSelect); Log.info("Selected profileWeblist " + pSelect); Thread.sleep(10); // Clear and Enter a Score Value element = driver.findElement(By.xpath("//input[@id='score']")); element.clear(); element = driver.findElement(By.xpath("//input[@id='score']")); element.sendKeys(Constant.scoreVal); ; Log.info("Enter Score Value " + Constant.scoreVal); // wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h1[contains(.,'*****@*****.**')]"))); return element; }
@BeforeClass public void setUp() throws Exception { // Configuring Log4j logs. new BaseClass(); DOMConfigurator.configure(BaseClass.bLog); // Setting Excel File -- Test Data xls File ExcelUtils.setExcelFile( Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); // Getting the Test Case name, as it will going to use in so many places // The main use is to get the TestCase row from the Test Data Excel sheet sTestCaseName = this.toString(); Log.info(sTestCaseName); sTestCaseName = Utils.getTestCaseName(this.toString()); Log.info(sTestCaseName); Log.startTestCase(sTestCaseName); testStep = new HelperFunction(); }
public static void closeBrowser(String object, String data) { try { Log.info("Closing the browser"); driver.quit(); } catch (Exception e) { Log.error("Not able to Close the Browser --- " + e.getMessage()); DriverScript.bResult = false; } }
public static void waitFor(String object, String data) throws Exception { try { Log.info("Wait for 5 seconds"); Thread.sleep(5000); } catch (Exception e) { Log.error("Not able to Wait --- " + e.getMessage()); DriverScript.bResult = false; } }
public static void input(String object, String data) { try { Log.info("Entering the text in " + object); driver.findElement(By.xpath(OR.getProperty(object))).sendKeys(data); } catch (Exception e) { Log.error("Not able to Enter UserName --- " + e.getMessage()); DriverScript.bResult = false; } }
public static void click(String object, String data) { try { Log.info("Clicking on Webelement " + object); driver.findElement(By.xpath(OR.getProperty(object))).click(); } catch (Exception e) { Log.error("Not able to click --- " + e.getMessage()); DriverScript.bResult = false; } }
public static WebElement btn_LogIn() throws Exception { try { element = driver.findElement(By.id("login")); Log.info("Submit button is found on the Login page"); } catch (Exception e) { Log.error("Submit button is not found on the Login Page"); throw (e); } return element; }
public static WebElement txtbx_Password() throws Exception { try { element = driver.findElement(By.id("pwd")); Log.info("Password text box is found on the Login page"); } catch (Exception e) { Log.error("Password text box is not found on the Login Page"); throw (e); } return element; }
public static WebElement txtbx_UserName() throws Exception { try { element = driver.findElement(By.id("log")); Log.info("Username text box is found on the Login Page"); } catch (Exception e) { Log.error("UserName text box is not found on the Login Page"); throw (e); } return element; }
public static WebElement prospectList_AddClickList(WebDriver driver) throws Exception { WebDriverWait wait = new WebDriverWait(driver, 60); // Wait for Prospect->List page to load and click on Add New Prospect wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Constant.pListCreateXpath))); element = driver.findElement(By.xpath(Constant.pListCreateXpath)); element.click(); Log.info("Clicking on Prospect->List->AddProspect Link"); return element; }
public static WebElement prospectList(WebDriver driver) throws Exception { // WebElement pHoverLink = driver.findElement(By.xpath(Constant.pXpath)); element = driver.findElement(By.xpath(Constant.pXpath)); Actions actions = new Actions(driver); WebDriverWait wait = new WebDriverWait(driver, 60); Log.info("Initializing Actions"); // actions.moveToElement(pHoverLink).perform(); actions.moveToElement(element).perform(); Log.info("Menu Prospect Hover Link"); // Hover over Prospect menu and click on Prospect->List // WebElement moveonMenu = driver.findElement(By.xpath(mXpath)); wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(Constant.pListXpath))); // actions.moveToElement(submenuHoverLink).moveToElement(driver.findElement(By.xpath(msListXpath))).click().perform(); element = driver.findElement(By.xpath(Constant.pListXpath)); element.click(); Log.info("Menu Prospect->List Hover Link"); return element; }
public static void openBrowser(String object, String data) { Log.info("Opening Browser"); try { if (data.equals("Mozilla")) { driver = new FirefoxDriver(); Log.info("Mozilla browser started"); } else if (data.equals("IE")) { // Dummy Code, Implement you own code driver = new InternetExplorerDriver(); Log.info("IE browser started"); } else if (data.equals("Chrome")) { // Dummy Code, Implement you own code driver = new ChromeDriver(); Log.info("Chrome browser started"); } int implicitWaitTime = (10); driver.manage().timeouts().implicitlyWait(implicitWaitTime, TimeUnit.SECONDS); } catch (Exception e) { Log.info("Not able to open the Browser --- " + e.getMessage()); DriverScript.bResult = false; } }
@Test(dataProvider = "getXlsData") public void testUserRegistration( String SrNo, String TestCaseName, String FirstName, String LastName, String CitizenId, String DOB, String ZipCode, String Email, String ConfirmEmail, String MobileNumber, String NeedToExecute, String Result, String Comments) throws Exception { try { flag = false; // Fatching Test Data from the Test Data file and store into the array [] object. Log.info("Fatching Test Data from the Test Data file and store into the array [] object."); rowIndex = Integer.parseInt(SrNo); rowData = ExcelUtils.getXlsRowData(rowIndex, Constant.Total_Col_MetLifeGSSP); // Checking if test case need to be executed or not Log.info( "Value of rowData[Constant.Col_MetLifeGSSP_NeedToExecute] -->" + rowData[Constant.Col_MetLifeGSSP_NeedToExecute] + "--" + NeedToExecute); System.out.println("No -->" + SrNo); if (NeedToExecute.equalsIgnoreCase("Yes")) { // Init the Webdriver with Opening the browser and URL Log.info("Webdriver init and Opening the test application"); driver = Utils.OpenBrowser(Constant.appName); Log.info("Webdriver initilazied and test application open"); // Developing the Test Step into the Modules and based on the result we verify that the step // is pass or not. // TestBase.Assert() Function is used for assertion and this will stop the execution if // assert is fail. // TestBase.verifyAssert() Function is used for assertion verification but it will not stop // the execution and after capturing the error it continue the execution. // If function() return true then the execution will move to next step of the test case step // otherwise it fail and stop the execution. // Test Step 1 Log.info("Execution Test Step -->openRegistrationLink"); flag = testStep.openRegistrationLink(driver, rowIndex, sTestCaseName, rowData); Log.info("Test Step openRegistrationLink result -- >" + flag); TestBase.verifyTrue(flag); // Test Step 2 if (flag) { Log.info("Execution Test Step -->registrationCustomer"); flag = testStep.registrationCustomer(driver, rowIndex, sTestCaseName, rowData); Log.info("Test Step registrationCustomer result -- >" + flag); TestBase.verifyTrue(flag); } // Test Step 3 if (flag) { Log.info("Execution Test Step -->verifyCaptcha"); flag = testStep.verifyCaptcha(driver, rowIndex, sTestCaseName, rowData); Log.info("Test Step verifyCaptcha result -- >" + flag); TestBase.verifyTrue(flag); } // Test Step 3 if (flag) { Log.info("Execution Test Step -->verifyRegistration"); flag = testStep.verifyRegistration(driver, rowIndex, sTestCaseName, rowData); Log.info("Test Step verifyRegistration result -- >" + flag); TestBase.verifyTrue(flag); } Log.info("Final Result of the test case -->" + sTestCaseName + "-->" + flag); // Printing the result of the test case in the excel Result Column and TestNG report. if (flag) { ExcelUtils.setExcelFile( Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); ExcelUtils.setCellData( "Pass", rowIndex, Constant.Col_MetLifeGSSP_Result, Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); ExcelUtils.setCellData( "Test Case executed successfully.", rowIndex, Constant.Col_MetLifeGSSP_Comments, Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); Reporter.log(sTestCaseName + " Test Case Pass"); } else { throw new Exception("Test Case Failed because of Verification"); } } // If Test Case need not to be executed. else { Log.info("Test Case need not to be executed"); // Writing comment on the test data file why this case is skipped from the execution. ExcelUtils.setExcelFile( Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); ExcelUtils.setCellData( "Skip", rowIndex, Constant.Col_MetLifeGSSP_Result, Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); ExcelUtils.setCellData( "Need To Execute Request is selected as No", rowIndex, Constant.Col_MetLifeGSSP_Comments, Constant.Path_TestData + Constant.File_TestData, Constant.File_TestappNameSheet); throw new SkipException("Skiping This Test as 'Need To Execute' Request is selected as No"); } } catch (SkipException e) { throw (e); } }