Part 3 Using Page Objects with Behavior Driven Development in an Agile Environment Demonstration

Part 3: Mock Two Week Sprint Day 3 and Day 4

Day 3 of the Sprint

Daily Scrum

Automation Tasks Day 3 – The automation team members would continue stubbing out the Page Objects until they were completed. Once the Page Objects were stubbed out, the automation team members would start writing test cases to verify the Acceptance Criteria has been meet. As new code is created, it should be checked into the CMS.

Page Object example: Login Page

/*
 * Filename: LoginPage.java 
 * 
 */

package com.cos.selenium.admin.pages;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import com.fl.flpi.selenium.common.PageParent;
import com.fl.flpi.selenium.utils.ToolBox;

public class LoginPage extends PageParent {

	
     /**
     * Enter  Username.
     * 
     * @Text 
     */
	public void setValueInUsernameField(String user) {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        
        // Verify UserName present
        // Enter Username.
        WebElement uName = null;
        try {
        	 uName = webDriver.findElement(By.id("userName"));
        	 uName.clear();
              Uname.sendKeys(userName);
            

        } catch (NoSuchElementException e) {
            fail("Username Field not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }
	
     /**
     * Enter Password.
     * 
     * @Text 
     */
	public void setValueInPasswordField(String pass) {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
       

        // Verify Password present
        // Enter Password.
        WebElement pw = null;
        try {
        	pw = webDriver.findElement(By.id("userPassword")); 
             pw.clear();
             pw.sendKeys(pass);
            
        	
        } catch (NoSuchElementException e) {
            fail("Password Field not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }
	
     /**
     * Clicks the Login button.
     * 
     */
	public void clickLoginBtn() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        

        // Verify Login Button present
        // Click the Login button.
        WebElement log = null;
        try {
        	log = webDriver.findElement(By.id("submit")); 
             log.click(); 	

        } catch (NoSuchElementException e) {
            fail("Login Button not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
	}
	
     /**
     * Clicks the Remember me Checkbox.
     * 
     */
	public void clickRememberMeCheckbox() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        

        // Verify Remember me Checkbox present
        // Click the Remember me Checkbox.
        WebElement rMe = null;
        try {
        	rMe = webDriver.findElement(By.id("rememberMeCheckbox")); 
             rMe.click(); 	

        } catch (NoSuchElementException e) {
            fail("Remember Me Checkbox not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
	}

     /**
     * Clicks the Forgot Password? Link.
     * 
     */
	public void clickForgotPasswordLink() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        

        // Verify Forgot Password? Link present
        // Click the Forgot Password Link.
        WebElement fPassword = null;
        try {
        	fPassword = webDriver.findElement(By.id("forgotPassword")); 
             fPassword.click(); 	

        } catch (NoSuchElementException e) {
            fail("Forgot Password Link not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
	}

}

Page Object example: Welcome Page

/*
 * Filename: WelcomePage.java 
 * 
 */

package com.cos.selenium.admin.pages;

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import com.fl.flpi.selenium.common.PageParent;
import com.fl.flpi.selenium.utils.ToolBox;

public class WelcomePage extends PageParent {

	
     /**
     * Click Home Button.
     * 
     *  
     */
	public void clickHomeBtn() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        
        // Verify Home Button present
        // Click Button.
        WebElement hBtn = null;
        try {
        	 hBtn = webDriver.findElement(By.id("homeButton");
              hBtn.click();
            

        } catch (NoSuchElementException e) {
            fail("Home Button not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }

     /**
     * Click My Account Button.
     * 
     * 
     */
	public void clickMyAccountBtn() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        
        // Verify My Account Button present
        // Click Button.
        WebElement maBtn = null;
        try {
        	 maBtn = webDriver.findElement(By.id("myAccountButton");
              maBtn.click();
            

        } catch (NoSuchElementException e) {
            fail("My Account Button not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }


        /**
     * Click Buy Tickets Button.
     * 
     *  
     */
	public void clickBuyTicketsBtn() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        
        // Verify Buy Tickets Button present
        // Click Button.
        WebElement btBtn = null;
        try {
        	 btBtn = webDriver.findElement(By.id("buyTicketsButton");
              btBtn.click();            

        } catch (NoSuchElementException e) {
            fail("Buy Tickets Button not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }


        /**
     * Click Logout Link.
     * 
     *  
     */
	public void clickLogoutLink() {

        if (debugMode) {
			ToolBox.logMessage(new Exception("Entered"));
		}
        
        // Verify Logout Link present
        // Click Link.
        WebElement lLink = null;
        try {
        	 lLink = webDriver.findElement(By.id("logout");
              lLink.click();
            

        } catch (NoSuchElementException e) {
            fail("Logout Link not found");
        }

        if (debugMode) {
			ToolBox.logMessage(new Exception("Leaving"));
		}
    }

Important Note: The location of the services (Username, Login Button, etc..) on a mockup or the actual page does not matter to Page Objects, since the WebDriver command (webDriver.findElement)is going to search the page DOM until it finds the correct service indicated in the (By.id(“”));.

Day 4 of the Sprint

Daily Scrum

Automation Tasks Day 4 – The automation team members would continue writing test cases to verify the Acceptance Criteria has been meet. The automation team members would also be creating any needed test data and test suite(s). At this point the team members would also be watching for code to start being delivered. Once code starts being delivered, the team members would start updating their stubbed out Page Objects and also start running their test cases and do refactoring as needed. As new code is created, it should be checked into the CMS.

Acceptance Criteria One Test:

/*----------------------------------------------------------------------
 * Filename: SuccessLoginTest.java
 *
 *
 */

package com.cos.selenium.admin.test;

import static org.testng.AssertJUnit.assertTrue;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.testng.annotations.Test;
import com.fl.flpi.selenium.admin.pages.LoginPage;
import com.fl.flpi.selenium.common.BaseCosTest;

public class SuccessLoginOneTest extends BaseCosTest {

    private LoginPage loginPage  = new loginPage ();

    @Test
    public void SuccessfulLoginTests() throws FindFailed {

        String testId = "Login Success Test";

        entered(testId);

        String userName = testData.getString("LOGIN_ONE_USERNAME");
        String pass = testData.getString(“LOGIN_ONE_PASSWORD”);

        loginPage.setValueInUsernameField(userName);
        loginPage.setValueInPasswordField(pass);
        loginPage.clickLoginBtn();
        assertTrue(driver.getTitle().contains("Welcome to Widgets of America"));
        welcomePage.clickLogout();

        leaving(testId);

    }



}
Posted in Uncategorized

Download and extend ATF...

ATF Is Now Open Source

Join this 10 week program anytime...

DevOps Mastery Program

Get your DevOps health check now...

Free DevOps Assessment

X