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

Commit

Permalink
feat(locators): remove deprecated locator APIs
Browse files Browse the repository at this point in the history
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')`
  • Loading branch information
chirayuk authored and juliemr committed May 23, 2014
1 parent 8d46e21 commit 9e5d9e4
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 194 deletions.
3 changes: 0 additions & 3 deletions bin/elementexplorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ var INITIAL_SUGGESTIONS = [
'element(by.css(\'\'))',
'element(by.name(\'\'))',
'element(by.binding(\'\'))',
'element(by.input(\'\'))',
'element(by.select(\'\'))',
'element(by.textarea(\'\'))',
'element(by.xpath(\'\'))',
'element(by.tagName(\'\'))',
'element(by.className(\'\'))'
Expand Down
2 changes: 1 addition & 1 deletion docs/control-flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ to keep execution organized. For example, consider the test
it('should find an element by text input model', function() {
browser.get('app/index.html#/form');

var username = element(by.input('username'));
var username = element(by.model('username'));
username.clear();
username.sendKeys('Jane Doe');

Expand Down
83 changes: 0 additions & 83 deletions lib/clientsidescripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,27 +326,6 @@ clientSideScripts.findRepeaterColumn = function(repeater, binding, using) {
return matches;
};

/**
* Find an input elements by model name.
* DEPRECATED - use findByModel
*
* @param {string} model The model name.
* @param {Element} using The scope of the search. Defaults to 'document'.
*
* @return {Array.<Element>} The matching input elements.
*/
clientSideScripts.findInputs = function(model, using) {
using = using || document;
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = 'input[' + prefixes[p] + 'model="' + model + '"]';
var inputs = using.querySelectorAll(selector);
if (inputs.length) {
return inputs;
}
}
};

/**
* Find elements by model name.
*
Expand Down Expand Up @@ -423,68 +402,6 @@ clientSideScripts.findByPartialButtonText = function(searchText, using) {
return matches;
};


/**
* Find multiple select elements by model name.
*
* @param {string} model The model name.
* @param {Element} using The scope of the search. Defaults to 'document'.
*
* @return {Array.<Element>} The matching select elements.
*/
clientSideScripts.findSelects = function(model, using) {
using = using || document;
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = 'select[' + prefixes[p] + 'model="' + model + '"]';
var inputs = using.querySelectorAll(selector);
if (inputs.length) {
return inputs;
}
}
};

/**
* Find selected option elements by model name.
*
* @param {string} model The model name.
* @param {Element} using The scope of the search. Defaults to 'document'.
*
* @return {Array.<Element>} The matching select elements.
*/
clientSideScripts.findSelectedOptions = function(model, using) {
using = using || document;
var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = 'select[' + prefixes[p] + 'model="' + model + '"] option:checked';
var inputs = using.querySelectorAll(selector);
if (inputs.length) {
return inputs;
}
}
};

/**
* Find textarea elements by model name.
*
* @param {String} model The model name.
* @param {Element} using The scope of the search. Defaults to 'document'.
*
* @return {Array.<Element>} An array of matching textarea elements.
*/
clientSideScripts.findTextareas = function(model, using) {
using = using || document;

var prefixes = ['ng-', 'ng_', 'data-ng-', 'x-ng-', 'ng\\:'];
for (var p = 0; p < prefixes.length; ++p) {
var selector = 'textarea[' + prefixes[p] + 'model="' + model + '"]';
var textareas = using.querySelectorAll(selector);
if (textareas.length) {
return textareas;
}
}
};

/**
* Find elements by css selector and textual content.
*
Expand Down
72 changes: 0 additions & 72 deletions lib/locators.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,60 +119,6 @@ ProtractorBy.prototype.exactBinding = function(bindingDescriptor) {
};
};

/**
* @deprecated Use 'model' instead.
*
* @view
* <select ng-model="user" ng-options="user.name for user in users"></select>
*
* @example
* element(by.select('user'));
*/
ProtractorBy.prototype.select = function(model) {
return {
findElementsOverride: function(driver, using) {
return driver.findElements(
webdriver.By.js(clientSideScripts.findSelects, model, using));
},
message: 'by.select("' + model + '")'
};
};

/**
* @view
* <select ng-model="user" ng-options="user.name for user in users"></select>
*
* @example
* element(by.selectedOption("user"));
*/
ProtractorBy.prototype.selectedOption = function(model) {
return {
findElementsOverride: function(driver, using) {
return driver.findElements(
webdriver.By.js(clientSideScripts.findSelectedOptions, model, using));
},
message: 'by.selectedOption("' + model + '")'
};
};

/**
* @deprecated Use 'model' instead.
* @view
* <input ng-model="user" type="text"/>
*
* @example
* element(by.input('user'));
*/
ProtractorBy.prototype.input = function(model) {
return {
findElementsOverride: function(driver, using) {
return driver.findElements(
webdriver.By.js(clientSideScripts.findInputs, model, using));
},
message: 'by.input("' + model + '")'
};
};

/**
* Find an element by ng-model expression.
*
Expand Down Expand Up @@ -244,24 +190,6 @@ ProtractorBy.prototype.partialButtonText = function(searchText) {
};


/**
* @deprecated Use 'model' instead.
* @view
* <textarea ng-model="user"></textarea>
*
* @example
* element(by.textarea('user'));
*/
ProtractorBy.prototype.textarea = function(model) {
return {
findElementsOverride: function(driver, using) {
return driver.findElements(
webdriver.By.js(clientSideScripts.findTextareas, model, using));
},
message: 'by.textarea("' + model + '")'
};
};

/**
* Find elements inside an ng-repeat.
*
Expand Down
41 changes: 6 additions & 35 deletions spec/basic/locators_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,17 @@ describe('locators', function() {
toEqual('Something else to write about');
});

it('should find an element by textarea model', function() {
// Note: deprecated API.
var about = element(by.textarea('aboutbox'));
expect(about.getAttribute('value')).toEqual('This is a text box');

about.clear();
about.sendKeys('Something else to write about');

expect(about.getAttribute('value')).
toEqual('Something else to write about');
});

it('should find multiple selects by model', function() {
var selects = element.all(by.model('dayColor.color'));
expect(selects.count()).toEqual(3);
});

it('should find the selected option', function() {
var select = element(by.model('fruit'));
var selectedOption = select.element(by.css('option:checked'));
expect(selectedOption.getText()).toEqual('apple');
});

it('should find inputs with alternate attribute forms', function() {
var letterList = element(by.id('letterlist'));
expect(letterList.getText()).toBe('');
Expand Down Expand Up @@ -131,29 +125,6 @@ describe('locators', function() {
});
});

describe('by select', function() {
it('should find multiple selects', function() {
// Note: deprecated API.
element.all(by.select('dayColor.color')).then(function(arr) {
expect(arr.length).toEqual(3);
});
});

it('should find the selected option', function() {
expect(element(by.selectedOption('fruit')).getText()).toEqual('apple');
});

it('should find multiple selected options', function() {
element.all(
by.selectedOption('dayColor.color')).then(function(arr) {
expect(arr.length).toEqual(3);
expect(arr[0].getText()).toBe('red');
expect(arr[1].getText()).toBe('green');
expect(arr[2].getText()).toBe('blue');
});
});
});

describe('by partial button text', function() {
it('should find multiple buttons containing "text"', function() {
element.all(by.partialButtonText('text')).then(function(arr) {
Expand Down

0 comments on commit 9e5d9e4

Please sign in to comment.