diff --git a/lib/element.js b/lib/element.js index e2666403e..4716ed9ad 100644 --- a/lib/element.js +++ b/lib/element.js @@ -229,14 +229,16 @@ ElementArrayFinder.prototype.filter = function(filterFn) { * expect(list.get(0).getText()).toBe('First'); * expect(list.get(1).getText()).toBe('Second'); * - * @param {number} index Element index. + * @param {number|webdriver.promise.Promise} index Element index. * @return {ElementFinder} finder representing element at the given index. */ ElementArrayFinder.prototype.get = function(index) { var self = this; var getWebElements = function() { - return self.getWebElements().then(function(parentWebElements) { - var i = index; + return webdriver.promise.all([ index, self.getWebElements() ]).then(function(results) { + var i = results[0]; + var parentWebElements = results[1]; + if (i < 0) { // wrap negative indices i = parentWebElements.length + i; diff --git a/scripts/test.js b/scripts/test.js index 1027810c4..d056ac8ce 100755 --- a/scripts/test.js +++ b/scripts/test.js @@ -119,9 +119,9 @@ executor.addCommandlineTest('node lib/cli.js spec/errorTest/slowHttpAndTimeoutCo .expectExitCode(1) .expectErrors([ {message: 'The following tasks were pending[\\s\\S]*\\$http: \/slowcall'}, - {message: 'The following tasks were pending[\\s\\S]*' + - '\\$timeout: function \\(\\) {[\\s\\S]*' + - '\\$scope\\.slowAngularTimeoutStatus = \'done\';[\\s\\S]' + + {message: 'The following tasks were pending[\\s\\S]*' + + '\\$timeout: function \\(\\) {[\\s\\S]*' + + '\\$scope\\.slowAngularTimeoutStatus = \'done\';[\\s\\S]' + '*}'} ]); diff --git a/spec/basic/elements_spec.js b/spec/basic/elements_spec.js index b5cce45fe..6ac9c823d 100644 --- a/spec/basic/elements_spec.js +++ b/spec/basic/elements_spec.js @@ -1,5 +1,3 @@ -var util = require('util'); - describe('ElementFinder', function() { beforeEach(function() { // Clear everything between each test. @@ -346,7 +344,7 @@ describe('ElementArrayFinder', function() { expect(element.all(by.binding('doesnotexist')).count()).toEqual(0); }); - it('should return not present when an element disappears within an array', + it('should return not present when an element disappears within an array', function() { browser.get('index.html#/form'); element.all(by.model('color')).then(function(elements) { @@ -367,6 +365,15 @@ describe('ElementArrayFinder', function() { expect(colorList.get(2).getAttribute('value')).toEqual('red'); }); + it('should get an element from an array by promise index', function() { + var colorList = element.all(by.model('color')); + var index = protractor.promise.fulfilled(1); + + browser.get('index.html#/form'); + + expect(colorList.get(index).getAttribute('value')).toEqual('green'); + }); + it('should get an element from an array using negative indices', function() { var colorList = element.all(by.model('color'));