Skip to content

Commit

Permalink
Add by.exactBinding
Browse files Browse the repository at this point in the history
Test by.binding & by.exactBinding

Fix #32
  • Loading branch information
bootstraponline committed Jun 3, 2015
1 parent 192083a commit 23f35ff
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
24 changes: 22 additions & 2 deletions lib/angular_webdriver/protractor/by.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,27 @@ def binding binding_descriptor
{ binding: binding_descriptor }
end

# Find an element by exact binding.
#
# @view
# <span>{{ person.name }}</span>
# <span ng-bind="person-email"></span>
# <span>{{person_phone|uppercase}}</span>
#
# @example
# expect(element(by.exactBinding('person.name')).present?).to eq(true);
# expect(element(by.exactBinding('person-email')).present?).to eq(true);
# expect(element(by.exactBinding('person')).present?).to eq(false);
# expect(element(by.exactBinding('person_phone')).present?).to eq(true);
# expect(element(by.exactBinding('person_phone|uppercase')).present?).to eq(true);
# expect(element(by.exactBinding('phone')).present?).to eq(false);
#
# @param binding_descriptor <String>
# @return { exactBinding: binding_descriptor }
def exactBinding binding_descriptor
{ exactBinding: binding_descriptor }
end

# Find a button by partial text.
#
# @view
Expand Down Expand Up @@ -262,6 +283,5 @@ def by
:name=>"name",
:partial_link_text=>"partial link text",
:tag_name=>"tag name",
:xpath=>"xpath",
:binding=>"binding"}
:xpath=>"xpath"}
=end
1 change: 1 addition & 0 deletions lib/angular_webdriver/protractor/protractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Protractor

NEW_FINDERS_KEYS = %i(
binding
exactBinding
partialButtonText
buttonText
model
Expand Down
5 changes: 3 additions & 2 deletions lib/angular_webdriver/protractor/webdriver_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ def protractor_find(many, how, what, parent = nil)

# args order from locators.js
case how
when 'binding'
when 'binding', 'exactBinding'
exact = how == 'exactBinding'
binding_descriptor = what
args = [binding_descriptor, false, using, root_selector]
args = [binding_descriptor, exact, using, root_selector]
protractor_js = protractor.client_side_scripts.find_bindings
when 'partialButtonText'
search_text = what
Expand Down
41 changes: 41 additions & 0 deletions spec/upstream/basic/locators_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,47 @@
visit 'form'
end

describe 'by binding' do
it 'should find an element by binding' do
greeting = element(by.binding('greeting'))

expect(greeting.text).to eq('Hiya')
end

# it 'should allow custom expectations to expect an element' do
# Not applicable to Ruby

it 'should find a binding by partial match' do
greeting = element(by.binding('greet'))

expect(greeting.text).to eq('Hiya')
end

it 'should find exact match by exactBinding' do
greeting = element(by.exactBinding('greeting'))

expect(greeting.text).to eq('Hiya')
end

it 'should not find partial match by exactBinding' do
greeting = element(by.exactBinding('greet'))

expect(greeting.present?).to eq(false)
end

it 'should find an element by binding with ng-bind attribute' do
name = element(by.binding('username'))

expect(name.text).to eq('Anon')
end

it 'should find an element by binding with ng-bind-template attribute' do
name = element(by.binding('nickname|uppercase'))

expect(name.text).to eq('(ANNIE)')
end
end # describe 'by binding'

describe 'by model' do
it 'should find an element by text input model' do
username = element(by.model('username'))
Expand Down

0 comments on commit 23f35ff

Please sign in to comment.