diff --git a/docs/overview.md b/docs/overview.md index a148857..3a788b1 100644 --- a/docs/overview.md +++ b/docs/overview.md @@ -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 @@ -76,7 +77,6 @@ These locators are on the roadmap for implementation. - **findRepeaterColumn** - **findByModel** - **findByOptions** -- **findByButtonText** - **findByCssContainingText** ## Waiting diff --git a/lib/angular_webdriver/protractor/protractor.rb b/lib/angular_webdriver/protractor/protractor.rb index 417dc30..1a6c6b9 100644 --- a/lib/angular_webdriver/protractor/protractor.rb +++ b/lib/angular_webdriver/protractor/protractor.rb @@ -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. # diff --git a/lib/angular_webdriver/protractor/webdriver_patch.rb b/lib/angular_webdriver/protractor/webdriver_patch.rb index bc3bbb4..1151a98 100644 --- a/lib/angular_webdriver/protractor/webdriver_patch.rb +++ b/lib/angular_webdriver/protractor/webdriver_patch.rb @@ -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) } diff --git a/lib/angular_webdriver/protractor_compatability.rb b/lib/angular_webdriver/protractor_compatability.rb index 04fa066..c77c038 100644 --- a/lib/angular_webdriver/protractor_compatability.rb +++ b/lib/angular_webdriver/protractor_compatability.rb @@ -118,11 +118,25 @@ def binding binding_descriptor # @example # element(by.partialButtonText('Save')); # - # @param {string} search_text + # @param search_text # @return { partialButtonText: search_text } def partialButtonText search_text { partialButtonText: search_text } end + + # Find a button by text. + # + # @view + # + # + # @example + # element(by.buttonText('Save')); + # + # @param search_text + # @return {buttonText: search_text } + def buttonText search_text + { buttonText: search_text } + end end end diff --git a/spec/helpers/utils.rb b/spec/helpers/utils.rb index 4fefa2d..b8cddb8 100644 --- a/spec/helpers/utils.rb +++ b/spec/helpers/utils.rb @@ -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) diff --git a/spec/upstream/basic/locators_spec.rb b/spec/upstream/basic/locators_spec.rb index 488a2fa..b59e4bb 100644 --- a/spec/upstream/basic/locators_spec.rb +++ b/spec/upstream/basic/locators_spec.rb @@ -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