gregloscombe
gregloscombe

Reputation: 99

Page-object with known quantity of generated fields

I'm using Ruby, Watir-webdriver and the Page-object gem at work for automated testing.

Just wondering how people would approach a page that was dynamic in nature in terms of quantity of text fields. The page I'm currently working has 'key' / 'value' pair list, with the ability to add as many as you want.

I know I could just access say the 5th one with something like

text_field(:key5, id: "key", index: 4)
text_field(:value5, id: "value", index: 4)

But it feels a bit messy populating a support page with a load of items that might not exist.

Is there a better approach to this that I'm missing?

Upvotes: 2

Views: 175

Answers (1)

Cheezy
Cheezy

Reputation: 789

The simplest idea that comes to mind is to do something like this:

text_fields(:key, :id => 'key')
text_fields(:value, :id => 'value')

This will generate the methods key_elements and value_elements which will return an array of the text fields. Perhaps this will work for you.

Upvotes: 1

Related Questions