Module: Watirloo::Page::ClassMethods

Defined in:
lib/watirloo/page.rb

Instance Method Summary collapse

Instance Method Details

#face(name, *args, &definition) ⇒ Object

“anything which is the forward or world facing part of a system which has internal structure is considered its ‘face’, like the facade of a building” ~ en.wikipedia.org/wiki/Face

Declares Semantic Interface to the DOM elements on the Page (facade) binds a symbol to a block of code that accesses the DOM. When the user speaks of filling in the last name the are usually entering data in a text_field we can create a semantic accessor interface like this:

face(:last_name) { text_field(:name, 'last_nm'}

what matters to the user is on the left (:last_name) and what matters to the programmer is on the right The face method provides an adapter and insolates the tests form the changes in GUI. The patterns is: face(:friendlyname) { watir_element(how, whatcode } where watir_element is actuall way of accessing the element on the page. The page is implicit. Each interface or face is an object of interest that we want to access by its interface name

example:

  class GoogleSearch
    include Watirloo::Page
    face(:query)   { text_field(:name, 'q') }
    face(:search)  { button(:name, 'btnG') }
  end

  at run time calling
  query.set "Ruby"
  is equivalent to
  page.text_field(:name, 'q').set "Ruby"
  where page is the root of HTML document


86
87
88
89
90
# File 'lib/watirloo/page.rb', line 86

def face(name, *args, &definition)
  define_method(name) do |*args|
    page.instance_exec(*args, &definition)
  end
end