Skip to content

Commit

Permalink
Add by.buttonText
Browse files Browse the repository at this point in the history
Fix #15 #16
  • Loading branch information
bootstraponline committed Jun 1, 2015
1 parent 8ff4393 commit 67641fe
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 5 deletions.
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Locator | Protractor |
--- | --- | ---
**binding** | `element(by.binding('slowHttpStatus')).locate` | `driver.find_element(:binding, 'slowHttpStatus')`
**findByPartialButtonText** | `element.all(by.partialButtonText('text')).to_a` | `driver.find_elements(:findByPartialButtonText, 'slowHttpStatus')`
**findByButtonText** | `element.all(by.buttonText('Exact text')).to_a` | `driver.find_elements(:buttonText, 'Exact text')`

## Unsupported Protractor Locators

Expand All @@ -76,7 +77,6 @@ These locators are on the roadmap for implementation.
- **findRepeaterColumn**
- **findByModel**
- **findByOptions**
- **findByButtonText**
- **findByCssContainingText**

## Waiting
Expand Down
4 changes: 2 additions & 2 deletions lib/angular_webdriver/protractor/protractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

class Protractor

NEW_FINDERS_HASH = { binding: 'binding', partialButtonText: 'partialButtonText' }.freeze
NEW_FINDERS_KEYS = NEW_FINDERS_HASH.keys.freeze
NEW_FINDERS_KEYS = %i(binding partialButtonText buttonText).freeze # [:binding]
NEW_FINDERS_HASH = NEW_FINDERS_KEYS.map { |e| [e, e.to_s] }.to_h.freeze # {binding: 'binding'}

# Return true if given finder is a protractor finder.
#
Expand Down
4 changes: 4 additions & 0 deletions lib/angular_webdriver/protractor/webdriver_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ def protractor_find(many, how, what, parent = nil)
search_text = what
args = [search_text, using, root_selector]
protractor_js = protractor.client_side_scripts.find_by_partial_button_text
when 'buttonText'
search_text = what
args = [search_text, using, root_selector]
protractor_js = protractor.client_side_scripts.find_by_button_text
end

finder = lambda { protractor.executeScript_(protractor_js, comment, *args) }
Expand Down
16 changes: 15 additions & 1 deletion lib/angular_webdriver/protractor_compatability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,25 @@ def binding binding_descriptor
# @example
# element(by.partialButtonText('Save'));
#
# @param {string} search_text
# @param search_text <String>
# @return { partialButtonText: search_text }
def partialButtonText search_text
{ partialButtonText: search_text }
end

# Find a button by text.
#
# @view
# <button>Save</button>
#
# @example
# element(by.buttonText('Save'));
#
# @param search_text <String>
# @return {buttonText: search_text }
def buttonText search_text
{ buttonText: search_text }
end
end
end

Expand Down
3 changes: 2 additions & 1 deletion spec/helpers/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ def driver

def no_wait &block
driver.set_max_wait 0
block.call
result = block.call
driver.set_max_wait max_wait_seconds_default
result
end

# Sets the driver's set_max_wait (client side client wait)
Expand Down
16 changes: 16 additions & 0 deletions spec/upstream/basic/locators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,20 @@
expect(arr[3].id).to eq('inputbutton')
end
end

describe 'by button text' do
it 'should find two button containing "Exact text"' do
arr = element.all(by.buttonText('Exact text')).to_a
expect_equal arr.length, 2
expect_equal arr[0].id, 'exacttext'
expect_equal arr[1].id, 'submitbutton'

end

it 'should not find any buttons containing "text"' do
# we expect this not to find anything so temp set client max wait to 0
arr = no_wait { element.all(by.buttonText('text')).to_a }
expect_equal arr.length, 0
end
end
end

0 comments on commit 67641fe

Please sign in to comment.