2

I'm still new(ish), to POM, but I've found the syntax and general structure quite strong, so now I'm looking to advanced techniques.

I have a dynamic page, and for each of the sections I am running the following code/psuedo code

if has_SECTVAR1?
   $LOG.info("Stuff")
end

if has_SECTVAR2?
   $LOG.info("Stuff")
end

What I want to do is something like this.

ALLSECTIONARRAYS.each do |var|
  if has_var?
    $LOG.info("Stuff")
  end
end

Any thoughts?

Luke Hill
  • 460
  • 2
  • 10

1 Answers1

1

You can get an array of element names using #mapped_items. The more interesting part is checking if those exist on the page by calling #has_element?.

The abstract version of what you want to do is call a method on an object given its name as a string. To do this, use #send:

MyObject.send("method_name", *args)

Or in your case:

MyPage.send("has_element?")

Finally, to iterate over all elements:

MyPage.mapped_items.each do |item|
  if MyPage.send("has_#{item}?")
    $LOG.info("Stuff")
  end
end
nloveladyallen
  • 184
  • 1
  • 10
  • Haha, as you messaged this I already got the send portion. Will update my code that I have now. Will try the mapped_items function today, if that works then I'm all done! – Luke Hill Sep 08 '16 at 07:40