1

I have this two page-object elements:

images(:new_number, src: '/static/images/sec_core/plus.png')
text_fields(:users, class: 'custom-combobox-input ui-widget ui-widget-content ui-state-default ui-corner-left ui-autocomplete-input')

And I am able to use it to click in the last image of a list of images in the HTML if I use the following code:

users_elements[user_index].parent.parent.parent[1].image_elements(:src => '/static/images/sec_core/plus.png').last.parent.when_present.click

Isn't it possible to reuse the page-object element somehow, as a watir "method" in order to avoid repeating code, something that's similar to this:

users_elements[user_index].parent.parent.parent[1].new_number_elements.last.parent.when_present.click
skimisha
  • 143
  • 1
  • 10
  • Hard to be more helpful without having a play with the code, but you might want to look into using nested page objects - http://stackoverflow.com/questions/23663564/accessing-nested-divs-using-page-object-model. – alannichols Mar 16 '16 at 12:58
  • are you rolling your own page objects, or using one of a few existing gems for it, or what? knowing that helps to answer this. – Chuck van der Linden Mar 17 '16 at 17:21

1 Answers1

1

The answer here depends a lot on how you implement page objects. If you are using your own code, or a library like Cheezy's Page-Object gem, or the Test-Factory gem Abe Heward and I cooked up when we were at rSmart (Abe did all the heavy lifting)

I've not used Cheezy's gem enough to know if you can do it there, but I've defined methods similar to that when using page factory, it was pretty easy to do (although the docs don't give a good example of it, I should fix that)

Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43