Skip to content

Commit

Permalink
enable #text for button elements powered by selenium.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Andersen committed Apr 24, 2015
1 parent bc24445 commit 7a3fe24
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 6 deletions.
16 changes: 13 additions & 3 deletions features/button.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Feature: Button
Scenario: Clicking a button (type=submit)
When I click the button
Then I should be on the success page

Scenario: Clicking a button (type=image)
When I click the button with type image
Then I should be on the success page

Scenario: Clicking an image button by src
When I click the image button using src
Then I should be on the success page
Expand Down Expand Up @@ -62,6 +62,16 @@ Feature: Button
| search_by |
| text |

@dane
Scenario Outline: Getting the text from a button
When I get the text for a button that is a "<tag>"
Then the text should be "This button is a <tag>"

Scenarios:
| tag |
| button |
| input |

Scenario Outline: Locating button using multiple parameters
When I search for the button by "<param1>" and "<param2>"
Then I should be able to click the button
Expand All @@ -70,7 +80,7 @@ Feature: Button
| param1 | param2 |
| class | index |
| name | index |

Scenario Outline: Locating real button using multiple parameters
When I search for the button by "<param1>" and "<param2>"
Then I should be able to click the real button
Expand Down
2 changes: 2 additions & 0 deletions features/html/static_elements.html
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@ <h6 id="h6_id" class="h6_class" name="h6_name">h6's are cool</h6>
<img src="images/img_pulpit.jpg" alt="The Pulpit Rock" width="304" height="228">
</figure>
This text have <b id="b_id" class="b_class" name="b_name">some text in bold</b>
<button id="button_button">This button is a button</button>
<input id="input_button" type="button" value="This button is a input" />
</body>
</html>

Expand Down
5 changes: 5 additions & 0 deletions features/step_definitions/button_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,8 @@
Then /^I should see that the button exists$/ do
@page.button_id?.should == true
end


When(/^I get the text for a button that is a "([^"]*)"$/) do |tagname|
@text = @page.button_element(:id => "#{tagname}_button").text
end
6 changes: 3 additions & 3 deletions lib/page-object/platforms/selenium_webdriver/button.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ module Platforms
module SeleniumWebDriver
module Button
#
# Override PageObject::PLatforms::SeleniumElement#text because
# #text does not reliably return a value in Selenium
# Override PageObject::PLatforms::SeleniumElement#text
# to get #text from buttons and #attribute('value') from inputs
#
def text
raise "text is not available on button element in Selenium"
element.tag_name == 'button' ? element.text : element.attribute('value')
end
end
end
Expand Down
14 changes: 14 additions & 0 deletions spec/page-object/elements/button_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
expect(lambda { button.text }).to raise_error
end

it "should return text for a button tag button" do
allow(button_element).to receive(:tag_name).and_return('button')
allow(button_element).to receive(:text).and_return('button?')
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
expect(button.text).to eq 'button?'
end

it "should return text for an input tag button" do
allow(button_element).to receive(:tag_name).and_return('input')
allow(button_element).to receive(:attribute).with('value').and_return('button!')
button = PageObject::Elements::Button.new(button_element, :platform => :selenium_webdriver)
expect(button.text).to eq 'button!'
end
end
end

Expand Down

0 comments on commit 7a3fe24

Please sign in to comment.