SlideShare a Scribd company logo
Page Object From the Ground Up
Joseph Beale
02/07/2017
Agenda
1. Prepare the Environment
2.Build Automated Test using Watir
3.Convert to Page Object
4.Final Test Run
5.Q&A and Fun Time
But first...
Could I have a volunteer from the audience?
Environment
Create a folder called “test_project” under
c:rubyprograms
Environment
Inside of test_project, create a folder called
“features”. Then inside of that, create three
more called “step_definitions”, “support”,
and “pages”.
Environment
Open up the features -> support folder and
create a new text file called “env.rb”.
Environment
This demonstration will require you to have
Ruby installed on your system. For this, go
to https://rubyinstaller.org/ and download
the necessary installer. Then follow the
directions there.
After installing Ruby, grab the Cucumber
gem by typing “gem install cucumber” at a
command prompt.
Environment
We will need two more gems for this
demonstration:
• rspec
• page-object
Q: What is a Ruby gem?
A: A pre-built code module that performs
some useful function in Ruby, available for
free from https://rubygems.org
Environment
Open up env.rb using Notepad++ (free
download) and add the following
statements:
Require statements tell Ruby that you are
going to use some extra code modules.
Build
Create a feature file and a test scenario:
Cucumber scenarios are written in ordinary
business language using Gherkin
keywords (“Feature:”, “Scenario:”, “Given”,
“When”, “Then”, “And”, “But”).
Build
Optional: Create a batch file to execute
your test.
Build
These commands tell the operating system
to:
1.Open up a new command prompt in the
current directory
(c:rubyprogramstest_project).
2.Execute the “cucumber” command
3.Create a new report called “report.html”
and format it as an html document.
4.Open up the report.
Build
You can go ahead and run the test with no
other effort. It will not do much, but
Cucumber will give you a head start:
Build
Create a file called “my_steps.rb” in the
step_definitions folder and paste the
helper code snippets there:
Build
First step:
Given I am on the Bing home page
To satisfy this step, we need to open a
browser and navigate to the Bing home
page.
How do we do this in Ruby?
Build using Watir
Source: https://watir.github.io/
Build using Watir
Right on the front page is the code we
need to create a browser object (along
with lots of other helpful code):
We will use these exact lines of code but
modify them for our purposes.
Build using Watir
We will create “$browser” using the code
they gave us, but we will put it in the
env.rb file so that it is created before any
of the steps are run:
Build using Watir
Q: Why did you put a ‘$’ in front of your object
name?
A: To indicate that it is a global variable.
We want the browser object to be accessible
to all steps, so we make it global.
Build using Watir
In the first step definition, we will put the
next line of code, but modified to reflect
our global browser object and the URL for
Bing.com:
Now when we run our test we will get...
Build using Watir
...the Bing home page!
Build using Watir
Note that our report now shows one step is
green, meaning that it has passed:
Build using Watir
A quick word about method calls: the
format for calling a method in Ruby is
(object name) + dot (‘.’) + (method name).
So in the method call below, the object
name is ‘$browser’ and the method name
is ‘goto’.
Build using Watir
The ‘goto’ method is just one of the pre-
defined methods inside of the Watir::Browser
class. The method takes one argument: a
URL (because it needs to know where to “go
to”).
Arguments can be passed either inside of
parentheses or alongside a method call. So
in the previous example we could have said:
$browser.goto(‘bing.com’)
Build using Watir
Second step:
When I search the phrase "Call me Ishmael"
To automate this step, we need to interact
with two elements on the page:
1. The search text field
2. The search button (indicated by the
magnifying glass icon).
Build using Watir
Watir has several methods in the Browser
class to interact with the elements that are
common to most web pages. The two we
need are listed in the example given on their
home page (right under the ‘goto’):
Build using Watir
To interact with the two search elements, we
will use the ‘text_field’ and ‘button’ methods.
These two methods each take one argument:
a locator as indicated by the syntax (locator:
‘unique_identifier’).
For example:
$browser.text_field(id: ‘my_id’).set ‘my text’
$browser.button(id: ‘my_button’).click
Build using Watir
The locators are part of the page’s
Document Object Model or DOM, which is
a model of the page’s html code. But you
don’t need to understand the underlying
code; all you need to know is how to
inspect your desired elements.
Build using Watir
If you are using Chrome browser, you can
activate DevTools in three ways:
Source:
https://developers.google.com/web/tools/chrome-devtools/
Build using Watir
Inspecting the search box yields:
Build using Watir
The most common locator to use is ‘id’, so
we will copy the value for the id locator
(“sb_form_q”) and use it in our code for
the text_field method.
Build using Watir
Once nice feature of Ruby method calls is the
ability to “chain” methods one right after
another. Ruby will execute them in the order
given, from left to right. That is what you see
in the text_field example:
The ‘set’ method is executed right after the
text_field method.
Build using Watir
You can use the ‘set’ method anytime you
have defined a text field element using the
‘text_field’ method. It takes one argument: the
word or phrase that you wish to place in the
field. So, substituting a helpful variable name
like “search_phrase” for “arg1” in the code
snippet, the code for our second step looks
like this:
Build using Watir
Q: Where does the value for
“search_phrase” come from?
A: It is passed into the code from the
Gherkin step using a capture group.
This cryptic bit of code "([^"]*)" grabs
whatever is between the double-quotes
and throws it into my given variable.
Build using Watir
Since the variable search_phrase is a string,
we can use it as an argument for the set
method. And so then we are able to use that
same Ruby code block no matter what
phrase is used in the Gherkin.
Step →
Step definition →
Build using Watir
Now running the test yields:
For the button element, we’ll do it exactly
like we did the text field except that
instead of using the set method we will
need to find a method that will click the
button. The method name in this case is -
surprise! - click. From the Watir site:
browser.button(type: 'submit').click
Build using Watir
For most buttons, the locator they are using
(type: ‘submit’) will work but it’s not
specific enough so we’ll use the id to
locate the field. Adding that and the dollar
sign for the global variable, our step
definition looks like this:
Build using Watir
Running again we get:
Build using Watir
And in the report two steps are now green:
Build using Watir
Third step:
Then I will see results that contain “Moby
Dick”
Somehow we need to get our code to
examine the result page and check to see
if our phrase “Moby Dick” is found
anywhere. This is where the RSpec gem
comes in handy.
Build using Watir
There are many different ways to compare
fields using RSpec, but the one we will use
is a combination of “should” and “include”.
To locate the results area, we found that
we can use the ‘div’ method and an id of
‘b_content’.
Build using Watir
Running again causes all steps to pass:
Why Page Object
The Problem: If you have multiple tests or
even multiple steps that use the same
page elements, it’s tedious to keep having
to locate them by id again and again.
The Solution: Store all of the attributes for
any given page in one place, assign them
labels, and then in your steps simply refer
to the pages and the labels.
Convert to Page Object
The Page Object gem requires some
additional lines of code in the env.rb file:
Hint: code it and forget it.
Convert to Page Object
For each page where we need to interact
with fields or other attributes, we will need
to create a class (blueprint for an object):
Convert to Page Object
When we create a class to represent a
page, we are creating a situation where
the attributes of the page are already
defined and they are just waiting for the
page object to be instantiated by creating
a new instance of the class. Once that is
done, the user has access to all of the
attribute methods.
Convert to Page Object
Digging into the code for the two page
classes:
Convert to Page Object
Q: Why use ‘include’?
A: This will pull all of the standard Page
Object methods into your class.
http://www.rubydoc.info/github/cheezy/page-object/PageObject/Accessors
Convert to Page Object
For example:
Convert to Page Object
Here is what our steps will look like:
Convert to Page Object
Special Page Object Methods
visit - grabs the URL passed to the
‘page_url’ method and executes a ‘goto’
method on it.
on_page or on - instantiates the named
page and allows you to access its
attributes and their methods.
Final Test Run
Running again, we see the steps are still
green:
Questions/Answers
Does anyone have a question?
Let’s Stay In Touch
Contact me:
joseph.beale92@gmail.com
Connect with me on LinkedIn:
www.linkedin.com/in/JosephBealeQA
Follow me on Twitter: @JosephBealeQA

More Related Content

PPT
Web Performance Tips
PDF
Java script browser objects 1
 
PPTX
JavaScript : A trending scripting language
PPTX
Intro to jQuery
PPTX
PDF
How AngularDart & Firebase did an App together
PDF
Ten practical ways to improve front-end performance
PDF
Create responsive websites with Django, REST and AngularJS
Web Performance Tips
Java script browser objects 1
 
JavaScript : A trending scripting language
Intro to jQuery
How AngularDart & Firebase did an App together
Ten practical ways to improve front-end performance
Create responsive websites with Django, REST and AngularJS

What's hot (19)

PDF
Front Ends for Back End Developers - Spring I/O 2017
PPT
OpenSocial Intro
PPTX
An introduction to Vue.js
PPT
Wookie Meetup
PPT
jQuery introduction
PDF
Advanced java script essentials v1
PDF
Learning from the Best jQuery Plugins
PPTX
Local SQLite Database with Node for beginners
PPT
Django
PDF
The Art of AngularJS in 2015
PPT
Grails and Dojo
PPT
Enhance Web Performance
PDF
Testing web APIs
PDF
BDD with cucumber
PDF
Java REST API Framework Comparison - UberConf 2021
PDF
Web Components
PDF
Chrome enchanted 2015
PDF
Top 7 Angular Best Practices to Organize Your Angular App
PDF
Introduction to App Engine Development
Front Ends for Back End Developers - Spring I/O 2017
OpenSocial Intro
An introduction to Vue.js
Wookie Meetup
jQuery introduction
Advanced java script essentials v1
Learning from the Best jQuery Plugins
Local SQLite Database with Node for beginners
Django
The Art of AngularJS in 2015
Grails and Dojo
Enhance Web Performance
Testing web APIs
BDD with cucumber
Java REST API Framework Comparison - UberConf 2021
Web Components
Chrome enchanted 2015
Top 7 Angular Best Practices to Organize Your Angular App
Introduction to App Engine Development
Ad

Viewers also liked (6)

PPTX
Defect Triage by Matt Eakin
PPTX
Testing and checking by Newton Olivieri
PDF
Create testing commandos for creative problem solving!!! by Pradeepa Narayana...
PPTX
Security Testing by Ken De Souza
PDF
Bringing the hacker mindset into requirements and testing by Eapen Thomas and...
PDF
Digital transformation continues to drive IT strategy, How is QA and testing ...
Defect Triage by Matt Eakin
Testing and checking by Newton Olivieri
Create testing commandos for creative problem solving!!! by Pradeepa Narayana...
Security Testing by Ken De Souza
Bringing the hacker mindset into requirements and testing by Eapen Thomas and...
Digital transformation continues to drive IT strategy, How is QA and testing ...
Ad

Similar to Page object from the ground up by Joe Beale (20)

PPTX
Cucumber From the Ground Up - Joseph Beale
PPT
Watir Presentation Sumanth Krishna. A
PPT
What you can do In WatiR
PPT
Introduction To Ruby Watir (Web Application Testing In Ruby)
PPTX
Test Automation using Ruby
PDF
Espremendo melancia | TDC2014 Floripa | Chaordic
PDF
Espremendo melancia | TDC2014 Floripa | Chaordic
PPT
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
PPTX
Cross Browser Automation Testing Using Watir
PPTX
Making Watir and Cucumber an efficient tool for Web UI Automation
PDF
End-to-end web-testing in ruby ecosystem
PPT
No Va Taig April 7 2010
PDF
ruby pentest
ZIP
Ruby Kaigi 2008 LT
PDF
How to Begin to Develop Ruby Core
PPTX
MyHeritage - End 2 End testing Infra
PDF
Cucumber
PDF
full-stack-webapp-testing-with-selenium-and-rails.pdf
PDF
I'm watir
ZIP
Web Scraping In Ruby Utosc 2009.Key
Cucumber From the Ground Up - Joseph Beale
Watir Presentation Sumanth Krishna. A
What you can do In WatiR
Introduction To Ruby Watir (Web Application Testing In Ruby)
Test Automation using Ruby
Espremendo melancia | TDC2014 Floripa | Chaordic
Espremendo melancia | TDC2014 Floripa | Chaordic
Test Automation using Ruby, Watir, Rspec and AutoIT for GAMESCALE products te...
Cross Browser Automation Testing Using Watir
Making Watir and Cucumber an efficient tool for Web UI Automation
End-to-end web-testing in ruby ecosystem
No Va Taig April 7 2010
ruby pentest
Ruby Kaigi 2008 LT
How to Begin to Develop Ruby Core
MyHeritage - End 2 End testing Infra
Cucumber
full-stack-webapp-testing-with-selenium-and-rails.pdf
I'm watir
Web Scraping In Ruby Utosc 2009.Key

More from QA or the Highway (20)

PDF
KrishnaToolComparisionPPT.pdf
PPTX
Ravi Lakkavalli - World Quality Report.pptx
PPTX
Caleb Crandall - Testing Between the Buckets.pptx
PDF
Thomas Haver - Mobile Testing.pdf
PDF
Thomas Haver - Example Mapping.pdf
PDF
Joe Colantonio - Actionable Automation Awesomeness in Testing Farm.pdf
PDF
Sarah Geisinger - Continious Testing Metrics That Matter.pdf
PDF
Jeff Sing - Quarterly Service Delivery Reviews.pdf
PDF
Leandro Melendez - Chihuahua Load Tests.pdf
PDF
Rick Clymer - Incident Management.pdf
PPTX
Robert Fornal - ChatGPT as a Testing Tool.pptx
PDF
Federico Toledo - Extra-functional testing.pdf
PPTX
Andrew Knight - Managing the Test Data Nightmare.pptx
PDF
Melissa Tondi - Automation We_re Doing it Wrong.pdf
PDF
Jeff Van Fleet and John Townsend - Transition from Testing to Leadership.pdf
PPTX
DesiradhaRam Gadde - Testers _ Testing in ChatGPT-AI world.pptx
PDF
Damian Synadinos - Word Smatter.pdf
PDF
Lee Barnes - What Successful Test Automation is.pdf
PPTX
Jordan Powell - API Testing with Cypress.pptx
PPTX
Carlos Kidman - Exploring AI Applications in Testing.pptx
KrishnaToolComparisionPPT.pdf
Ravi Lakkavalli - World Quality Report.pptx
Caleb Crandall - Testing Between the Buckets.pptx
Thomas Haver - Mobile Testing.pdf
Thomas Haver - Example Mapping.pdf
Joe Colantonio - Actionable Automation Awesomeness in Testing Farm.pdf
Sarah Geisinger - Continious Testing Metrics That Matter.pdf
Jeff Sing - Quarterly Service Delivery Reviews.pdf
Leandro Melendez - Chihuahua Load Tests.pdf
Rick Clymer - Incident Management.pdf
Robert Fornal - ChatGPT as a Testing Tool.pptx
Federico Toledo - Extra-functional testing.pdf
Andrew Knight - Managing the Test Data Nightmare.pptx
Melissa Tondi - Automation We_re Doing it Wrong.pdf
Jeff Van Fleet and John Townsend - Transition from Testing to Leadership.pdf
DesiradhaRam Gadde - Testers _ Testing in ChatGPT-AI world.pptx
Damian Synadinos - Word Smatter.pdf
Lee Barnes - What Successful Test Automation is.pdf
Jordan Powell - API Testing with Cypress.pptx
Carlos Kidman - Exploring AI Applications in Testing.pptx

Recently uploaded (20)

PPTX
Funds Management Learning Material for Beg
PDF
Tenda Login Guide: Access Your Router in 5 Easy Steps
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
The Internet -By the Numbers, Sri Lanka Edition
PDF
Slides PDF The World Game (s) Eco Economic Epochs.pdf
PPTX
presentation_pfe-universite-molay-seltan.pptx
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PPT
tcp ip networks nd ip layering assotred slides
PDF
Testing WebRTC applications at scale.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PPTX
Slides PPTX World Game (s) Eco Economic Epochs.pptx
PPTX
SAP Ariba Sourcing PPT for learning material
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
DOCX
Unit-3 cyber security network security of internet system
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PPTX
522797556-Unit-2-Temperature-measurement-1-1.pptx
Funds Management Learning Material for Beg
Tenda Login Guide: Access Your Router in 5 Easy Steps
Introuction about ICD -10 and ICD-11 PPT.pptx
Module 1 - Cyber Law and Ethics 101.pptx
Unit-1 introduction to cyber security discuss about how to secure a system
The Internet -By the Numbers, Sri Lanka Edition
Slides PDF The World Game (s) Eco Economic Epochs.pdf
presentation_pfe-universite-molay-seltan.pptx
Design_with_Watersergyerge45hrbgre4top (1).ppt
tcp ip networks nd ip layering assotred slides
Testing WebRTC applications at scale.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
Slides PPTX World Game (s) Eco Economic Epochs.pptx
SAP Ariba Sourcing PPT for learning material
SASE Traffic Flow - ZTNA Connector-1.pdf
Unit-3 cyber security network security of internet system
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
522797556-Unit-2-Temperature-measurement-1-1.pptx

Page object from the ground up by Joe Beale

  • 1. Page Object From the Ground Up Joseph Beale 02/07/2017
  • 2. Agenda 1. Prepare the Environment 2.Build Automated Test using Watir 3.Convert to Page Object 4.Final Test Run 5.Q&A and Fun Time
  • 3. But first... Could I have a volunteer from the audience?
  • 4. Environment Create a folder called “test_project” under c:rubyprograms
  • 5. Environment Inside of test_project, create a folder called “features”. Then inside of that, create three more called “step_definitions”, “support”, and “pages”.
  • 6. Environment Open up the features -> support folder and create a new text file called “env.rb”.
  • 7. Environment This demonstration will require you to have Ruby installed on your system. For this, go to https://rubyinstaller.org/ and download the necessary installer. Then follow the directions there. After installing Ruby, grab the Cucumber gem by typing “gem install cucumber” at a command prompt.
  • 8. Environment We will need two more gems for this demonstration: • rspec • page-object Q: What is a Ruby gem? A: A pre-built code module that performs some useful function in Ruby, available for free from https://rubygems.org
  • 9. Environment Open up env.rb using Notepad++ (free download) and add the following statements: Require statements tell Ruby that you are going to use some extra code modules.
  • 10. Build Create a feature file and a test scenario: Cucumber scenarios are written in ordinary business language using Gherkin keywords (“Feature:”, “Scenario:”, “Given”, “When”, “Then”, “And”, “But”).
  • 11. Build Optional: Create a batch file to execute your test.
  • 12. Build These commands tell the operating system to: 1.Open up a new command prompt in the current directory (c:rubyprogramstest_project). 2.Execute the “cucumber” command 3.Create a new report called “report.html” and format it as an html document. 4.Open up the report.
  • 13. Build You can go ahead and run the test with no other effort. It will not do much, but Cucumber will give you a head start:
  • 14. Build Create a file called “my_steps.rb” in the step_definitions folder and paste the helper code snippets there:
  • 15. Build First step: Given I am on the Bing home page To satisfy this step, we need to open a browser and navigate to the Bing home page. How do we do this in Ruby?
  • 16. Build using Watir Source: https://watir.github.io/
  • 17. Build using Watir Right on the front page is the code we need to create a browser object (along with lots of other helpful code): We will use these exact lines of code but modify them for our purposes.
  • 18. Build using Watir We will create “$browser” using the code they gave us, but we will put it in the env.rb file so that it is created before any of the steps are run:
  • 19. Build using Watir Q: Why did you put a ‘$’ in front of your object name? A: To indicate that it is a global variable. We want the browser object to be accessible to all steps, so we make it global.
  • 20. Build using Watir In the first step definition, we will put the next line of code, but modified to reflect our global browser object and the URL for Bing.com: Now when we run our test we will get...
  • 21. Build using Watir ...the Bing home page!
  • 22. Build using Watir Note that our report now shows one step is green, meaning that it has passed:
  • 23. Build using Watir A quick word about method calls: the format for calling a method in Ruby is (object name) + dot (‘.’) + (method name). So in the method call below, the object name is ‘$browser’ and the method name is ‘goto’.
  • 24. Build using Watir The ‘goto’ method is just one of the pre- defined methods inside of the Watir::Browser class. The method takes one argument: a URL (because it needs to know where to “go to”). Arguments can be passed either inside of parentheses or alongside a method call. So in the previous example we could have said: $browser.goto(‘bing.com’)
  • 25. Build using Watir Second step: When I search the phrase "Call me Ishmael" To automate this step, we need to interact with two elements on the page: 1. The search text field 2. The search button (indicated by the magnifying glass icon).
  • 26. Build using Watir Watir has several methods in the Browser class to interact with the elements that are common to most web pages. The two we need are listed in the example given on their home page (right under the ‘goto’):
  • 27. Build using Watir To interact with the two search elements, we will use the ‘text_field’ and ‘button’ methods. These two methods each take one argument: a locator as indicated by the syntax (locator: ‘unique_identifier’). For example: $browser.text_field(id: ‘my_id’).set ‘my text’ $browser.button(id: ‘my_button’).click
  • 28. Build using Watir The locators are part of the page’s Document Object Model or DOM, which is a model of the page’s html code. But you don’t need to understand the underlying code; all you need to know is how to inspect your desired elements.
  • 29. Build using Watir If you are using Chrome browser, you can activate DevTools in three ways: Source: https://developers.google.com/web/tools/chrome-devtools/
  • 30. Build using Watir Inspecting the search box yields:
  • 31. Build using Watir The most common locator to use is ‘id’, so we will copy the value for the id locator (“sb_form_q”) and use it in our code for the text_field method.
  • 32. Build using Watir Once nice feature of Ruby method calls is the ability to “chain” methods one right after another. Ruby will execute them in the order given, from left to right. That is what you see in the text_field example: The ‘set’ method is executed right after the text_field method.
  • 33. Build using Watir You can use the ‘set’ method anytime you have defined a text field element using the ‘text_field’ method. It takes one argument: the word or phrase that you wish to place in the field. So, substituting a helpful variable name like “search_phrase” for “arg1” in the code snippet, the code for our second step looks like this:
  • 34. Build using Watir Q: Where does the value for “search_phrase” come from? A: It is passed into the code from the Gherkin step using a capture group. This cryptic bit of code "([^"]*)" grabs whatever is between the double-quotes and throws it into my given variable.
  • 35. Build using Watir Since the variable search_phrase is a string, we can use it as an argument for the set method. And so then we are able to use that same Ruby code block no matter what phrase is used in the Gherkin. Step → Step definition →
  • 36. Build using Watir Now running the test yields:
  • 37. For the button element, we’ll do it exactly like we did the text field except that instead of using the set method we will need to find a method that will click the button. The method name in this case is - surprise! - click. From the Watir site: browser.button(type: 'submit').click
  • 38. Build using Watir For most buttons, the locator they are using (type: ‘submit’) will work but it’s not specific enough so we’ll use the id to locate the field. Adding that and the dollar sign for the global variable, our step definition looks like this:
  • 39. Build using Watir Running again we get:
  • 40. Build using Watir And in the report two steps are now green:
  • 41. Build using Watir Third step: Then I will see results that contain “Moby Dick” Somehow we need to get our code to examine the result page and check to see if our phrase “Moby Dick” is found anywhere. This is where the RSpec gem comes in handy.
  • 42. Build using Watir There are many different ways to compare fields using RSpec, but the one we will use is a combination of “should” and “include”. To locate the results area, we found that we can use the ‘div’ method and an id of ‘b_content’.
  • 43. Build using Watir Running again causes all steps to pass:
  • 44. Why Page Object The Problem: If you have multiple tests or even multiple steps that use the same page elements, it’s tedious to keep having to locate them by id again and again. The Solution: Store all of the attributes for any given page in one place, assign them labels, and then in your steps simply refer to the pages and the labels.
  • 45. Convert to Page Object The Page Object gem requires some additional lines of code in the env.rb file: Hint: code it and forget it.
  • 46. Convert to Page Object For each page where we need to interact with fields or other attributes, we will need to create a class (blueprint for an object):
  • 47. Convert to Page Object When we create a class to represent a page, we are creating a situation where the attributes of the page are already defined and they are just waiting for the page object to be instantiated by creating a new instance of the class. Once that is done, the user has access to all of the attribute methods.
  • 48. Convert to Page Object Digging into the code for the two page classes:
  • 49. Convert to Page Object Q: Why use ‘include’? A: This will pull all of the standard Page Object methods into your class. http://www.rubydoc.info/github/cheezy/page-object/PageObject/Accessors
  • 50. Convert to Page Object For example:
  • 51. Convert to Page Object Here is what our steps will look like:
  • 52. Convert to Page Object Special Page Object Methods visit - grabs the URL passed to the ‘page_url’ method and executes a ‘goto’ method on it. on_page or on - instantiates the named page and allows you to access its attributes and their methods.
  • 53. Final Test Run Running again, we see the steps are still green:
  • 55. Let’s Stay In Touch Contact me: joseph.beale92@gmail.com Connect with me on LinkedIn: www.linkedin.com/in/JosephBealeQA Follow me on Twitter: @JosephBealeQA