Skip to content

Commit

Permalink
Merge pull request cheezy#231 from daneandersen/master
Browse files Browse the repository at this point in the history
bug with indexed properties allowing access of elements on other indexed properties.
  • Loading branch information
cheezy committed Aug 11, 2014
2 parents 2a3f9a0 + 1359d19 commit 9fa3551
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 22 deletions.
14 changes: 14 additions & 0 deletions features/html/indexed_property.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,34 @@
<td><input type="checkbox" id="table[123].check" value="1"/></td>
<td><textarea id="table[123].area" rows="2" cols="20"></textarea></td>
<td><input id="table[123].button" type="submit" value="Click 123"/></td>
<td><div id="table[123].content">123!</div></td>
</tr>
<tr>
<td><input type="text" id="table[foo].text" name="tableName[foo].text" size="20"/></td>
<td><input type="radio" id="table[foo].radio" value="foo"/></td>
<td><input type="checkbox" id="table[foo].check" value="2"/></td>
<td><textarea id="table[foo].area" rows="2" cols="20"></textarea></td>
<td><input id="table[foo].button" type="submit" value="Click foo"/></td>
<td><div id="table[foo].content">foo!</div></td>
</tr>
<tr>
<td><input type="text" id="table[12test].text" name="tableName[12test].text" size="20"/></td>
<td><input type="radio" id="table[12test].radio" value="12test"/></td>
<td><input type="checkbox" id="table[12test].check" value="3"/></td>
<td><textarea id="table[12test].area" rows="2" cols="20"></textarea></td>
<td><input id="table[12test].button" type="submit" value="Click 12test"/></td>
<td><div id="table[12test].content">12test!</div></td>
</tr>
</table>

<table id="other_table_id" name align="table_name" class="table_class" border="1">
<tr>
<td><input type="text" id="other_table[foo].text" name="otherTableName[foo].text" size="20"/></td>
<td><div id="other_table[foo].content">foo2!</div></td>
</tr>
<tr>
<td><input type="text" id="other_table[bar].text" name="otherTableName[bar].text" size="20"/></td>
<td><div id="other_table[bar].content">bar!</div></td>
</tr>
</table>

Expand Down
15 changes: 15 additions & 0 deletions features/indexed_property.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,18 @@ Feature: Indexed Property
| foo |
| 123 |
| 12test |

Scenario: Element on first indexed property but not second
When I search for an element that is on an indexed property
And I search for the element on another indexed property it is not on
Then I should see that the element doesn't exist

Scenario: Index on first indexed property but not on second
When I search for an element by an index on an indexed property
And I search using the index which is not on another indexed property
Then I should see that the element doesn't exist for that index

Scenario: Index on first indexed property and different on second
When I search for an element with text by an index on an indexed property
And I search using an index which is on another indexed property
Then I should see the content of the element on the second indexed property
48 changes: 47 additions & 1 deletion features/step_definitions/indexed_property_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,16 @@ class IndexedPropertyPage
[:radio_button, :radio, {:id => 'table[%s].radio'}],
[:checkbox, :check, {:id => 'table[%s].check'}],
[:text_area, :area, {:id => 'table[%s].area'}],
[:button, :button, {:id => 'table[%s].button'}]]
[:button, :button, {:id => 'table[%s].button'}],
[:div, :content, {:id => 'table[%s].content'}]]

indexed_property :nottable, [[:text_field, :text_nottable, {:id => 'nottable[%s].text'}]]

indexed_property :other_table, [
[:text_field, :text_table, {:id => 'other_table[%s].text'}],
[:div, :content, {:id => 'other_table[%s].content'}]
]

end

def page
Expand Down Expand Up @@ -81,3 +87,43 @@ def page
page.nottable[@index].text_nottable.should == val
end


When(/^I search for an element not on my indexed property but on another$/) do
@index = 'foo'
end

Then(/^I should see that the element doesn't exist$/) do
expect { page.other_table[@index].radio_element.value }.to raise_error(NoMethodError)
end

When(/^I search for an element that is on an indexed property$/) do
page.table['foo'].radio_element
end

And(/^I search for the element on another indexed property it is not on$/) do
@index = 'foo'
end

When(/^I search using the index which is not on another indexed property$/) do
@index = '123'
end

Then(/^I should see that the element doesn't exist for that index/) do
expect { page.other_table[@index].text_table_element.text }.to raise_error /unable to locate element|Selenium::WebDriver::Error::NoSuchElementError/
end

When(/^I search for an element by an index on an indexed property$/) do
page.table['123'].text_table_element.html
end

And(/^I search using an index which is on another indexed property$/) do
@index = 'bar'
end

Then(/^I should see the content of the element on the second indexed property$/) do
expect(page.other_table['bar'].content).to eq 'bar!'
end

When(/^I search for an element with text by an index on an indexed property$/) do
expect(page.table['123'].content).to eq '123!'
end
41 changes: 20 additions & 21 deletions lib/page-object/indexed_properties.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
module PageObject
module IndexedProperties
class RowOfElements
include PageObject
include LoadsPlatform
extend Accessors

def initialize (browser, index, identifier_list)
initialize_browser(browser)

identifier_list.each do |identifier|
type = identifier[0]
name = identifier[1]
how_and_what = identifier[2].clone # Cannot modify the original...
how_and_what.each do |key, value|
how_and_what[key] = value % index
end
self.class.send type, name, how_and_what unless self.class.instance_methods.include? name
end
end
end

class TableOfElements
include PageObject
include LoadsPlatform

def initialize (browser, identifier_list)
initialize_browser(browser)
@identifier_list = identifier_list
@indexed_property_class = Class.new {
include PageObject
include LoadsPlatform
extend Accessors

def initialize (browser, index, identifier_list)
initialize_browser(browser)

identifier_list.each do |identifier|
type = identifier[0]
name = identifier[1]
how_and_what = identifier[2].clone # Cannot modify the original...
how_and_what.each do |key, value|
how_and_what[key] = value % index
end
self.class.send type, name, how_and_what unless self.class.instance_methods.include? name
end
end
}
end

def [] (index)
RowOfElements.new(@browser, index, @identifier_list)
@indexed_property_class.new(@browser,index,@identifier_list)
end
end
end
Expand Down

0 comments on commit 9fa3551

Please sign in to comment.