SlideShare a Scribd company logo
Page Objects with
Selenium WebDriver
Trójmiejska Grupa Testerska
Spotkanie #3
Marcin Wasilczyk, Oleksandr Perepelytsya
16-Apr-15 1
Commercial In Confidence & Proprietary, Kainos Software 2012
Agenda
 Automated Testing overview
 Selenium
 Page Object pattern
 Demo
 Konkurs (z nagrodami )
16-Apr-15 2
Commercial In Confidence & Proprietary, Kainos Software 2012
Automated Testing overview
16-Apr-15 3
• Reduces amount of manual testing
• Can be run frequently (e.g. every night/build)
• Save testers time and is a quick signal to the dev
team that something was broken recently (either
test or application)
• Requires effort to write them as reliable piece of
software
• Test code needs to be easy to maintain when
application changes
• The code should be as good as production code
Commercial In Confidence & Proprietary, Kainos Software 2012
Selenium
16-Apr-15 4
• Is Selenium a test framework? Nope!
• Selenium is a suite of tools that automate web
browsers
• Supports most of the browsers and operating systems
• Could be used for
• Automating boring web-based administration tasks
• Testing (when run by external test framework like NUnit)
• Two versions exist
• Selenium RC (Remote Control)
• Uses javascript ‘injection’ to control the browser
• not supported anymore
• Selenium WebDriver
• Uses browser’s native support for automation
Selenium Basic Concepts
IWebDriver instance lets you control the browser
ChromeDriver, InternetExplorerDriver, FirefoxDriver, etc...
IWebElement instance lets you operate the page element
IWebElement button =
driver.FindElement(By.ClassName(“PrimaryButton”));
button.Click();
WebDriverWait lets you wait for elements being loaded
var loadWait = new WebDriverWait(driver,
TimeSpan.FromSeconds(5));
loadWait.Until(ExpectedConditions.TitleIs(„My Dashboard“));
16-Apr-15 5
Page Object pattern
Create model of UI pages as objects
Reduces the amount of duplicated code
If you change anything in UI, fix will be applied only to one place
Encapsulation of Page Object internals
Client (e.g. NUnit test) will know only about services exposed as public
methods
Page Objects should return other Page Objects; examples:
var userPage = loginPage.LoginAs(“username”, “password”);
var loginPage = logoutPopup.Confirm();
Changing the id of the button you don’t need to change the test, only the
page object’s internals will be modified
16-Apr-15 6
Page Object pattern -
summary
Generally don't make assertions – these should be done in the test,
not in the Page Object
Need not represent an entire page
Different results for the same action are modelled as different
methods
var patientRecordPage =
dashboardPage.SimpleSearchForSinglePatientWith(searchText);
var dashboardPage =
dashboardPage.SimpleSearchForManyPatientsWith(searchText);
16-Apr-15 7
Page Object pattern -
example
public class LoginPage
{
private IWebDriver Driver { get; set; }
private IWebElement UserName { get; set; }
private IWebElement Password { get; set; }
private IWebElement LoginButton { get; set; }
public LoginPage(IWebDriver driver)
{
Driver = driver;
UserName = driver.FindElement(By....)
// initialization of the remaining elements
}
// methods like
public UserPage LoginAs(string username, string password) { ... }
}
16-Apr-15 8
Selenium – support of
“Page Object pattern”
PageFactory lets you automatically initialize elements defined in
Page Object (binding - action)
PageFactory.InitElements(driver, pageObject);
FindsBy attribute - automatically find elements on page (binding -
definition)
CacheLookup attribute – caches found element
[FindsBy(How = How.Id, Using = „userNameElement")]
[CacheLookup]
private IWebElement UserName { get; set; }
16-Apr-15 9
Selenium – support of
“Page Object pattern”
public class LoginPage
{
private IWebDriver Driver { get; set; }
[FindsBy(How = How.Id, Using = "ctl00_content_UserName")]
[CacheLookup]
private IWebElement UserName { get; set; }
// ... other fields with attributes applied...
public LoginPage(IWebDriver driver)
{
Driver = driver;
PageFactory.InitElements(this.Driver, this);
}
// methods like
public UserPage LoginAs(string username, string password) { ... }
} 16-Apr-15 10
Demo
16-Apr-15 11
Konkurs
Test Steps:
1. Navigate to Home page
2. Search for “laptop”
3. Click on 3 (third) element in the results list
4. Remember seller name and price
5. Add to bucket
6. Verify that item in the bucket has the same
seller and price
7. Remove item from bucket
8. Navigate to Home page
16-Apr-15 12
Questions?
16-Apr-15 13

More Related Content

PPTX
TGT#13 - UI Tests Automation Framework in Evolve EDM – Case Study - Mateusz R...
PPTX
Angular UI Testing with Protractor
PDF
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
PDF
AngularJS and Protractor
PDF
Selenium - The page object pattern
PPTX
Protractor Tutorial Quality in Agile 2015
PPTX
An Introduction to AngularJS End to End Testing using Protractor
PDF
Protractor: Tips & Tricks
TGT#13 - UI Tests Automation Framework in Evolve EDM – Case Study - Mateusz R...
Angular UI Testing with Protractor
Carmen Popoviciu - Protractor styleguide | Codemotion Milan 2015
AngularJS and Protractor
Selenium - The page object pattern
Protractor Tutorial Quality in Agile 2015
An Introduction to AngularJS End to End Testing using Protractor
Protractor: Tips & Tricks

What's hot (20)

PPTX
Better Page Object Handling with Loadable Component Pattern
PPTX
Automated Testing using JavaScript
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
PPTX
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
PDF
Automated Web Testing using JavaScript
PDF
UI Testing Automation
PPTX
Automated UI testing done right (DDDSydney)
PDF
Workshop - E2e tests with protractor
PPTX
Protractor training
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
PPTX
Automation using Javascript
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
PPTX
Better End-to-End Testing with Page Objects Model using Protractor
PDF
Web UI test automation instruments
PDF
Selenium Overview
PPTX
Protractor overview
PDF
PHP Unit Testing in Yii
PDF
Automated Testing in Angular Slides
PDF
Automation Abstraction Layers: Page Objects and Beyond
PDF
Codeception presentation
Better Page Object Handling with Loadable Component Pattern
Automated Testing using JavaScript
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Automated Web Testing using JavaScript
UI Testing Automation
Automated UI testing done right (DDDSydney)
Workshop - E2e tests with protractor
Protractor training
Acceptance & Functional Testing with Codeception - Devspace 2015
Automation using Javascript
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Better End-to-End Testing with Page Objects Model using Protractor
Web UI test automation instruments
Selenium Overview
Protractor overview
PHP Unit Testing in Yii
Automated Testing in Angular Slides
Automation Abstraction Layers: Page Objects and Beyond
Codeception presentation
Ad

Similar to Marcin Wasilczyk - Page objects with selenium (20)

PDF
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
PPT
I one aolpage-test-2010
PDF
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
PDF
Good practices for debugging Selenium and Appium tests
PPTX
Testing ASP.NET - Progressive.NET
PPTX
Qa process
PDF
Page Object Model and Implementation in Selenium
PPTX
Mastering Test Automation: How To Use Selenium Successfully
ODP
Integrating Selenium testing infrastructure into Scala Project
PPTX
Qa process
PDF
Page object pattern
PPTX
Slides for Automation Testing or End to End testing
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
PPTX
Load Testing: See a Bigger Picture
PDF
Automation Abstractions: Page Objects and Beyond
PPTX
BDD with SpecFlow and Selenium
PDF
Advanced Techniques to Build an Efficient Selenium Framework
PDF
Building a Robust WebDriverIO Test Automation Framework
PPT
PPT
Test Automation Framework Development Introduction
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
I one aolpage-test-2010
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Good practices for debugging Selenium and Appium tests
Testing ASP.NET - Progressive.NET
Qa process
Page Object Model and Implementation in Selenium
Mastering Test Automation: How To Use Selenium Successfully
Integrating Selenium testing infrastructure into Scala Project
Qa process
Page object pattern
Slides for Automation Testing or End to End testing
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Load Testing: See a Bigger Picture
Automation Abstractions: Page Objects and Beyond
BDD with SpecFlow and Selenium
Advanced Techniques to Build an Efficient Selenium Framework
Building a Robust WebDriverIO Test Automation Framework
Test Automation Framework Development Introduction
Ad

More from Trójmiejska Grupa Testerska (20)

PPTX
Rafal prezentacja testowanie ai
PPTX
Tgt 23 przemyslaw_pradzynski
PDF
TGT#21 - Tester eksploracyjny, ostatni zawód na świecie. – Radosław Smilgin
PPTX
TGT#19 - Wszyscy jestesmy testerami - Michal Rabczuk
PPTX
TGT#20 - Ataki XSS - Robert Charewicz
PDF
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
PPTX
TGT#20 - TGT in Numbers - Mateusz Radkiewicz
PPTX
TGT#19 - 3 seconds or less - Piotr Liss
PPTX
TGT#18 - End-to-end testing using Protractor - Jakub Raniszewski
PPTX
TGT#18 - BDD with The Three Amigos in API Testing - Julia Szarlej
PPTX
TGT#17 - Efektywne testy oprogramowania w środowisku Scrumowym - Marcin Kubecki
PDF
TGT#17 - RestApi testing tips and tricks: how to start testing api of your we...
PPTX
TGT#16 - Pain of test automatization in PAAS/SAAS solutions - Krzysztof Lembi...
PPT
TGT#16 - Rozmowa techniczna (short talk) - Waldemar Mozoła
PPTX
TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
PPTX
TGT#15 - Piramida testów w praktyce (notatki z dyskusji)
PPTX
TGT#15 - Testowanie w metodykach zwinnych czyli skąd testerzy wiedzą więcej o...
PPTX
TGT#14 - @Before – Nie będę automatyzować @After – No dobra, to nie jest taki...
PPTX
TGT#14 - Case Study: Współpraca Testera i Product Ownera w zespole scrumowym ...
PPTX
TG#13 - Nie samym Selenium człowiek żyje, czyli jak tworzyć stabilne testy fu...
Rafal prezentacja testowanie ai
Tgt 23 przemyslaw_pradzynski
TGT#21 - Tester eksploracyjny, ostatni zawód na świecie. – Radosław Smilgin
TGT#19 - Wszyscy jestesmy testerami - Michal Rabczuk
TGT#20 - Ataki XSS - Robert Charewicz
TGT#20 - Automated Tests Only For Testers - Kasper Kulikowski
TGT#20 - TGT in Numbers - Mateusz Radkiewicz
TGT#19 - 3 seconds or less - Piotr Liss
TGT#18 - End-to-end testing using Protractor - Jakub Raniszewski
TGT#18 - BDD with The Three Amigos in API Testing - Julia Szarlej
TGT#17 - Efektywne testy oprogramowania w środowisku Scrumowym - Marcin Kubecki
TGT#17 - RestApi testing tips and tricks: how to start testing api of your we...
TGT#16 - Pain of test automatization in PAAS/SAAS solutions - Krzysztof Lembi...
TGT#16 - Rozmowa techniczna (short talk) - Waldemar Mozoła
TGT#16 - Sztuka projektowania testów - Agnieszka Garwolińska
TGT#15 - Piramida testów w praktyce (notatki z dyskusji)
TGT#15 - Testowanie w metodykach zwinnych czyli skąd testerzy wiedzą więcej o...
TGT#14 - @Before – Nie będę automatyzować @After – No dobra, to nie jest taki...
TGT#14 - Case Study: Współpraca Testera i Product Ownera w zespole scrumowym ...
TG#13 - Nie samym Selenium człowiek żyje, czyli jak tworzyć stabilne testy fu...

Recently uploaded (20)

PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Digital Systems & Binary Numbers (comprehensive )
PPTX
assetexplorer- product-overview - presentation
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
medical staffing services at VALiNTRY
PDF
iTop VPN Free 5.6.0.5262 Crack latest version 2025
PDF
Nekopoi APK 2025 free lastest update
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PPTX
Patient Appointment Booking in Odoo with online payment
Odoo Companies in India – Driving Business Transformation.pdf
CHAPTER 2 - PM Management and IT Context
AutoCAD Professional Crack 2025 With License Key
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Digital Systems & Binary Numbers (comprehensive )
assetexplorer- product-overview - presentation
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
medical staffing services at VALiNTRY
iTop VPN Free 5.6.0.5262 Crack latest version 2025
Nekopoi APK 2025 free lastest update
Navsoft: AI-Powered Business Solutions & Custom Software Development
Salesforce Agentforce AI Implementation.pdf
Transform Your Business with a Software ERP System
Product Update: Alluxio AI 3.7 Now with Sub-Millisecond Latency
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
Tally Prime Crack Download New Version 5.1 [2025] (License Key Free
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Patient Appointment Booking in Odoo with online payment

Marcin Wasilczyk - Page objects with selenium

  • 1. Page Objects with Selenium WebDriver Trójmiejska Grupa Testerska Spotkanie #3 Marcin Wasilczyk, Oleksandr Perepelytsya 16-Apr-15 1
  • 2. Commercial In Confidence & Proprietary, Kainos Software 2012 Agenda  Automated Testing overview  Selenium  Page Object pattern  Demo  Konkurs (z nagrodami ) 16-Apr-15 2
  • 3. Commercial In Confidence & Proprietary, Kainos Software 2012 Automated Testing overview 16-Apr-15 3 • Reduces amount of manual testing • Can be run frequently (e.g. every night/build) • Save testers time and is a quick signal to the dev team that something was broken recently (either test or application) • Requires effort to write them as reliable piece of software • Test code needs to be easy to maintain when application changes • The code should be as good as production code
  • 4. Commercial In Confidence & Proprietary, Kainos Software 2012 Selenium 16-Apr-15 4 • Is Selenium a test framework? Nope! • Selenium is a suite of tools that automate web browsers • Supports most of the browsers and operating systems • Could be used for • Automating boring web-based administration tasks • Testing (when run by external test framework like NUnit) • Two versions exist • Selenium RC (Remote Control) • Uses javascript ‘injection’ to control the browser • not supported anymore • Selenium WebDriver • Uses browser’s native support for automation
  • 5. Selenium Basic Concepts IWebDriver instance lets you control the browser ChromeDriver, InternetExplorerDriver, FirefoxDriver, etc... IWebElement instance lets you operate the page element IWebElement button = driver.FindElement(By.ClassName(“PrimaryButton”)); button.Click(); WebDriverWait lets you wait for elements being loaded var loadWait = new WebDriverWait(driver, TimeSpan.FromSeconds(5)); loadWait.Until(ExpectedConditions.TitleIs(„My Dashboard“)); 16-Apr-15 5
  • 6. Page Object pattern Create model of UI pages as objects Reduces the amount of duplicated code If you change anything in UI, fix will be applied only to one place Encapsulation of Page Object internals Client (e.g. NUnit test) will know only about services exposed as public methods Page Objects should return other Page Objects; examples: var userPage = loginPage.LoginAs(“username”, “password”); var loginPage = logoutPopup.Confirm(); Changing the id of the button you don’t need to change the test, only the page object’s internals will be modified 16-Apr-15 6
  • 7. Page Object pattern - summary Generally don't make assertions – these should be done in the test, not in the Page Object Need not represent an entire page Different results for the same action are modelled as different methods var patientRecordPage = dashboardPage.SimpleSearchForSinglePatientWith(searchText); var dashboardPage = dashboardPage.SimpleSearchForManyPatientsWith(searchText); 16-Apr-15 7
  • 8. Page Object pattern - example public class LoginPage { private IWebDriver Driver { get; set; } private IWebElement UserName { get; set; } private IWebElement Password { get; set; } private IWebElement LoginButton { get; set; } public LoginPage(IWebDriver driver) { Driver = driver; UserName = driver.FindElement(By....) // initialization of the remaining elements } // methods like public UserPage LoginAs(string username, string password) { ... } } 16-Apr-15 8
  • 9. Selenium – support of “Page Object pattern” PageFactory lets you automatically initialize elements defined in Page Object (binding - action) PageFactory.InitElements(driver, pageObject); FindsBy attribute - automatically find elements on page (binding - definition) CacheLookup attribute – caches found element [FindsBy(How = How.Id, Using = „userNameElement")] [CacheLookup] private IWebElement UserName { get; set; } 16-Apr-15 9
  • 10. Selenium – support of “Page Object pattern” public class LoginPage { private IWebDriver Driver { get; set; } [FindsBy(How = How.Id, Using = "ctl00_content_UserName")] [CacheLookup] private IWebElement UserName { get; set; } // ... other fields with attributes applied... public LoginPage(IWebDriver driver) { Driver = driver; PageFactory.InitElements(this.Driver, this); } // methods like public UserPage LoginAs(string username, string password) { ... } } 16-Apr-15 10
  • 12. Konkurs Test Steps: 1. Navigate to Home page 2. Search for “laptop” 3. Click on 3 (third) element in the results list 4. Remember seller name and price 5. Add to bucket 6. Verify that item in the bucket has the same seller and price 7. Remove item from bucket 8. Navigate to Home page 16-Apr-15 12