Skip to content

Commit 545909d

Browse files
authored
Merge pull request #186 from appfolio/hexDocumentCustomPageCollections
klh - Explain custom collections in more detail
2 parents cc7d9f7 + 77733a7 commit 545909d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

README.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ be used in automated acceptance test suites.
3636
- [Custom Elements](#custom-elements)
3737
- [Forms](#forms)
3838
- [Collections](#collections)
39+
- [Custom Collections](#custom-collections)
3940
- [Staling](#staling)
4041
- [Load Ensuring](#load-ensuring-1)
4142
- [Checking presence](#checking-presence)
@@ -939,7 +940,13 @@ class AuthorsNewPage < AePageObjects::Document
939940
end
940941
```
941942

942-
Additionally, if you can use `:is` to specify the collection type:
943+
944+
#### Custom Collections
945+
946+
Sometimes, we'll want a collection that supports more methods
947+
than what the [default implementation](./lib/ae_page_objects/elements/collection.rb)
948+
supports. An easy way to handle this use case is to create a new
949+
class that inherits from `AePageObjects::Collection`:
943950

944951
```ruby
945952
class Address < AePageObjects::Element
@@ -952,15 +959,21 @@ class AddressList < AePageObjects::Collection
952959
last.click('.delete-button')
953960
end
954961
end
962+
```
963+
964+
Then, in the page object, use `:is` to specify the collection type:
955965

966+
```ruby
956967
class AuthorsNewPage < AePageObjects::Document
957968
form_for :author do
958969
collection :addresses, is: AddressList, contains: Address
959970
end
960971
end
961972
```
962973

963-
`collection` supports every combination of `:is`, `:contains`, and the block. See the source for more examples.
974+
This custom collection is also declared to contain items of the custom
975+
`Address` element subclass. `collection` supports every combination of
976+
`:is`, `:contains`, and the block. See the source for more examples.
964977

965978
### Staling
966979

0 commit comments

Comments
 (0)