Hey folks!

Got a head-scratcher, here.

My use case: I want to create a smoke-test that verifies particular 
elements are present on a page.

So, I define the page elements I want, using Alister Scott's 
Code<https://github.com/alisterscott/wmf-custom-page-object/blob/master/lib/pages/generic_base_page.rb>
:

  *def* self.element element_name
    raise "#{element_name} is being defined twice in #{self}!" if self
.instance_methods.include?(element_name.to_sym)
    *define_method* element_name.to_s *do*
      yield self   # This is the line that throws the error (see below)
    *end*
  *end*
*
*
I define elements in my page class...

*class Page*
  element(:important_element1) { |b| b.link(:id=>"x") }
  element(:important_element2) { |b| b.button(:id=>"y") }
*end*
*
*
Then I have an array containing the names (as symbols) of the important 
elements I want to test...

array = [:important_element1, :important_element2]

Here's the problem: I thought the following would work to iterate through 
the list:

*def* elements_exist?
  array.each { |item| self.send(item).exists? }
*end*
*
*
I invoke the *elements_exist? *method like this:

on Page do |p|
  p.elements_exist?
end
*
*
But the error I'm getting is:

<in the line I noted in red above> in `block in element': no block given 
(yield) (LocalJumpError)

What I don't understand is why it would call the *self.element* method 
again at all. I thought it only does that once at the start, when the class 
is declared.  I don't want to pass it a block here because I already did 
that when I defined the element in the first place.

Is my approach just completely off-base, here?

Abe

-- 
Before posting, please read http://watir.com/support. In short: search before 
you ask, be nice.

watir-general@googlegroups.com
http://groups.google.com/group/watir-general
watir-general+unsubscr...@googlegroups.com

Reply via email to