page-object icon indicating copy to clipboard operation
page-object copied to clipboard

Easy/Safe way to add custom widgets in subclasses?

Open imjonsnooow opened this issue 8 years ago • 6 comments
trafficstars

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!

imjonsnooow avatar Feb 14 '17 12:02 imjonsnooow

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

djangofan avatar Feb 23 '17 21:02 djangofan

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 avatar Mar 06 '17 12:03 cheezy

@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 avatar Sep 22 '17 19:09 cheezy

@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?

cheezy avatar Sep 22 '17 20:09 cheezy

@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) :)

imjonsnooow avatar Oct 07 '17 19:10 imjonsnooow

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

jkotests avatar Nov 21 '18 14:11 jkotests