Created
September 8, 2014 22:22
-
-
Save elgalu/bd7e323225aab4b167e6 to your computer and use it in GitHub Desktop.
Dollar shortcuts for less typing, i.e. $model, $xpath, $linkText
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Dollar shortcuts for less typing, i.e. $model, $xpath, $linkText... | |
* | |
* @example | |
* var nameElm = $model('user.name'); | |
* // Equivalent to | |
* var nameElm = element(by.model('user.name')); | |
* | |
* @example | |
* var chainedElm = | |
* $model('container').$binding('user.name'); | |
* // Equivalent to | |
* var chainedElm = | |
* element(by.model('container')).element(by.binding('user.name')); | |
* | |
* @example | |
* var chainedLastElm = | |
* $model('container').$$binding('user.name').last(); | |
* // Equivalent to | |
* var chainedLastElm = | |
* element(by.model('container')).all(by.binding('user.name')).last(); | |
*/ | |
var LOCATORS = ['model', 'binding', 'exactBinding', 'repeater', 'options', | |
'linkText', 'partialLinkText', 'xpath', 'buttonText', 'partialButtonText', | |
'cssContainingText', 'name', 'id', 'js', 'tagName']; | |
/** | |
* Current workaround until https://github.com/angular/protractor/issues/1102 | |
* @type {Function} | |
*/ | |
var ElementFinder = $('').constructor; | |
var ElementArrayFinder = $$('').constructor; | |
LOCATORS.forEach(function(locatorName) { | |
global['$' + locatorName] = function() { | |
return element(By[locatorName].apply(By, arguments)); | |
}; | |
global['$$' + locatorName] = function() { | |
return element.all(By[locatorName].apply(By, arguments)); | |
}; | |
ElementFinder.prototype['$' + locatorName] = function() { | |
return this.element(By[locatorName].apply(By, arguments)); | |
}; | |
ElementArrayFinder.prototype['$$' + locatorName] = function() { | |
return this.all(By[locatorName].apply(By, arguments)); | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment