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

Indexed property child field is not being added correctly

Open Kysis101 opened this issue 9 years ago • 3 comments

I have defined an index property in my page-object. All of these fields are working except the :name field. I renamed it to :physician_name which worked but the method isn't created when it is :name. indexed_property(:physician_panel,[ [:p, :physician_tab, text: '%s Physician'], [:td, :name, id: 'authSubmitView-physicianPanel-%sPhysicianTab-NameField'], [:td, :npi, id: 'authSubmitView-physicianPanel-%sPhysicianTab-NPIField'], [:td, :specialty, id: 'authSubmitView-physicianPanel-%sPhysicianTab-SpecialtyField'], [:td, :address, id: 'authSubmitView-physicianPanel-%sPhysicianTab-AddressField'], [:td, :tin, id: 'authSubmitView-physicianPanel-%sPhysicianTab-TINField'], [:td, :group_name, id: 'authSubmitView-physicianPanel-%sPhysicianTab-GroupNameField'], [:td, :city_state_zip, id: 'authSubmitView-physicianPanel-%sPhysicianTab-CityStateZipField'], [:text_field, :contact_name, id: 'authSubmitView-physicianPanel-%sPhysicianTab-ContactNameField'], [:text_field, :email, id: 'authSubmitView-physicianPanel-%sPhysicianTab-EmailField'], [:text_field, :phone_number, id: 'authSubmitView-physicianPanel-%sPhysicianTab-PhoneField'], [:text_field, :last_contact, id: 'authSubmitView-physicianPanel-%sPhysicianTab-LastContactField'], [:text_field, :fax_number, id: 'authSubmitView-physicianPanel-%sPhysicianTab-FaxField'] ])

Kysis101 avatar Jul 02 '15 19:07 Kysis101

I've run into this problem as well.

Essentially, page-object does a check to make sure you are not overwriting an instance method on class Class before defining the property method, since Class already has an instance method :name, it doesn't define the property.

Unfortunately this fails silently rather than warning the user. I'm not sure it's a good idea to allow a property called :name to be declared, but there should probably be a warning of some sort rather than silently doing nothing.

AlanLGuy avatar Jul 03 '15 19:07 AlanLGuy

That was my first instinct as well but if this is the case then calling .name on the object in question shouldn't throw a No Method error right? name is also not present when I print the methods for the object in question.

Kysis101 avatar Jul 07 '15 14:07 Kysis101

Example test case is below.

HTML:

<html>
  <body>
    <table>
      <tr>
        <td id="authSubmitView-physicianPanel-1PhysicianTab-NameField">a</td>
        <td id="authSubmitView-physicianPanel-1PhysicianTab-NPIField">b</td>
      </tr>
      <tr>
        <td id="authSubmitView-physicianPanel-2PhysicianTab-NameField">c</td>
        <td id="authSubmitView-physicianPanel-2PhysicianTab-NPIField">d</td>
      </tr>
    </table>
  </body>
</html>

Page-object code:

class MyPage
  include PageObject

  indexed_property(:physician_panel,[
    [:td, :name, id: 'authSubmitView-physicianPanel-%sPhysicianTab-NameField'],
    [:td, :npi, id: 'authSubmitView-physicianPanel-%sPhysicianTab-NPIField']
  ])
end

page = MyPage.new(browser)
p page.physician_panel[1].npi
#=> "b"
p page.physician_panel[1].name
#=> C:/Ruby24/lib/ruby/gems/2.4.0/gems/page-object-2.2.4/lib/page-object/elements/element.rb:180:in `name': undefined method `attribute' for #<Watir::Browser:0x3eb4dac6 closed=true> (NoMethodError)
#=> 	from C:/Ruby24/lib/ruby/gems/2.4.0/gems/page-object-2.2.4/lib/page-object.rb:49:in `method_missing'
#=> 	from pageobject.rb:36:in `<main>'

jkotests avatar Nov 21 '18 02:11 jkotests