SlideShare a Scribd company logo
1 of 14
and the PageObject Design Model
www.Seleniumonlinetraining.info
1
 How Selenium Remote Control works
 You launch a server on your test machine.
 Your tests connect to that server via IP.
 The server launches a browser, with selenium CORE
embedded as javascript into the page.
 Selenium CORE simulates user actions with javascript.
www.Seleniumonlinetraining.info
2
THE GOOD THE BAD
 Doesn’t steal your
mouse/keyboard.
 Works with any browser that
uses javascript
 Works for any OS that
supports java.
 Very fast page interactions.
 Large API
 Supports a variety of
programming languages.
 Can be run on remote
machines
 Can’t see anything outside
the page object.
 Not all browsers support all
functionality.
 Some pages aren’t
automatable.
 Can’t see inside third party
apps
 XSS Limitations
www.Seleniumonlinetraining.info
3
 A different way of automating the browser.
 Create a browser-specific driver to control the browser
directly.
 Have to do this for each browser!
 Object oriented API
 Doesn’t need a real browser
 No javascript limitations
 No need for a server.
 Isn’t as delicate as selenium.
www.Seleniumonlinetraining.info
4
 Went into Beta Dec 24th
.
 WebDriver + Selenium
 The two projects have merged (literally) into
Selenium 2.0
 Large browser support and no javascript limitations.
 No server
 The old API’s are still available.
 New API’s are becoming available.
www.Seleniumonlinetraining.info
5
 You have 2 options:
 IWebDriver
 This is just the WebDriver api
 Doesn’t support a lot of browsers.
 Will need to change all your tests.
 WebDriverBackedSelenium
 Uses the old Selenium 1 API
 But uses WebDriver to run things if possible
 Can use selenium 1 if the browser isn’t supported.
www.Seleniumonlinetraining.info
6
 Object Oriented
 Doesn’t break nearly as often
 Handles pageloads automatically
 Fewer problems automating
 Somewhat more complicated API
 selenium.type(“password”,”thisIsMyPassword”);
 driver.findElement(By.id("password")).sendKeys(“thisIsMyPassword");
 By.Id, By.Xpath, By.Name, By.ClassName, By.PartialLinkText
 All the supported browsers work really well
 Can extend the API to add custom functionality.
 Works well with a Page Object design model.
www.Seleniumonlinetraining.info
7
 Adds a layer of abstraction into your code.
 Helps to organize your code once it grows large.
 All automation is automatically reusable and shareable.
 A way to separate tests from re-usable functions.
 A way to store information about how the system works.
 A way to specify what page functions start on, and what page they end on.
 A way to programmatically break your tests when functionality changes.
 Makes code maintenance easier.
 There is even a PageFactory class available to automatically create them.
www.Seleniumonlinetraining.info
8
 Each page is defined as it’s own class.
 Actions (including navigation) are represented as functions for a class.
 Each function returns a new Page object, signifying what page the actions stops
on.
 Your tests “know” what page you are on, and will only give you access to
functions available to that class.
 Tests only talk to the page objects.
 Page objects only talk to the driver.
 Elements on the page are stored as variables for the page object.
 Automatic page validations can be stored in the constructor for each page
object.
 Tests become a string of well defined functions, not meaningless gibberish.
 Tests can be grouped by namespace.
 Class Inheritance can be used to define functionality to a set of pages.
 We can make functional logic transparent to the tests by returning different
inherited classes.
www.Seleniumonlinetraining.info
9
globalVars.logDescription = "log in";
globalVars.selenium.Open(globalVars.mobiUrl);
functions.type("userId", globalVars.studName + "1");
functions.type("password", globalVars.studPass + "1");
functions.clickAndWait("signInBtn");
selenium.click("//a[@id='discussions']/span");
selenium.click("//a[@id='thingsToKnow']/span");
globalVars.logDescription = "Checking elements on happenings:by date page";
selenium.waitForElementNotVisible("//div[@id='THSContainer']//span[@class='ajaxLoadingHeader']");
selenium.waitForElementVisible("//div[@id='THSContainer']/ul[1]/li[1]");
selenium.click("//div[@id='THSContainer']//span[@class='replytext']");
selenium.click("backButton");
selenium.waitForElementVisible("//div[@id='TTHContainer']/ul[1]/li[1]");
selenium.click("//div[@id='TTHContainer']//span[@class='replytext']");
selenium.click("backButton");
globalVars.selenium.Select("byDateFilter", "label=Things Happening Soon");
selenium.waitForElementVisible("//div[@id='THSContainer']/ul[1]/li[1]");
selenium.click("//div[@id='THSContainer']//span[@class='replytext']");
selenium.click("backButton");
globalVars.selenium.Select("byDateFilter", "label=Things That Happened");
www.Seleniumonlinetraining.info
10
[Test]
public void testByDateTab()
{
funtions.loginMobi();
selenium.click("//a[@id='discussions']/span");
selenium.click("//a[@id='thingsToKnow']/span");
functions.verifyThingsToKnow();
functions.verifyThingsHappeningSoon();
selenium.Select("byDateFilter", "label=Things That Happened");
functions.verifyThingsThatHappened();
}
www.Seleniumonlinetraining.info
11
[Test]
public void testByDateTab()
{
selenium.Open(Moby_Common.MobyLoginUrl);
LoginPage loginPage = new LoginPage(selenium);
HappeningsPage happeningsPage = loginPage.loginAs(Common.stud1Name, Common.stud1Password);
happeningsPage.waitToLoad();
Assert.That(!happeningsPage.isByTypePageLoaded());
Assert.That(happeningsPage.isByDatePageLoaded());
Assert.That(!happeningsPage.isByCoursePageLoaded());
happeningsPage.filterResults("byDateFilter","Things That Happened");
Assert.That(happeningsPage.isVisible("TTHContainer"));
happeningsPage.filterResults("byDateFilter", "Things Happening Soon");
Assert.That(happeningsPage.isVisible("THSContainer"));
happeningsPage.filterResults("byDateFilter", "All Types");
Assert.That(happeningsPage.isVisible("TTHContainer"));
Assert.That(happeningsPage.isVisible("THSContainer"));
}
www.Seleniumonlinetraining.info
12
public class HappeningsPage : WebPageBaseClass
{
private string _loadingImage =
"//span[@class='ajaxLoadingHeader']";
private string _moreLink = "more";
public HappeningsPage(ISelenium selenium)
{
this.selenium = selenium;
this.title = "Happenings";
this.url = "index.html";
assertPageLoadedCorrectly();
}
public HappeningsPage waitToLoad()
{
waitForElementNotVisible(_loadingImage );
return new HappeningsPage(selenium);
}
public ContentItemPage goToItem(string type, string name)
{
click("//div[@id='" + type + "']//span[text()="" + name +
""]");
return new ContentItemPage(selenium);
}
public HappeningsPage clickMoreLink()
{
click(_moreLink);
return new HappeningsPage(selenium);
}
public HappeningsPage filterResults(string id, string name)
{
selectDropdown(id, name);
return new HappeningsPage(selenium);
}
}
www.Seleniumonlinetraining.info
13
www.Seleniumonlinetraining.info
14

More Related Content

More from onlinemindq

A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2onlinemindq
 
Selenium Open Source Tool
Selenium Open Source ToolSelenium Open Source Tool
Selenium Open Source Toolonlinemindq
 

More from onlinemindq (6)

Selenium 2
Selenium 2Selenium 2
Selenium 2
 
Selenium (2)
Selenium (2)Selenium (2)
Selenium (2)
 
Selenium (1)
Selenium (1)Selenium (1)
Selenium (1)
 
Selenium.ppt
Selenium.pptSelenium.ppt
Selenium.ppt
 
A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2A Buffer's Guide to Selenium 2
A Buffer's Guide to Selenium 2
 
Selenium Open Source Tool
Selenium Open Source ToolSelenium Open Source Tool
Selenium Open Source Tool
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxMaryGraceBautista27
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parentsnavabharathschool99
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17Celine George
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONHumphrey A Beña
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
Science 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptxScience 7 Quarter 4 Module 2: Natural Resources.pptx
Science 7 Quarter 4 Module 2: Natural Resources.pptx
 
Choosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for ParentsChoosing the Right CBSE School A Comprehensive Guide for Parents
Choosing the Right CBSE School A Comprehensive Guide for Parents
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17How to Add Barcode on PDF Report in Odoo 17
How to Add Barcode on PDF Report in Odoo 17
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATIONTHEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
THEORIES OF ORGANIZATION-PUBLIC ADMINISTRATION
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 

Automation w selenium_brian_kitchner (1)

  • 1. and the PageObject Design Model www.Seleniumonlinetraining.info 1
  • 2.  How Selenium Remote Control works  You launch a server on your test machine.  Your tests connect to that server via IP.  The server launches a browser, with selenium CORE embedded as javascript into the page.  Selenium CORE simulates user actions with javascript. www.Seleniumonlinetraining.info 2
  • 3. THE GOOD THE BAD  Doesn’t steal your mouse/keyboard.  Works with any browser that uses javascript  Works for any OS that supports java.  Very fast page interactions.  Large API  Supports a variety of programming languages.  Can be run on remote machines  Can’t see anything outside the page object.  Not all browsers support all functionality.  Some pages aren’t automatable.  Can’t see inside third party apps  XSS Limitations www.Seleniumonlinetraining.info 3
  • 4.  A different way of automating the browser.  Create a browser-specific driver to control the browser directly.  Have to do this for each browser!  Object oriented API  Doesn’t need a real browser  No javascript limitations  No need for a server.  Isn’t as delicate as selenium. www.Seleniumonlinetraining.info 4
  • 5.  Went into Beta Dec 24th .  WebDriver + Selenium  The two projects have merged (literally) into Selenium 2.0  Large browser support and no javascript limitations.  No server  The old API’s are still available.  New API’s are becoming available. www.Seleniumonlinetraining.info 5
  • 6.  You have 2 options:  IWebDriver  This is just the WebDriver api  Doesn’t support a lot of browsers.  Will need to change all your tests.  WebDriverBackedSelenium  Uses the old Selenium 1 API  But uses WebDriver to run things if possible  Can use selenium 1 if the browser isn’t supported. www.Seleniumonlinetraining.info 6
  • 7.  Object Oriented  Doesn’t break nearly as often  Handles pageloads automatically  Fewer problems automating  Somewhat more complicated API  selenium.type(“password”,”thisIsMyPassword”);  driver.findElement(By.id("password")).sendKeys(“thisIsMyPassword");  By.Id, By.Xpath, By.Name, By.ClassName, By.PartialLinkText  All the supported browsers work really well  Can extend the API to add custom functionality.  Works well with a Page Object design model. www.Seleniumonlinetraining.info 7
  • 8.  Adds a layer of abstraction into your code.  Helps to organize your code once it grows large.  All automation is automatically reusable and shareable.  A way to separate tests from re-usable functions.  A way to store information about how the system works.  A way to specify what page functions start on, and what page they end on.  A way to programmatically break your tests when functionality changes.  Makes code maintenance easier.  There is even a PageFactory class available to automatically create them. www.Seleniumonlinetraining.info 8
  • 9.  Each page is defined as it’s own class.  Actions (including navigation) are represented as functions for a class.  Each function returns a new Page object, signifying what page the actions stops on.  Your tests “know” what page you are on, and will only give you access to functions available to that class.  Tests only talk to the page objects.  Page objects only talk to the driver.  Elements on the page are stored as variables for the page object.  Automatic page validations can be stored in the constructor for each page object.  Tests become a string of well defined functions, not meaningless gibberish.  Tests can be grouped by namespace.  Class Inheritance can be used to define functionality to a set of pages.  We can make functional logic transparent to the tests by returning different inherited classes. www.Seleniumonlinetraining.info 9
  • 10. globalVars.logDescription = "log in"; globalVars.selenium.Open(globalVars.mobiUrl); functions.type("userId", globalVars.studName + "1"); functions.type("password", globalVars.studPass + "1"); functions.clickAndWait("signInBtn"); selenium.click("//a[@id='discussions']/span"); selenium.click("//a[@id='thingsToKnow']/span"); globalVars.logDescription = "Checking elements on happenings:by date page"; selenium.waitForElementNotVisible("//div[@id='THSContainer']//span[@class='ajaxLoadingHeader']"); selenium.waitForElementVisible("//div[@id='THSContainer']/ul[1]/li[1]"); selenium.click("//div[@id='THSContainer']//span[@class='replytext']"); selenium.click("backButton"); selenium.waitForElementVisible("//div[@id='TTHContainer']/ul[1]/li[1]"); selenium.click("//div[@id='TTHContainer']//span[@class='replytext']"); selenium.click("backButton"); globalVars.selenium.Select("byDateFilter", "label=Things Happening Soon"); selenium.waitForElementVisible("//div[@id='THSContainer']/ul[1]/li[1]"); selenium.click("//div[@id='THSContainer']//span[@class='replytext']"); selenium.click("backButton"); globalVars.selenium.Select("byDateFilter", "label=Things That Happened"); www.Seleniumonlinetraining.info 10
  • 12. [Test] public void testByDateTab() { selenium.Open(Moby_Common.MobyLoginUrl); LoginPage loginPage = new LoginPage(selenium); HappeningsPage happeningsPage = loginPage.loginAs(Common.stud1Name, Common.stud1Password); happeningsPage.waitToLoad(); Assert.That(!happeningsPage.isByTypePageLoaded()); Assert.That(happeningsPage.isByDatePageLoaded()); Assert.That(!happeningsPage.isByCoursePageLoaded()); happeningsPage.filterResults("byDateFilter","Things That Happened"); Assert.That(happeningsPage.isVisible("TTHContainer")); happeningsPage.filterResults("byDateFilter", "Things Happening Soon"); Assert.That(happeningsPage.isVisible("THSContainer")); happeningsPage.filterResults("byDateFilter", "All Types"); Assert.That(happeningsPage.isVisible("TTHContainer")); Assert.That(happeningsPage.isVisible("THSContainer")); } www.Seleniumonlinetraining.info 12
  • 13. public class HappeningsPage : WebPageBaseClass { private string _loadingImage = "//span[@class='ajaxLoadingHeader']"; private string _moreLink = "more"; public HappeningsPage(ISelenium selenium) { this.selenium = selenium; this.title = "Happenings"; this.url = "index.html"; assertPageLoadedCorrectly(); } public HappeningsPage waitToLoad() { waitForElementNotVisible(_loadingImage ); return new HappeningsPage(selenium); } public ContentItemPage goToItem(string type, string name) { click("//div[@id='" + type + "']//span[text()="" + name + ""]"); return new ContentItemPage(selenium); } public HappeningsPage clickMoreLink() { click(_moreLink); return new HappeningsPage(selenium); } public HappeningsPage filterResults(string id, string name) { selectDropdown(id, name); return new HappeningsPage(selenium); } } www.Seleniumonlinetraining.info 13

Editor's Notes

  1. seleniumonlinetraining.info
  2. seleniumonlinetraining.info