Module: Watirloo::Page

Defined in:
lib/watirloo/page.rb

Overview

Semantic Page Objects Container include it in your ClientClass that manages Test. Your client class must provide an instance of browser. If you don’t want an explicit browser the Watirloo.browser will be used. example

class UsageScenarioOfSomeFeature
  include Watirloo::Page
end

now the client GoogleSearch can access browser and elements defined instead of including it directly in classes that you instantiate to keep track of state you can build modules of pages that you can later include into your client

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object

metahook by which ClassMethods become singleton methods of an including module Perhaps the proper way is to do this class SomeClass

include PageHelper
extend PageHelper::ClassMethods

end but we are just learning this metaprogramming



101
102
103
# File 'lib/watirloo/page.rb', line 101

def self.included(klass)
  klass.extend(ClassMethods)
end

Instance Method Details

#browserObject

provide browser for a client. If now browser is assigned to a client Use the default Watirloo.browser if no browser set explicitly



17
18
19
# File 'lib/watirloo/page.rb', line 17

def browser
  @browser ||= ::Watirloo.browser
end

#browser=(browser) ⇒ Object

set browser instance for a client to use – the method is a bit better than browser= because setting browser in mehtods would probably requires a call to:

self.browser= ie

else

browser = ie

may be an assignemnt to local variable



29
30
31
# File 'lib/watirloo/page.rb', line 29

def browser=(browser)
  @browser = browser
end

#pageObject

browser document container that delimits the scope of elements. all faces use page as a base. In a frameless DOM the browser is page, the document container. however if page with frames you can setup a doc destination to be a frame as the base container for face accessors. in most circumstances page is a passthru to browser example: if you have a frameset and you want to talk to a frame(:name, ‘content’) you can redefine set the page self.page = browser.frame(:name, ‘content’) see set_page



42
43
44
# File 'lib/watirloo/page.rb', line 42

def page
  @page ||= browser
end

#page=(watir_element) ⇒ Object

set the page base element as the receiver of all facename methods one would have to make this type of call:

self.page = watir_element
else this:
page = watir_element
may be treated as assignemnt to local variable


53
54
55
# File 'lib/watirloo/page.rb', line 53

def page=(watir_element)
  @page = watir_element
end

#scrape(facenames) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/watirloo/page.rb', line 124

def scrape(facenames)
  data = {}
  facenames.each do |facename|
    watir_control = self.send facename
    method_name = case watir_control.class.to_s.split("::").last
    when "SelectList", "CheckboxGroup", "RadioGroup" then :selected
    else  
      :value
    end
    data.update facename => watir_control.send(method_name)
  end
  data
end

#spray(hash) ⇒ Object Also known as: set

enter values on controls idenfied by keys on the page. data map is a hash, key represents the page objects that can be filled or set with values, value represents its value to be set, either text, array or boolean exmaple:

spray :first => "Johnny", :last => 'Begood'

# Given the faces defined
face(:first) {doc.text_field(:name, 'lst_nm')}
face(:last) {doc.text_field(:name, 'fst_nm')}


114
115
116
117
118
# File 'lib/watirloo/page.rb', line 114

def spray(hash)
  hash.each_pair do |facename, value|
    self.send(facename).set value #make every control element in watir respond to set
  end
end