Video:
Code:
1 2 3 4 5 6 7 8 9 10 |
package config; import org.openqa.selenium.WebDriver; import utils.BrowserManager; public class Config { public static String APP_URL = "http://parabank.parasoft.com"; } |
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 |
package po; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.testng.Assert; public class CommonPageObjects { //Section 1 WebDriver driver; //Section2 : Paramatrized Construcotr public CommonPageObjects(WebDriver driver) { this.driver = driver; } //Section 3: Locators @FindBy(how=How.LINK_TEXT,using="Open New Account") WebElement link_open_new_account; @FindBy(how=How.LINK_TEXT,using="Transfer Funds") WebElement link_transfer_funds; //Section 4: Methods public void ClickOnNewAccount() { link_open_new_account.click(); Assert.assertEquals(driver.getTitle(), "ParaBank | Open Account"); } public void ClickOnTransferFunds() { link_transfer_funds.click(); Assert.assertEquals(driver.getTitle(), "ParaBank | Transfer Funds"); } } |
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 |
package po; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.testng.Assert; import org.testng.Reporter; public class LoginPage { //Section 1 WebDriver driver; //Section2 : Paramatrized Construcotr public LoginPage(WebDriver driver) { this.driver = driver; } //Section 3: Locators @FindBy(how=How.NAME,using="username") WebElement txtbx_username; @FindBy(how=How.NAME,using="password") WebElement txtbx_password; @FindBy(how=How.XPATH,using="//input[@value='Log In']") WebElement btn_submit; //Section 4: Methods public void SetUserName(String arg) { txtbx_username.sendKeys(arg); Reporter.log("User Name set: " + arg,true); } public void SetPassword(String arg) { txtbx_password.sendKeys(arg); Reporter.log("Password set: " + arg,true); } public void ClickSubmitButton() { btn_submit.click(); Reporter.log("Button Clicked ",true); } public void LoginInToParaBank(String u, String p) { SetUserName(u); SetPassword(p); ClickSubmitButton(); String actual = driver.getTitle(); String expected = "ParaBank | Accounts Overview"; Assert.assertEquals(actual, expected); Reporter.log("Login In to ParaBank",true); } /* * * driver.findElement(By.name("username")).sendKeys("john"); driver.findElement(By.name("passowrd")).sendKeys("demo"); driver.findElement(By.xpath("//input[@value='Log In']")).click(); */ } |
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 |
package po; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; import org.openqa.selenium.support.ui.Select; import org.testng.Assert; import org.testng.Reporter; public class OpenNewAccountPageObject { //Section 1 WebDriver driver; //Section2 : Paramatrized Construcotr public OpenNewAccountPageObject(WebDriver driver) { this.driver = driver; } //Section 3: Locators @FindBy(how=How.ID,using="type") WebElement list_account_type; @FindBy(how=How.ID,using="fromAccountId") WebElement list_from_account; @FindBy(how=How.XPATH,using="//input[@type='submit']") WebElement btn_open_new_account; @FindBy(how=How.XPATH,using="//div[@ng-if='showResult']") WebElement segment_show_result; //Section 4: Methods public void SelectAccountType(String arg) { Select obj = new Select(list_account_type); obj.selectByVisibleText(arg); } public void SelectFromAccount(String arg) { Select obj = new Select(list_from_account); obj.selectByVisibleText(arg); } public void ClickSubmitButton() { btn_open_new_account.click(); } public void ValidateNewAccountIsCreated() { String actualText = segment_show_result.getText(); if (actualText.contains("Congratulations, your account is now open")) { Assert.assertTrue(true); }else { Assert.assertTrue(false,"Account not Created"); } //Fetch the Account Number String sNewAccountNumber = segment_show_result.findElement(By.id("newAccountId")).getText(); Reporter.log("New Account Created: " + sNewAccountNumber , true); } } |
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 |
package tc; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.PageFactory; import org.testng.Assert; import org.testng.annotations.Test; import config.Config; import po.CommonPageObjects; import po.LoginPage; import po.OpenNewAccountPageObject; import utils.BrowserManager; public class SmokeTest { String url = Config.APP_URL; //@Test public void t_01_login_in_to_parabank() { WebDriver driver = BrowserManager.InvokeAndNavigateBrowser(url); LoginPage login = PageFactory.initElements(driver, LoginPage.class); login.LoginInToParaBank("john", "demo"); } @Test public void t_02_create_new_account() { //Step 1: Invoke and Navigate WebDriver driver = BrowserManager.InvokeAndNavigateBrowser(url); LoginPage login = PageFactory.initElements(driver, LoginPage.class); //Step 2: Login in to the Application login.LoginInToParaBank("john", "demo"); //Step 3: Click on Menu Item Create New Account CommonPageObjects oCmnPageObject = PageFactory.initElements(driver, CommonPageObjects.class); oCmnPageObject.ClickOnNewAccount(); //Step 4: Create New Account OpenNewAccountPageObject oNewAccount = PageFactory.initElements(driver, OpenNewAccountPageObject.class); oNewAccount.SelectAccountType("SAVINGS"); oNewAccount.SelectFromAccount("13233"); oNewAccount.ClickSubmitButton(); //Step 5: Validation: New Account is Created oNewAccount.ValidateNewAccountIsCreated(); } } //USER ACTIONS /* driver.findElement(By.name("username")).sendKeys("john"); driver.findElement(By.name("passowrd")).sendKeys("demo"); driver.findElement(By.xpath("//input[@value='Log In']")).click(); */ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
package utils; import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.Reporter; public class BrowserManager { public static WebDriver InvokeAndNavigateBrowser(String url) { System.setProperty("webdriver.chrome.driver", "/Users/akashtyagi/Desktop/chromedriver"); WebDriver driver = new ChromeDriver(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.manage().window().maximize(); driver.get(url); Reporter.log("Browser Invoked",true); return driver; } } |