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

What's hot (20)

PPTX
Better Page Object Handling with Loadable Component Pattern
SQALab
 
PPTX
Automated Testing using JavaScript
Simon Guest
 
PDF
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
PPTX
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
PDF
Automated Web Testing using JavaScript
Simon Guest
 
PDF
UI Testing Automation
AgileEngine
 
PPTX
Automated UI testing done right (DDDSydney)
Mehdi Khalili
 
PDF
Workshop - E2e tests with protractor
Walmyr Lima e Silva Filho
 
PPTX
Protractor training
Sergiy Stotskiy
 
PDF
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
PPTX
Automation using Javascript
khanhdang1214
 
PDF
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
PPTX
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
PDF
Web UI test automation instruments
Artem Nagornyi
 
PDF
Selenium Overview
Abhijeet Vaikar
 
PPTX
Protractor overview
Abhishek Yadav
 
PDF
PHP Unit Testing in Yii
IlPeach
 
PDF
Automated Testing in Angular Slides
Jim Lynch
 
PDF
Automation Abstraction Layers: Page Objects and Beyond
Alan Richardson
 
PDF
Codeception presentation
Andrei Burian
 
Better Page Object Handling with Loadable Component Pattern
SQALab
 
Automated Testing using JavaScript
Simon Guest
 
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...
Applitools
 
UI Testing Automation - Alex Kalinovsky - CreamTec LLC
Jim Lane
 
Automated Web Testing using JavaScript
Simon Guest
 
UI Testing Automation
AgileEngine
 
Automated UI testing done right (DDDSydney)
Mehdi Khalili
 
Workshop - E2e tests with protractor
Walmyr Lima e Silva Filho
 
Protractor training
Sergiy Stotskiy
 
Acceptance & Functional Testing with Codeception - Devspace 2015
Joe Ferguson
 
Automation using Javascript
khanhdang1214
 
Test-driven Development with Drupal and Codeception (DrupalCamp Brighton)
Cogapp
 
Better End-to-End Testing with Page Objects Model using Protractor
Kasun Kodagoda
 
Web UI test automation instruments
Artem Nagornyi
 
Selenium Overview
Abhijeet Vaikar
 
Protractor overview
Abhishek Yadav
 
PHP Unit Testing in Yii
IlPeach
 
Automated Testing in Angular Slides
Jim Lynch
 
Automation Abstraction Layers: Page Objects and Beyond
Alan Richardson
 
Codeception presentation
Andrei Burian
 

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

PDF
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
PPT
I one aolpage-test-2010
Nicholas Tang
 
PDF
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Ondřej Machulda
 
PDF
Good practices for debugging Selenium and Appium tests
Abhijeet Vaikar
 
PPTX
Testing ASP.NET - Progressive.NET
Ben Hall
 
PPTX
Qa process
Aila Bogasieru
 
PDF
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
PPTX
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
ODP
Integrating Selenium testing infrastructure into Scala Project
Knoldus Inc.
 
PPTX
Qa process
Aila Bogasieru
 
PDF
Page object pattern
Petro Konopelko
 
PPTX
Slides for Automation Testing or End to End testing
SwapnilNarayan
 
PPTX
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
PPTX
Load Testing: See a Bigger Picture
Alexander Podelko
 
PDF
Automation Abstractions: Page Objects and Beyond
TechWell
 
PPTX
BDD with SpecFlow and Selenium
Liraz Shay
 
PDF
Advanced Techniques to Build an Efficient Selenium Framework
digitaljignect
 
PDF
Building a Robust WebDriverIO Test Automation Framework
digitaljignect
 
PPT
Selenium
husnara mohammad
 
PPT
Test Automation Framework Development Introduction
Ganuka Yashantha
 
Three Simple Chords of Alternative PageObjects and Hardcore of LoadableCompon...
Iakiv Kramarenko
 
I one aolpage-test-2010
Nicholas Tang
 
Workshop: Functional testing made easy with PHPUnit & Selenium (phpCE Poland,...
Ondřej Machulda
 
Good practices for debugging Selenium and Appium tests
Abhijeet Vaikar
 
Testing ASP.NET - Progressive.NET
Ben Hall
 
Qa process
Aila Bogasieru
 
Page Object Model and Implementation in Selenium
Zoe Gilbert
 
Mastering Test Automation: How To Use Selenium Successfully
SpringPeople
 
Integrating Selenium testing infrastructure into Scala Project
Knoldus Inc.
 
Qa process
Aila Bogasieru
 
Page object pattern
Petro Konopelko
 
Slides for Automation Testing or End to End testing
SwapnilNarayan
 
Improving Your Selenium WebDriver Tests - Belgium testing days_2016
Roy de Kleijn
 
Load Testing: See a Bigger Picture
Alexander Podelko
 
Automation Abstractions: Page Objects and Beyond
TechWell
 
BDD with SpecFlow and Selenium
Liraz Shay
 
Advanced Techniques to Build an Efficient Selenium Framework
digitaljignect
 
Building a Robust WebDriverIO Test Automation Framework
digitaljignect
 
Test Automation Framework Development Introduction
Ganuka Yashantha
 
Ad

More from Trójmiejska Grupa Testerska (20)

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

Recently uploaded (20)

PPTX
PCC IT Forum 2025 - Legislative Technology Snapshot
Gareth Oakes
 
PDF
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
PPTX
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
 
PPTX
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
PPTX
How Can Reporting Tools Improve Marketing Performance.pptx
Varsha Nayak
 
PDF
Understanding the EU Cyber Resilience Act
ICS
 
PDF
Simplify React app login with asgardeo-sdk
vaibhav289687
 
PPTX
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
PDF
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
 
PPTX
API DOCUMENTATION | API INTEGRATION PLATFORM
philipnathen82
 
PDF
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
PDF
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
PPTX
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
PDF
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
PDF
Introduction to Apache Iceberg™ & Tableflow
Alluxio, Inc.
 
PPTX
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 
PDF
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
PPTX
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
 
PPTX
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
PPTX
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 
PCC IT Forum 2025 - Legislative Technology Snapshot
Gareth Oakes
 
How Attendance Management Software is Revolutionizing Education.pdf
Pikmykid
 
ChessBase 18.02 Crack + Serial Key Free Download
cracked shares
 
Smart Doctor Appointment Booking option in odoo.pptx
AxisTechnolabs
 
How Can Reporting Tools Improve Marketing Performance.pptx
Varsha Nayak
 
Understanding the EU Cyber Resilience Act
ICS
 
Simplify React app login with asgardeo-sdk
vaibhav289687
 
Chess King 25.0.0.2500 With Crack Full Free Download
cracked shares
 
How to get the licensing right for Microsoft Core Infrastructure Server Suite...
Q-Advise
 
API DOCUMENTATION | API INTEGRATION PLATFORM
philipnathen82
 
Virtual Threads in Java: A New Dimension of Scalability and Performance
Tier1 app
 
Everything you need to know about pricing & licensing Microsoft 365 Copilot f...
Q-Advise
 
Get Started with Maestro: Agent, Robot, and Human in Action – Session 5 of 5
klpathrudu
 
Salesforce Experience Cloud Consultant.pdf
VALiNTRY360
 
Introduction to Apache Iceberg™ & Tableflow
Alluxio, Inc.
 
MiniTool Partition Wizard Crack 12.8 + Serial Key Download Latest [2025]
filmoracrack9001
 
SAP GUI Installation Guide for Windows | Step-by-Step Setup for SAP Access
SAP Vista, an A L T Z E N Company
 
TexSender Pro 8.9.1 Crack Full Version Download
cracked shares
 
Transforming Insights: How Generative AI is Revolutionizing Data Analytics
LetsAI Solutions
 
prodad heroglyph crack 2.0.214.2 Full Free Download
cracked shares
 

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