Need to Automate below Scenarios:
* Test cases in this Pack.
* TC 1: Validate account table is displayed
* TC 2: Validate the sum of all the account balance is equal to total amount displayed.
* TC3: Validate account information is displayed correctly after clicking
* TC 4: Validate Account activity Filter is working correctly
* -Validate if no month-entry
* -Validate if month-entry is there
* TC 5: Validate Transaction Details
Currently automated:
* TC 1: Validate account table is displayed
* TC 2: Validate the sum of all the account balance is equal to total amount displayed.
Test Ng Class with Test Cases:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
package testcases; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Assert; import org.testng.annotations.AfterMethod; import org.testng.annotations.AfterTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; import reusables.AppReusables; import reusables.GenericResuables; /* * Test cases in this Pack. * TC1: Validate account table is displayed * TC2: Validate the sum of all the account balance is equal to total amount displayed. * TC3: Validate account information is displayed correctly after clicking * TC4: Validate Account activity Filter is working correctly * -Validate if no month-entry * -Validate if month-entry is there * TC5: Validate Transaction Details */ public class TC_AccountOverview { WebDriver driver; WebElement tbl_acc_overview_table; @BeforeTest public void beforeTest() { System.setProperty("webdriver.chrome.driver", "D:\\VisionITWorkspace\\dependencies\\chromedriver_win32\\chromedriver.exe"); } //@Test public void t_validate_account_overview_screen() { //Step1: Login AppReusables.LoginInToTheApplication(driver, "john", "demo"); //Step2: Validate Page Content is correctly displayed // a. Validate Title String sPageTitleActual = driver.getTitle(); String sPageTitleExpected = "ParaBank | Accounts Overview"; Assert.assertEquals(sPageTitleActual, sPageTitleExpected); if (sPageTitleActual.equalsIgnoreCase(sPageTitleExpected)) { GenericResuables.WriteLogs("pass", "Page title correctly displayed. " + "Expected: " + sPageTitleExpected + " Actual is: " + sPageTitleActual ); }else { GenericResuables.WriteLogs("fail", "Page title not correctly displayed. " + "Expected: " + sPageTitleExpected + " Actual is: " + sPageTitleActual ); } //b. Validate Table Info initialize_locators(); String sTblText = tbl_acc_overview_table.getText(); if (tbl_acc_overview_table.isDisplayed()) { GenericResuables.WriteLogs("pass", "Table is displayed successfully with text as " + sTblText); }else { GenericResuables.WriteLogs("fail", "Table is not displayed"); } } @Test public void t_validate_accounts_balance_matchinng_with_total() { //Step1: Login AppReusables.LoginInToTheApplication(driver, "john", "demo"); //b. Validate Table Info initialize_locators(); String sTblText = tbl_acc_overview_table.getText(); List<WebElement> o_collection_tr = tbl_acc_overview_table.findElements(By.tagName("tr")); String temp; ArrayList<String> arr_account_balance = new ArrayList<String>(); for (int i=1;i<o_collection_tr.size()-2;i++) { temp = o_collection_tr.get(i).findElements(By.tagName("td")).get(1).getText(); arr_account_balance.add(temp); } //Need further update in below statement: //Remove total and $ sign int total_actual = Integer.parseInt(o_collection_tr.get(o_collection_tr.size()).getText().replace("$", "")); //Add all the values String temp1; int temp2; ArrayList<Integer> arr_account_balance_formated = new ArrayList<Integer>(); for(int i=0;i<arr_account_balance.size();i++) { temp1 = arr_account_balance.get(i); temp1 = temp1.replaceAll("$", ""); temp2 = Integer.parseInt(temp1); arr_account_balance_formated.add(temp2); // arr_account_balance_formated.add(Integer.parseInt(arr_account_balance.get(i).replaceAll("$", ""))); } int sum_expected=0; for(int i=0;i<arr_account_balance_formated.size();i++) { sum_expected = arr_account_balance_formated.get(i) + sum_expected; } //Get Actual from Table if (total_actual==sum_expected) { GenericResuables.WriteLogs("pass", "Account Sum matching with total displayed"); }else { GenericResuables.WriteLogs("fail", "Account Sum not matching with total displayed"); } } @BeforeMethod public void beforeMethod() { driver = GenericResuables.WebDriverManager("chrome", "http://parabank.parasoft.com"); } @AfterMethod public void afterMethod() { driver.quit(); } @AfterTest public void afterTest() { } public void initialize_locators() { tbl_acc_overview_table = driver.findElement(By.id("accountTable")); } } |
Reusable Classes: AppResuables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package reusables; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; public class AppReusables { public AppReusables() { // TODO Auto-generated constructor stub } public static void LoginInToTheApplication(WebDriver driver,String username, String password) { //Locators for Login WebElement txt_username = driver.findElement(By.xpath("//input[@name='username' and @class='input']")); WebElement txt_password = driver.findElement(By.xpath("//input[@name='password' and @class='input']")); WebElement btn_submit = driver.findElement(By.xpath("//input[@value='Log In' and @type='submit']")); //Operation on- Login in to application txt_username.sendKeys(username); txt_password.sendKeys(password); btn_submit.click(); } } |
Reusable Classes: GenericResuables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package reusables; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; public class GenericResuables { public static void WriteLogs(String logtype, String msg) { System.out.println(logtype + "," + msg); } public static WebDriver WebDriverManager(String browsertype, String url) { //1 Create Driver object WebDriver driver = new ChromeDriver(); //Navigate driver.get(url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); return driver; } } |