Skip to content
This repository was archived by the owner on Jul 29, 2024. It is now read-only.

Commit 9e5d9e4

Browse files
chirayukjuliemr
authored andcommitted
feat(locators): remove deprecated locator APIs
This is a **breaking change**. The following deprecated Locator APIs have been removed. - `by.input` - `by.select` - `by.selectedOption` - `by.textarea` `input`, `select`, and `textarea` can be replaced by `by.model`. `element(by.selectedOption('foo'))` can be replaced by `element(by.model('foo')).$('option:checked')`
1 parent 8d46e21 commit 9e5d9e4

File tree

5 files changed

+7
-194
lines changed

5 files changed

+7
-194
lines changed

bin/elementexplorer.js

-3
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,6 @@ var INITIAL_SUGGESTIONS = [
4646
'element(by.css(\'\'))',
4747
'element(by.name(\'\'))',
4848
'element(by.binding(\'\'))',
49-
'element(by.input(\'\'))',
50-
'element(by.select(\'\'))',
51-
'element(by.textarea(\'\'))',
5249
'element(by.xpath(\'\'))',
5350
'element(by.tagName(\'\'))',
5451
'element(by.className(\'\'))'

docs/control-flow.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ to keep execution organized. For example, consider the test
1919
it('should find an element by text input model', function() {
2020
browser.get('app/index.html#/form');
2121

22-
var username = element(by.input('username'));
22+
var username = element(by.model('username'));
2323
username.clear();
2424
username.sendKeys('Jane Doe');
2525

lib/clientsidescripts.js

-83
Original file line numberDiff line numberDiff line change
@@ -326,27 +326,6 @@ clientSideScripts.findRepeaterColumn = function(repeater, binding, using) {
326326
return matches;
327327
};
328328

329-
/**
330-
* Find an input elements by model name.
331-
* DEPRECATED - use findByModel
332-
*
333-
* @param {string} model The model name.
334-
* @param {Element} using The scope of the search. Defaults to 'document'.
335-
*
336-
* @return {Array.<Element>} The matching input elements.
337-
*/
338-
clientSideScripts.findInputs = function(model, using) {
339-
using = using || document;
340-
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
341-
for (var p = 0; p < prefixes.length; ++p) {
342-
var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
343-
var inputs = using.querySelectorAll(selector);
344-
if (inputs.length) {
345-
return inputs;
346-
}
347-
}
348-
};
349-
350329
/**
351330
* Find elements by model name.
352331
*
@@ -423,68 +402,6 @@ clientSideScripts.findByPartialButtonText = function(searchText, using) {
423402
return matches;
424403
};
425404

426-
427-
/**
428-
* Find multiple select elements by model name.
429-
*
430-
* @param {string} model The model name.
431-
* @param {Element} using The scope of the search. Defaults to 'document'.
432-
*
433-
* @return {Array.<Element>} The matching select elements.
434-
*/
435-
clientSideScripts.findSelects = function(model, using) {
436-
using = using || document;
437-
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
438-
for (var p = 0; p < prefixes.length; ++p) {
439-
var selector = 'select[' + prefixes[p] + 'model="' + model + '"]';
440-
var inputs = using.querySelectorAll(selector);
441-
if (inputs.length) {
442-
return inputs;
443-
}
444-
}
445-
};
446-
447-
/**
448-
* Find selected option elements by model name.
449-
*
450-
* @param {string} model The model name.
451-
* @param {Element} using The scope of the search. Defaults to 'document'.
452-
*
453-
* @return {Array.<Element>} The matching select elements.
454-
*/
455-
clientSideScripts.findSelectedOptions = function(model, using) {
456-
using = using || document;
457-
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
458-
for (var p = 0; p < prefixes.length; ++p) {
459-
var selector = 'select[' + prefixes[p] + 'model="' + model + '"] option:checked';
460-
var inputs = using.querySelectorAll(selector);
461-
if (inputs.length) {
462-
return inputs;
463-
}
464-
}
465-
};
466-
467-
/**
468-
* Find textarea elements by model name.
469-
*
470-
* @param {String} model The model name.
471-
* @param {Element} using The scope of the search. Defaults to 'document'.
472-
*
473-
* @return {Array.<Element>} An array of matching textarea elements.
474-
*/
475-
clientSideScripts.findTextareas = function(model, using) {
476-
using = using || document;
477-
478-
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
479-
for (var p = 0; p < prefixes.length; ++p) {
480-
var selector = 'textarea[' + prefixes[p] + 'model="' + model + '"]';
481-
var textareas = using.querySelectorAll(selector);
482-
if (textareas.length) {
483-
return textareas;
484-
}
485-
}
486-
};
487-
488405
/**
489406
* Find elements by css selector and textual content.
490407
*

lib/locators.js

-72
Original file line numberDiff line numberDiff line change
@@ -119,60 +119,6 @@ ProtractorBy.prototype.exactBinding = function(bindingDescriptor) {
119119
};
120120
};
121121

122-
/**
123-
* @deprecated Use 'model' instead.
124-
*
125-
* @view
126-
* <select ng-model="user" ng-options="user.name for user in users"></select>
127-
*
128-
* @example
129-
* element(by.select('user'));
130-
*/
131-
ProtractorBy.prototype.select = function(model) {
132-
return {
133-
findElementsOverride: function(driver, using) {
134-
return driver.findElements(
135-
webdriver.By.js(clientSideScripts.findSelects, model, using));
136-
},
137-
message: 'by.select("' + model + '")'
138-
};
139-
};
140-
141-
/**
142-
* @view
143-
* <select ng-model="user" ng-options="user.name for user in users"></select>
144-
*
145-
* @example
146-
* element(by.selectedOption("user"));
147-
*/
148-
ProtractorBy.prototype.selectedOption = function(model) {
149-
return {
150-
findElementsOverride: function(driver, using) {
151-
return driver.findElements(
152-
webdriver.By.js(clientSideScripts.findSelectedOptions, model, using));
153-
},
154-
message: 'by.selectedOption("' + model + '")'
155-
};
156-
};
157-
158-
/**
159-
* @deprecated Use 'model' instead.
160-
* @view
161-
* <input ng-model="user" type="text"/>
162-
*
163-
* @example
164-
* element(by.input('user'));
165-
*/
166-
ProtractorBy.prototype.input = function(model) {
167-
return {
168-
findElementsOverride: function(driver, using) {
169-
return driver.findElements(
170-
webdriver.By.js(clientSideScripts.findInputs, model, using));
171-
},
172-
message: 'by.input("' + model + '")'
173-
};
174-
};
175-
176122
/**
177123
* Find an element by ng-model expression.
178124
*
@@ -244,24 +190,6 @@ ProtractorBy.prototype.partialButtonText = function(searchText) {
244190
};
245191

246192

247-
/**
248-
* @deprecated Use 'model' instead.
249-
* @view
250-
* <textarea ng-model="user"></textarea>
251-
*
252-
* @example
253-
* element(by.textarea('user'));
254-
*/
255-
ProtractorBy.prototype.textarea = function(model) {
256-
return {
257-
findElementsOverride: function(driver, using) {
258-
return driver.findElements(
259-
webdriver.By.js(clientSideScripts.findTextareas, model, using));
260-
},
261-
message: 'by.textarea("' + model + '")'
262-
};
263-
};
264-
265193
/**
266194
* Find elements inside an ng-repeat.
267195
*

spec/basic/locators_spec.js

+6-35
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,17 @@ describe('locators', function() {
7676
toEqual('Something else to write about');
7777
});
7878

79-
it('should find an element by textarea model', function() {
80-
// Note: deprecated API.
81-
var about = element(by.textarea('aboutbox'));
82-
expect(about.getAttribute('value')).toEqual('This is a text box');
83-
84-
about.clear();
85-
about.sendKeys('Something else to write about');
86-
87-
expect(about.getAttribute('value')).
88-
toEqual('Something else to write about');
89-
});
90-
9179
it('should find multiple selects by model', function() {
9280
var selects = element.all(by.model('dayColor.color'));
9381
expect(selects.count()).toEqual(3);
9482
});
9583

84+
it('should find the selected option', function() {
85+
var select = element(by.model('fruit'));
86+
var selectedOption = select.element(by.css('option:checked'));
87+
expect(selectedOption.getText()).toEqual('apple');
88+
});
89+
9690
it('should find inputs with alternate attribute forms', function() {
9791
var letterList = element(by.id('letterlist'));
9892
expect(letterList.getText()).toBe('');
@@ -131,29 +125,6 @@ describe('locators', function() {
131125
});
132126
});
133127

134-
describe('by select', function() {
135-
it('should find multiple selects', function() {
136-
// Note: deprecated API.
137-
element.all(by.select('dayColor.color')).then(function(arr) {
138-
expect(arr.length).toEqual(3);
139-
});
140-
});
141-
142-
it('should find the selected option', function() {
143-
expect(element(by.selectedOption('fruit')).getText()).toEqual('apple');
144-
});
145-
146-
it('should find multiple selected options', function() {
147-
element.all(
148-
by.selectedOption('dayColor.color')).then(function(arr) {
149-
expect(arr.length).toEqual(3);
150-
expect(arr[0].getText()).toBe('red');
151-
expect(arr[1].getText()).toBe('green');
152-
expect(arr[2].getText()).toBe('blue');
153-
});
154-
});
155-
});
156-
157128
describe('by partial button text', function() {
158129
it('should find multiple buttons containing "text"', function() {
159130
element.all(by.partialButtonText('text')).then(function(arr) {

0 commit comments

Comments
 (0)