Class: AngularWebdriver::By

Inherits:
Object
  • Object
show all
Defined in:
lib/angular_webdriver/protractor/by.rb

Class Method Summary collapse

Class Method Details

.binding(binding_descriptor) ⇒ Object

Find an element by binding. Does a partial match, so any elements bound to

variables containing the input string will be returned.

Note: For AngularJS version 1.2, the interpolation brackets, usually {{}},
are allowed in the binding description string. For Angular version 1.3, they
are not allowed, and no elements will be found if they are used.

@view
<span>{{person.name}}</span>
<span ng-bind="person.email"></span>

@example
span1 = element(by.binding('person.name'))
expect(span1.text).to eq('Foo')

span2 = element(by.binding('person.email'))
expect(span2.text.to eq('[email protected]')

# You can also use a substring for a partial match
span1alt = element(by.binding('name'))
expect(span1alt.text).to eq('Foo')

# This works for sites using Angular 1.2 but NOT 1.3
deprecatedSyntax = element(by.binding('{{person.name}}'))

@param binding_descriptor <String>
@return { binding: binding_descriptor }


81
82
83
# File 'lib/angular_webdriver/protractor/by.rb', line 81

def binding binding_descriptor
  { binding: binding_descriptor }
end

.buttonText(search_text) ⇒ buttonText: search_text

Find a button by text.

<button>Save</button>

element(by.buttonText(‘Save’))

Parameters:

  • search_text (String)

Returns:

  • (buttonText: search_text)


130
131
132
# File 'lib/angular_webdriver/protractor/by.rb', line 130

def buttonText search_text
  { buttonText: search_text }
end

.class(what) ⇒ Object

Selenium locators



9
10
11
# File 'lib/angular_webdriver/protractor/by.rb', line 9

def class what
  { class: what }
end

.class_name(what) ⇒ Object



13
14
15
# File 'lib/angular_webdriver/protractor/by.rb', line 13

def class_name what
  { class_name: what }
end

.css(what) ⇒ Object



17
18
19
# File 'lib/angular_webdriver/protractor/by.rb', line 17

def css what
  { css: what }
end

.cssContainingText(css_selector, search_text) ⇒ cssContainingText: { cssSelector: css_selector, searchText: search_text }

Find elements by CSS which contain a certain string.

@view
<ul>
  <li class="pet">Dog</li>
  <li class="pet">Cat</li>
</ul>

@example
# Returns the li for the dog, but not cat.
dog = element(by.cssContainingText('.pet', 'Dog'))

Returns:

  • (cssContainingText: { cssSelector: css_selector, searchText: search_text })


184
185
186
187
188
189
# File 'lib/angular_webdriver/protractor/by.rb', line 184

def cssContainingText css_selector, search_text
  # the "what" must be a string or watir will complain it's not a valid what.
  # even if watir is patched to accept hashes, the what will be converted
  # to a string by the time it's seen by selenium webdriver.
  { cssContainingText: { cssSelector: css_selector, searchText: search_text }.to_json }
end

.deepCss(selector) ⇒ Object

Find an element by css selector within the Shadow DOM.

<div>

<span id="outerspan">
<"shadow tree">
  <span id="span1"></span>
  <"shadow tree">
    <span id="span2"></span>
  </>
</>

</div> spans = element.all(by.deepCss(‘span’)); expect(spans.count()).to eq(3);



283
284
285
286
# File 'lib/angular_webdriver/protractor/by.rb', line 283

def deepCss selector
  # TODO: syntax will change from /deep/ to >>> at some point.
  { css: '* /deep/ ' + selector }
end

.exactBinding(binding_descriptor) ⇒ Object

Find an element by exact binding.

<span>person.name }</span> <span ng-bind=“person-email”></span> <span>{person_phone|uppercase}</span>

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 }


102
103
104
# File 'lib/angular_webdriver/protractor/by.rb', line 102

def exactBinding binding_descriptor
  { exactBinding: binding_descriptor }
end

.exactRepeater(repeat_descriptor) ⇒ Object

Find an element by exact repeater.

@view
<li ng-repeat="person in peopleWithRedHair"></li>
<li ng-repeat="car in cars | orderBy:year"></li>

@example
expect(element(by.exactRepeater('person in peopleWithRedHair')).present?)
    .to eq(true);
expect(element(by.exactRepeater('person in people')).present?).to eq(false);
expect(element(by.exactRepeater('car in cars')).present?).to eq(true);

@param {string} repeatDescriptor
@return {{findElementsOverride: findElementsOverride, toString: Function|string}}


263
264
265
# File 'lib/angular_webdriver/protractor/by.rb', line 263

def exactRepeater repeat_descriptor
  ByRepeaterInner.new exact: true, repeat_descriptor: repeat_descriptor
end

.id(what) ⇒ Object



21
22
23
# File 'lib/angular_webdriver/protractor/by.rb', line 21

def id what
  { id: what }
end


25
26
27
# File 'lib/angular_webdriver/protractor/by.rb', line 25

def link what
  { link: what }
end


29
30
31
# File 'lib/angular_webdriver/protractor/by.rb', line 29

def link_text what
  { link_text: what }
end

.model(model_expression) ⇒ model: model_expression

Find an element by ng-model expression.

<input type=“text” ng-model=“person.name”>

input = element(by.model(‘person.name’)) input.send_keys(‘123’) expect(input.value).to eq(‘Foo123’)

Parameters:

  • model_expression (String)

    ng-model expression.

Returns:

  • (model: model_expression)


147
148
149
# File 'lib/angular_webdriver/protractor/by.rb', line 147

def model model_expression
  { model: model_expression }
end

.name(what) ⇒ Object



33
34
35
# File 'lib/angular_webdriver/protractor/by.rb', line 33

def name what
  { name: what }
end

.options(options_descriptor) ⇒ Object

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 }


168
169
170
# File 'lib/angular_webdriver/protractor/by.rb', line 168

def options options_descriptor
  { options: options_descriptor }
end


37
38
39
# File 'lib/angular_webdriver/protractor/by.rb', line 37

def partial_link_text what
  { partial_link_text: what }
end

.partialButtonText(search_text) ⇒ partialButtonText: search_text

Find a button by partial text.

<button>Save my file</button>

element(by.partialButtonText(‘Save’))

Parameters:

  • search_text (String)

Returns:

  • (partialButtonText: search_text)


116
117
118
# File 'lib/angular_webdriver/protractor/by.rb', line 116

def partialButtonText search_text
  { partialButtonText: search_text }
end

.repeater(repeat_descriptor) ⇒ Object

Find elements inside an ng-repeat.

@view
<div ng-repeat="cat in pets">
  <span>{{cat.name}}</span>
  <span>{{cat.age}}</span>
</div>

<div class="book-img" ng-repeat-start="book in library">
  <span>{{$index}}</span>
</div>
<div class="book-info" ng-repeat-end>
  <h4>{{book.name}}</h4>
  <p>{{book.blurb}}</p>
</div>

@example
// Returns the DIV for the second cat.
secondCat = element(by.repeater('cat in pets').row(1));

// Returns the SPAN for the first cat's name.
firstCatName = element(by.repeater('cat in pets').
    row(0).column('cat.name'));

// Returns a promise that resolves to an array of WebElements from a column
ages = element.all(
    by.repeater('cat in pets').column('cat.age'));

// Returns a promise that resolves to an array of WebElements containing
// all top level elements repeated by the repeater. For 2 pets rows resolves
// to an array of 2 elements.
rows = element.all(by.repeater('cat in pets'));

// Returns a promise that resolves to an array of WebElements containing all
// the elements with a binding to the book's name.
divs = element.all(by.repeater('book in library').column('book.name'));

// Returns a promise that resolves to an array of WebElements containing
// the DIVs for the second book.
bookInfo = element.all(by.repeater('book in library').row(1));

// Returns the H4 for the first book's name.
firstBookName = element(by.repeater('book in library').
    row(0).column('book.name'));

// Returns a promise that resolves to an array of WebElements containing
// all top level elements repeated by the repeater. For 2 books divs
// resolves to an array of 4 elements.
divs = element.all(by.repeater('book in library'));

@param {string} repeatDescriptor
@return {{findElementsOverride: findElementsOverride, toString: Function|string}}


244
245
246
# File 'lib/angular_webdriver/protractor/by.rb', line 244

def repeater repeat_descriptor
  ByRepeaterInner.new exact: false, repeat_descriptor: repeat_descriptor
end

.tag_name(what) ⇒ Object



41
42
43
# File 'lib/angular_webdriver/protractor/by.rb', line 41

def tag_name what
  { tag_name: what }
end

.xpath(what) ⇒ Object



45
46
47
# File 'lib/angular_webdriver/protractor/by.rb', line 45

def xpath what
  { xpath: what }
end