PO_CmnPageObjects.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
package pageobjects; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; public class PO_CmnPageObjects { WebDriver driver; public PO_CmnPageObjects(WebDriver driver) { this.driver = driver; } @FindBy(how = How.LINK_TEXT, using = "Transfer Funds") private WebElement link_transfer_funds; public void ClickTransferFunds() { link_transfer_funds.click(); } } |
PO_Login.java
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 |
package pageobjects; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; import org.openqa.selenium.support.How; public class PO_Login { WebDriver driver; public PO_Login(WebDriver driver) { this.driver = driver; } @FindBy(how = How.NAME, using = "username") private WebElement txtbx_login; @FindBy(how = How.NAME, using = "password") private WebElement txtbx_password; @FindBy(how = How.XPATH, using = "//input[@type='submit' and @value='Log In']") private WebElement btn_login; public void SetUserName(String u) { txtbx_login.sendKeys(u); } public void SetPassword(String p) { txtbx_password.sendKeys(p); } public void ClickLoginBtn() { btn_login.click(); } } |
PO_TransferFunds.java
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 |
package pageobjects; 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 junit.framework.Assert; public class PO_TransferFunds { WebDriver driver; public PO_TransferFunds(WebDriver driver) { this.driver = driver; } @FindBy(how = How.ID, using = "amount") private WebElement txtbox_ammount; @FindBy(how = How.ID, using = "fromAccountId") private WebElement list_from_account; @FindBy(how = How.ID, using = "toAccountId") private WebElement list_to_account; @FindBy(how = How.XPATH, using = "//input[@value = 'Transfer']") private WebElement btn_tranfer; @FindBy(how = How.XPATH, using = "//div[@ng-if = 'showResult']") private WebElement txt_container_transfer_results; public void SetAmmount(String u) { txtbox_ammount.sendKeys(u); } public void SelectFromAccount(String p) { Select oFromList = new Select(list_from_account); oFromList.selectByValue(p); } public void SelectToAccount(String p) { Select oToList = new Select(list_to_account); oToList.selectByValue(p); } public void ClickTransfer() { btn_tranfer.click(); } /* * Transfer Complete! $123.00 has been transferred from account #13122 to account #13566. See Account Activity for more details. */ public void ValidateTransferResults() { //Validation 1 boolean result_actual = txt_container_transfer_results.isDisplayed(); boolean result_expected = true; Assert.assertEquals(result_actual, result_expected); //Validation 2 String result_text_actual = txt_container_transfer_results.getText(); String result_text_expected_1 = "Transfer Complete!"; boolean b = (result_text_actual.contains(result_text_expected_1)); Assert.assertTrue(b); //String result_text_expected_2 = "has been transferred from account"; //String result_text_expected_3 = "See Account Activity for more details."; //Assert.assertEquals(result_text_actual, result_text_expected_1); //Assert.assertEquals(result_text_actual, result_text_expected_2); //Assert.assertEquals(result_text_actual, result_text_expected_3); } } |
TC_SmokeTest.java
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 |
package testcases; import static org.junit.jupiter.api.Assertions.*; import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.support.PageFactory; import junit.framework.Assert; import pageobjects.PO_CmnPageObjects; import pageobjects.PO_Login; import pageobjects.PO_TransferFunds; class TC_SmokeTestJunit { WebDriver driver; PO_CmnPageObjects PO_CmnPageObjects; PO_TransferFunds PO_TransferFunds; @BeforeAll static void setUpBeforeClass() throws Exception { System.out.println("BeforeAll"); System.setProperty("webdriver.chrome.driver", "D:\\VisionITWorkspace\\dependencies\\chromedriver_win32\\chromedriver.exe"); } @BeforeEach void setUp() throws Exception { //1. Initialize the Browser driver = new ChromeDriver(); driver.get("http://parabank.parasoft.com/parabank/index.htm"); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); PO_CmnPageObjects = PageFactory.initElements(driver, PO_CmnPageObjects.class); PO_TransferFunds = PageFactory.initElements(driver, PO_TransferFunds.class); System.out.println("BeforeEach"); } @AfterEach void tearDown() throws Exception { driver.quit(); System.out.println("Driver quit"); } @Test void t_login_into_parabank() { System.out.println("Test1"); PO_Login o_login = PageFactory.initElements(driver, PO_Login.class); o_login.SetUserName("john"); o_login.SetPassword("demo"); o_login.ClickLoginBtn(); String s_title_expected = "ParaBank | Accounts Overview"; String s_title_actual = driver.getTitle(); Assert.assertEquals(s_title_expected, s_title_actual); //fail("Not yet implemented"); } @Test void t_check_transfer_funds() { //Login in to the application t_login_into_parabank(); //Click on Transfer funds PO_CmnPageObjects.ClickTransferFunds(); //Set Amount and perform Transfer Funds PO_TransferFunds.SetAmmount("1000"); PO_TransferFunds.SelectFromAccount("12345"); PO_TransferFunds.SelectToAccount("12346"); PO_TransferFunds.ClickTransfer(); //Validation PO_TransferFunds.ValidateTransferResults(); } } |