In this three part video sessions, I have explained how to create the new feature file and their respective step…
We can use these annotations in those cases when we have more than a single criteria to to identify one…
Test Case File:
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 |
public class TC_Login{ @Test public void t_01_validate_login() { WebDriver driver = WebDriverManager.InitializeBrowser("chrome", "http://parabank.parasoft.com/parabank/index.htm"); String expected_url = "http://parabank.parasoft.com/parabank/index.htm"; //Create Page Factory object for Login page PO_Login PO_Login = PageFactory.initElements(driver, PO_Login.class); PO_AccountOverview PO_AccountOverview = PageFactory.initElements(driver, PO_AccountOverview.class); PO_Login.SetUserNameTextBox("john"); PO_Login.SetPasswordTextBox("demo"); PO_Login.ClickLoginButton(); //Create Page Factory object for Account Overview PO_AccountOverview.ValidateAccountOverviewTableIsDisplayed(); /* List<WebElement> collection = driver.findElements(By.xpath("//input[@type='text']")); int total = collection.size(); for(int i=0;i<total;i++) { collection.get(i).clear(); } */ }//end method |
Page Object Class:
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 po; import org.openqa.selenium.NoSuchElementException; 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.ExpectedConditions; import org.openqa.selenium.support.ui.WebDriverWait; import reusables.GenericReusables; public class PO_Login { //Step1 : Define the driver WebDriver driver; //Step 2: Paramatrize the constructor public PO_Login(WebDriver driver1) { this.driver = driver1; } //Step 3: Declare the Locators // Two ways to declare 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[@type='submit']") WebElement btn_login; /* @FindBy(id = "dsf") WebElement sdfds; */ //Set user name public void SetUserNameTextBox(String username) { try { WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOf(txtbx_username)); txtbx_username.sendKeys(username); GenericReusables.WriteLogs("info", "User Name set with text: " + username); }catch(NoSuchElementException e) { GenericReusables.WriteLogs("fail", "User Name not set with text: " + username + " due to exception " + e.toString()); e.printStackTrace(); } } //Set user name public void SetPasswordTextBox(String password) { try { WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOf(txtbx_password)); txtbx_password.sendKeys(password); GenericReusables.WriteLogs("info", "Password set with text: " + txtbx_password); }catch(NoSuchElementException e) { GenericReusables.WriteLogs("fail", "Password not set with text: " + password + " due to exception " + e.toString()); e.printStackTrace(); } }//end Method //Set user name public void ClickLoginButton() { try { WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.visibilityOf(txtbx_password)); btn_login.click(); GenericReusables.WriteLogs("info", "Clicked on Login Button"); }catch(NoSuchElementException e) { GenericReusables.WriteLogs("fail", "Unable to click on login button" + " due to exception " + e.toString()); e.printStackTrace(); } }//end Method }//end class |