-
Notifications
You must be signed in to change notification settings - Fork 0
1 Quick Start
Justin Watts edited this page May 26, 2017
·
12 revisions
While meta-programming underscores Ferris design, we use it primarily to link Sites to Pages and Regions, rather than to add DSL. Below is a real world example which describes a Wikipedia as if it were under test. It invokes a Ferris::Site, a Ferris::Page, and a Ferris::Region.
class Wikipedia < Ferris::Site
page( :home_page, HomePage)
page( :apple_page, ApplePage)
region(:header, Header) { browser.div(id: 'mw-head') }
def ensure_loaded
header.wait_until(&:present?)
end
end
class ApplePage < Ferris::Page
partial_url { '/wiki/Apple' }
title { 'Apple - Wikipedia' }
element(:article_heading) { browser.h1(id: 'firstHeading') }
def ensure_loaded
article_heading.wait_until(&:present?)
end
end
class Header < Ferris::Region
element(:search_term) { root.text_field(id: 'searchInput') }
element(:submit_btn) { root.button(name: 'go') }
def search(input)
search_term.do! input
submit_btn.click
end
end
Access them in your code like this (RSpec example):
spec_helper.rb
c.before(:each) do
Ferris.browser = Watir::Browser.new :chrome
end
c.after(:each) do
Ferris.browser.close
end
wikipedia_spec.rb
describe 'Wikipedia' do
let(:wikipedia) { Wikipedia.new('https://en.wikipedia.org') }
it 'can search' do
wikipedia.visit
wikipedia.header.search('Apple')
expect(wikipedia.browser.title).to eql wikipedia.apple_page.title
end
it 'can check a region is present' do
wikipedia.visit
expect(wikipedia.header).to be_present
end
end