From 9e5d9e4abb7d0928e6092a711fda527554994be7 Mon Sep 17 00:00:00 2001 From: Chirayu Krishnappa Date: Wed, 21 May 2014 12:14:44 -0700 Subject: [PATCH] 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')` --- bin/elementexplorer.js | 3 -- docs/control-flow.md | 2 +- lib/clientsidescripts.js | 83 ------------------------------------- lib/locators.js | 72 -------------------------------- spec/basic/locators_spec.js | 41 +++--------------- 5 files changed, 7 insertions(+), 194 deletions(-) diff --git a/bin/elementexplorer.js b/bin/elementexplorer.js index 20cc8b681..ec7eeb712 100755 --- a/bin/elementexplorer.js +++ b/bin/elementexplorer.js @@ -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(\'\'))' diff --git a/docs/control-flow.md b/docs/control-flow.md index f5a1c8bce..e55bc3bfc 100644 --- a/docs/control-flow.md +++ b/docs/control-flow.md @@ -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'); diff --git a/lib/clientsidescripts.js b/lib/clientsidescripts.js index 879a1512e..2720f5e1c 100644 --- a/lib/clientsidescripts.js +++ b/lib/clientsidescripts.js @@ -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.} 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. * @@ -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.} 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.} 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.} 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. * diff --git a/lib/locators.js b/lib/locators.js index 3a984150a..a67410527 100644 --- a/lib/locators.js +++ b/lib/locators.js @@ -119,60 +119,6 @@ ProtractorBy.prototype.exactBinding = function(bindingDescriptor) { }; }; -/** - * @deprecated Use 'model' instead. - * - * @view - * - * - * @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 - * - * - * @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 - * - * - * @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. * @@ -244,24 +190,6 @@ ProtractorBy.prototype.partialButtonText = function(searchText) { }; -/** - * @deprecated Use 'model' instead. - * @view - * - * - * @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. * diff --git a/spec/basic/locators_spec.js b/spec/basic/locators_spec.js index 62f563bae..ad0cf6297 100644 --- a/spec/basic/locators_spec.js +++ b/spec/basic/locators_spec.js @@ -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(''); @@ -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) {