Cheezy Dynamic Finder for Page Section

110 Views Asked by At

I'm on ruby using the page-object-gem by cheezy. Following the excellent answer here, I decided to ask this question (a page_section isn't an element I think). Anyway what is the syntax for the dynamic finder/locator for a page_section and page_sections?

1

There are 1 best solutions below

2
Justin Ko On BEST ANSWER

I do not believe this scenario was considered in the original design, so there is not great support. Feel free to request it at https://github.com/cheezy/page-object/issues .

That said, you could use the internal platform object's #page_for and #pages_for methods. The parameters are:

  • A Hash for locating the container elements.
  • The page section class.

Example:

class Container
  include PageObject
end

class MyPage
  include PageObject

  # Individual page section
  def container
    platform.page_for({tag_name: 'div'}, Container)
  end

  # Collection of page sections
  def containers
    platform.pages_for({tag_name: 'div'}, Container)
  end
end