class Gamera::Page
This is a base class which implements common methods for page object classes.
You can use this to create a Ruby class which wraps a web page, providing an API for automating elements or processes on the page
@example Page
Object
class for registration page
class NewRegistrationPage < Gamera::Page def initialize @url = 'http://example.com/registration/new' @url_matcher = /registration\/new/ end # page elements def name_field find_field('Name') end def email_field find_field('Email Address') end def password_field find_field('Password') end def password_confirmation_field find_field('Confirm Password') end def instructions def instructions find('#instructions') end # page processes def save find_button('Save').click end def register_user(name:, email:, password:) name_field.set(name) email_field.set(email) password_field.set(password) password_confirmation_field.set(password) save end end # This could be used in a test or automation script, e.g. ... reg_page = NewRegistrationPage.new reg_page.visit reg_page.register_user(name: 'Laurence Peltier', email: 'lpeltier@example.com', password: 'super_secret') ...
@example Page
class for general Rails page with flash messages
class RailsPage < Gamera::Page def flash_error_css 'div.flash.error' end def flash_notice_css 'div.flash.notice' end def flash_error find(flash_error_css) end def flash_notice find(flash_notice_css) end def has_flash_message?(message) has_css?(flash_notice_css, text: message) end def has_flash_error?(error) has_css?(flash_error_css, text: error) end def has_no_flash_error? has_no_css?(flash_error_css) end def has_no_flash_message? has_no_css?(flash_notice_css) end def has_submission_problems? has_flash_error?('There were problems with your submission') end def fail_if_submission_problems fail(SubmissionProblemsError, flash_error.text) if has_submission_problems? end end
Attributes
url[R]
url_matcher[R]
Public Class Methods
new(url, url_matcher = nil)
click to toggle source
# File lib/gamera/page.rb, line 143 def initialize(url, url_matcher = nil) @url = url @url_matcher = url_matcher || /#{url}/ end