In this Framework, we will have a Page Class and for every Page class we will have respective Test Class associated with it.
Page class will have all the WebElement's of that particular page loaded inside and also the actions to perform on that respective WebElement's.
Ex: Google Home Page is considered to be one page and we call it as GooglePage class.
Test class will take all the actions methods from Page class and make it as one Test Method.
Ex: Scenario
- Open Google Chrome
- Enter www.google.com
- Enter "Hello" in search box
- Hit Enter button in keyboard.
Below is the complete Framework.
This is how Framework Structure will look like.
// This is a Test Class, which is inside a Package called "purush_TestPackage".
// All the Test Methods will sit inside this Package or we can group them according to our requirements alternatively.
GoogleTest class
package
purush_TestPackage;
import
org.testng.annotations.Test;
import
purush_PageClass.GooglePage;
import
org.testng.annotations.BeforeTest;
import
org.testng.annotations.AfterTest;
import org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class GoogleTest
{
//public WebDriver driver = new
InternetExplorerDriver();
public WebDriver driver = new ChromeDriver();
GooglePage objLoginPage = new GooglePage(driver);
@Test
public void EnterKeyword()
{
objLoginPage.EnterSearchKeyword();
}
@Test
public void PressEnterKey()
{
objLoginPage.PressEnterKey();
}
@BeforeTest
public void beforeTest()
{
driver.navigate().to("http://www.google.com");
driver.manage().window().maximize();
}
@AfterTest
public void afterTest()
{
driver.quit();
}
}
// This is the Page Class, where all the WebElement's of particular page sits, and also the action's to perform on those WebElement's.
GooglePage Class
package
purush_PageClass;
import
org.openqa.selenium.By;
import
org.openqa.selenium.Keys;
import
org.openqa.selenium.WebDriver;
public class GooglePage
{
WebDriver
driver;
By SearchBox= By.xpath("/html//input[@id='lst-ib']");
public
GooglePage(WebDriver driver)
{
this.driver=driver;
}
public void EnterSearchKeyword()
{
driver.findElement(SearchBox).sendKeys("Hello");
}
public void PressEnterKey()
{
driver.findElement(SearchBox).sendKeys(Keys.ENTER);
}
}
You're Welcome always
ReplyDelete