SlideShare ist ein Scribd-Unternehmen logo
1 von 6
Downloaden Sie, um offline zu lesen
Page Object Pattern
Electronics Page Furniture Page
ebay Home Page
(Page Factory)
Clothing
Sample PageFactory code
public class PageFactory {
PageFactory pageObject = new PageFactory();
ElectronicsPage electronicsPage = new ElectronicsPage();
ClothingPage clothingPage = new ClothingPage();
FurniturePage furniturePage = new FurniturePage();
public ElectronicsPage gotoElectronicsPage()
{
SeleniumCommands.click("electronics");
return electronicsPage;
}
public ClothingPage gotoClothingPage()
{
SeleniumCommands.click("clothing");
return clothingPage;
}
public FurniturePage gotoFurniturePage()
{
SeleniumCommands.click("furniture");
return furniturePage;
}
}
Electronics Page
isPriceEqualTo(price)getPrice(searchItem)
searchItem(searchItem)
Set of Action method
isElectronicsPageOpened()
Set of Check method
Sample Electronics page
public class ElectronicsPage {
// Action methods on page
public ElectronicsPage searchItem(String searchItemName) {
SeleniumCommands.type(searchItemName);
SeleniumCommands.click("searchButton");
return this;
}
public String getItemPrice(String searchItemName) {
return SeleniumCommands.getValue(searchItemName);
}
// Check methods on Page
public Validaton isPriceEqualTo(String itemPrice) {
return new Validaton(SeleniumCommands.getValue("searchItem"), itemPrice);
}
public Validaton isElectronicsPageOpened(String electronicsPageTitle) {
return new Validaton(SeleniumCommands.getPageTitle(),
electronicsPageTitle);
}
}
Validation Class
public class Validaton {
Object actual;
Object expected;
public Validaton(Object actual, Object expected) {
this.actual = actual;
this.expected = expected;
}
public Validaton(Object actual) {
this.actual = actual;
}
public void shouldBeEqual() {
Assert.assertEquals(actual, expected);
}
public void shouldBeTrue() {
Assert.assertTrue((boolean) actual);
}
}
Sample Test Case
public class SampleTest {
PageObject pageObject = new PageObject();
@Test
public void test() {
pageObject.gotoElectronicsPage().searchItem("MACBOOK").isPriceEqualTo("1400").shouldBeEqual();
}
}
pageObject.gotoElectronicsPage().
searchItem("MACBOOK")
shouldBeEqual()
isPriceEqualTo("1400")
ACTION
CHECK
VALIDATION

Weitere ähnliche Inhalte

Andere mochten auch

Andere mochten auch (7)

Building frameworks over Selenium
Building frameworks over SeleniumBuilding frameworks over Selenium
Building frameworks over Selenium
 
Write Selenide in Python 15 min
Write Selenide in Python 15 minWrite Selenide in Python 15 min
Write Selenide in Python 15 min
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, java
 
Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014Page Objects Done Right - selenium conference 2014
Page Objects Done Right - selenium conference 2014
 
Realtime selenium interview questions
Realtime selenium interview questionsRealtime selenium interview questions
Realtime selenium interview questions
 
Selenium interview questions
Selenium interview questionsSelenium interview questions
Selenium interview questions
 
Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]Kiss PageObjects [01-2017]
Kiss PageObjects [01-2017]
 

Ähnlich wie PageObectPattern

Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Thomas Fuchs
 

Ähnlich wie PageObectPattern (20)

Future of UI Automation testing and JDI
Future of UI Automation testing and JDIFuture of UI Automation testing and JDI
Future of UI Automation testing and JDI
 
Roman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium campRoman iovlev. Test UI with JDI - Selenium camp
Roman iovlev. Test UI with JDI - Selenium camp
 
Wicket KT part 2
Wicket KT part 2Wicket KT part 2
Wicket KT part 2
 
Beyond pageobjects
Beyond pageobjectsBeyond pageobjects
Beyond pageobjects
 
Creating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdfCreating a Facebook Clone - Part XXXI.pdf
Creating a Facebook Clone - Part XXXI.pdf
 
Роман Иовлев «Open Source UI Automation Tests on C#»
Роман Иовлев «Open Source UI Automation Tests on C#»Роман Иовлев «Open Source UI Automation Tests on C#»
Роман Иовлев «Open Source UI Automation Tests on C#»
 
A test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobileA test framework out of the box - Geb for Web and mobile
A test framework out of the box - Geb for Web and mobile
 
Griffon @ Svwjug
Griffon @ SvwjugGriffon @ Svwjug
Griffon @ Svwjug
 
SOLID principles with Typescript examples
SOLID principles with Typescript examplesSOLID principles with Typescript examples
SOLID principles with Typescript examples
 
Of plugins and decorators - trivago's e2e test framework in the spotlight
Of plugins and decorators - trivago's e2e test framework in the spotlightOf plugins and decorators - trivago's e2e test framework in the spotlight
Of plugins and decorators - trivago's e2e test framework in the spotlight
 
Тарас Олексин - Sculpt! Your! Tests!
Тарас Олексин  - Sculpt! Your! Tests!Тарас Олексин  - Sculpt! Your! Tests!
Тарас Олексин - Sculpt! Your! Tests!
 
08 Queries
08 Queries08 Queries
08 Queries
 
ConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with GroovyConFess Vienna 2015 - Metaprogramming with Groovy
ConFess Vienna 2015 - Metaprogramming with Groovy
 
Creating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdfCreating a Facebook Clone - Part XXXI - Transcript.pdf
Creating a Facebook Clone - Part XXXI - Transcript.pdf
 
Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...
Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...
Scrum Gathering 2012 Shanghai_工程实践与技术卓越分会场:how to write unit test for new cod...
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Test automation
Test  automationTest  automation
Test automation
 
Breaking the limits_of_page_objects
Breaking the limits_of_page_objectsBreaking the limits_of_page_objects
Breaking the limits_of_page_objects
 
Javascript Design Patterns
Javascript Design PatternsJavascript Design Patterns
Javascript Design Patterns
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDD
 

PageObectPattern

  • 1. Page Object Pattern Electronics Page Furniture Page ebay Home Page (Page Factory) Clothing
  • 2. Sample PageFactory code public class PageFactory { PageFactory pageObject = new PageFactory(); ElectronicsPage electronicsPage = new ElectronicsPage(); ClothingPage clothingPage = new ClothingPage(); FurniturePage furniturePage = new FurniturePage(); public ElectronicsPage gotoElectronicsPage() { SeleniumCommands.click("electronics"); return electronicsPage; } public ClothingPage gotoClothingPage() { SeleniumCommands.click("clothing"); return clothingPage; } public FurniturePage gotoFurniturePage() { SeleniumCommands.click("furniture"); return furniturePage; } }
  • 3. Electronics Page isPriceEqualTo(price)getPrice(searchItem) searchItem(searchItem) Set of Action method isElectronicsPageOpened() Set of Check method
  • 4. Sample Electronics page public class ElectronicsPage { // Action methods on page public ElectronicsPage searchItem(String searchItemName) { SeleniumCommands.type(searchItemName); SeleniumCommands.click("searchButton"); return this; } public String getItemPrice(String searchItemName) { return SeleniumCommands.getValue(searchItemName); } // Check methods on Page public Validaton isPriceEqualTo(String itemPrice) { return new Validaton(SeleniumCommands.getValue("searchItem"), itemPrice); } public Validaton isElectronicsPageOpened(String electronicsPageTitle) { return new Validaton(SeleniumCommands.getPageTitle(), electronicsPageTitle); } }
  • 5. Validation Class public class Validaton { Object actual; Object expected; public Validaton(Object actual, Object expected) { this.actual = actual; this.expected = expected; } public Validaton(Object actual) { this.actual = actual; } public void shouldBeEqual() { Assert.assertEquals(actual, expected); } public void shouldBeTrue() { Assert.assertTrue((boolean) actual); } }
  • 6. Sample Test Case public class SampleTest { PageObject pageObject = new PageObject(); @Test public void test() { pageObject.gotoElectronicsPage().searchItem("MACBOOK").isPriceEqualTo("1400").shouldBeEqual(); } } pageObject.gotoElectronicsPage(). searchItem("MACBOOK") shouldBeEqual() isPriceEqualTo("1400") ACTION CHECK VALIDATION