1

I have defined a sections element as containing a list of individual elements to model a data table. Each Section of the Sections collection corresponds to a row of the table and each element of the Sections definition corresponds to a column of the row.

I want to search the Sections collection for a Section which corresponds to the row with a given id and then click on an element of that row.

Unfortunately I cant find a way of searching the array of Section objects returned by PageObjectClass.<sections_name>.

If instead I define the set of rows as elements then PageObjectClass.<elements_name> returns a set of Capybara elements that I can do a Capybara find on but then I can't use the SitePrism section.element syntax.

Using the elements.find syntax seems to have a code smell because thus far the CSS for accessing elements has been abstracted away in the PageObject class definition - now I have to refer to the CSS for a specific element in the test code in order to click on it.

What am I missing here? How come there are so few examples of the use of data tables in SitePrism online discussion and why haven't more people hit this problem?

The only reference that I did hit upon is https://github.com/natritmeyer/site_prism/issues/91

Did anything ever come of this suggestion?

Craig Miles
  • 447
  • 4
  • 18

2 Answers2

0

To answer my own question...

The only way I came up with was to add a method to the page object class to iterate through the sections to find an element that matched the given id.

At least this encapsulated the CSS for the element in the page object.

Seems like there should be a better way, or at least this way should be defined as part of the SitePrism gem?

Craig Miles
  • 447
  • 4
  • 18
0

You would use a capybara query selector with text: 'value' on your original call.

So if you had 5 sections with id #foo you could define section :my_foo, #foo, text: 'fifth'

This would only return one section, and voila.

Alternatively you could iterate through them using #detect which stops once it has found the first positive match. So you would do my_sections.detect { |section| section.text == 'First match' }

Luke Hill
  • 460
  • 2
  • 10