cheezy / page-object

Gem to implement PageObject pattern in watir-webdriver and selenium-webdriver
MIT License
652 stars 220 forks source link

Easy/Safe way to add custom widgets in subclasses? #410

Open imjonsnooow opened 7 years ago

imjonsnooow commented 7 years ago

Hi team,

I've found a use-case where the custom widgets are less flexible than is ideal:

require 'page-object'

class One
  include PageObject
end

class GxtTable < PageObject::Elements::Table

  protected
  def child_xpath
    ".//descendant::tr"
  end
end

PageObject.register_widget :gxt_table, GxtTable, :div

class Two < One
  gxt_table(:a_table, :id => "top_div_id")
end

If we try to run this code, we will get a NoMethodError: undefined method 'gxt_table' for Two:Class. It seems that when you register_widget, one of the page-object modules are enhanced to have the appropriate methods, but those methods do not end up on classes that have already included PageObject.

Re-including PageObject does fix the issue, but I'm unclear on whether or not doing this would cause any unintended consequences. Mostly looking for advice, here.

Thank you!

djangofan commented 7 years ago

I am also very interested in whatever solution this is for this. I would also like to have a page object contain various widgets (smaller page objects) representing different parts of a page. It's not clear how to do this from reading the docs, unless I overlooked it. @cheezy

cheezy commented 7 years ago

I'm going to make a release today that will not include a fix for this. I will make it a focus on the next release which should be in a week or so.

cheezy commented 6 years ago

@djangofan you should look at page_sections. They are exactly what you are looking for. I included examples of this in the last release of my book.

cheezy commented 6 years ago

@imjonsnooow I've looked over this briefly and really do not know why it is not working. If this is important, I will take the time to try to resolve it. As you said above, simply including the PageObject gem in the subclass resolves the issue. Is this a valid resolution for you?

imjonsnooow commented 6 years ago

@cheezy - this isn't a huge priority for me right now, so I'm okay with the workaround identified (as it has not caused any adverse effects that I have noticed) :)

jkotests commented 5 years ago

A possible solution may be https://stackoverflow.com/a/14631604/1200545