Skip to content

Commit

Permalink
Add by.options
Browse files Browse the repository at this point in the history
Fix #14
  • Loading branch information
bootstraponline committed Jun 1, 2015
1 parent 44f7b67 commit e23b615
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ Locator | Protractor |
**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')`
**findByModel** | `element(by.model('username'))` | `driver.find_element(:model, 'username')`
**findByOptions** | `element.all(by.options('fruit')).to_a` | `driver.find_elements(:options, 'fruit')`

## Unsupported Protractor Locators

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

## Waiting
Expand Down
2 changes: 1 addition & 1 deletion lib/angular_webdriver/protractor/protractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class Protractor

NEW_FINDERS_KEYS = %i(binding partialButtonText buttonText model).freeze # [:binding]
NEW_FINDERS_KEYS = %i(binding partialButtonText buttonText model options).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 @@ -88,6 +88,10 @@ def protractor_find(many, how, what, parent = nil)
model = what
args = [model, using, root_selector]
protractor_js = protractor.client_side_scripts.find_by_model
when 'options'
options_descriptor = what
args = [options_descriptor, using, root_selector]
protractor_js = protractor.client_side_scripts.find_by_options
end

finder = lambda { protractor.executeScript_(protractor_js, comment, *args) }
Expand Down
22 changes: 22 additions & 0 deletions lib/angular_webdriver/protractor_compatability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,31 @@ def buttonText search_text
# expect(input.value).to eq('Foo123')
#
# @param model_expression <String> ng-model expression.
# @return { model: model_expression }
def model model_expression
{ model: model_expression }
end

# Find an element by ng-options expression.
#
# @alias by.options(optionsDescriptor)
# @view
# <select ng-model="color" ng-options="c for c in colors">
# <option value="0" selected="selected">red</option>
# <option value="1">green</option>
# </select>
#
# @example
# allOptions = element.all(by.options('c for c in colors')).to_a
# expect(allOptions.length).to eq(2);
# firstOption = allOptions.first
# expect(firstOption.text).to eq('red')
#
# @param options_descriptor <String> ng-options expression.
# @return { options: options_descriptor }
def options options_descriptor
{ options: options_descriptor }
end
end
end

Expand Down
10 changes: 10 additions & 0 deletions spec/upstream/basic/locators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,14 @@
expect_equal arr.length, 0
end
end

describe 'by options' do
it 'should find elements by options' do
allOptions = element.all(by.options('fruit for fruit in fruits')).to_a
expect(allOptions.length).to eq(4)

firstOption = allOptions.first
expect(firstOption.text).to eq('apple')
end
end
end

0 comments on commit e23b615

Please sign in to comment.