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

Commit a40a4ba

Browse files
stalniysjelin
authored andcommitted
feat(ElementArrayFinder#get): Implemented ability to pass promise as index to ElementArrayFinder#get
1 parent deba67d commit a40a4ba

File tree

3 files changed

+18
-9
lines changed

3 files changed

+18
-9
lines changed

lib/element.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,16 @@ ElementArrayFinder.prototype.filter = function(filterFn) {
229229
* expect(list.get(0).getText()).toBe('First');
230230
* expect(list.get(1).getText()).toBe('Second');
231231
*
232-
* @param {number} index Element index.
232+
* @param {number|webdriver.promise.Promise} index Element index.
233233
* @return {ElementFinder} finder representing element at the given index.
234234
*/
235235
ElementArrayFinder.prototype.get = function(index) {
236236
var self = this;
237237
var getWebElements = function() {
238-
return self.getWebElements().then(function(parentWebElements) {
239-
var i = index;
238+
return webdriver.promise.all([ index, self.getWebElements() ]).then(function(results) {
239+
var i = results[0];
240+
var parentWebElements = results[1];
241+
240242
if (i < 0) {
241243
// wrap negative indices
242244
i = parentWebElements.length + i;

scripts/test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,9 @@ executor.addCommandlineTest('node lib/cli.js spec/errorTest/slowHttpAndTimeoutCo
119119
.expectExitCode(1)
120120
.expectErrors([
121121
{message: 'The following tasks were pending[\\s\\S]*\\$http: \/slowcall'},
122-
{message: 'The following tasks were pending[\\s\\S]*' +
123-
'\\$timeout: function \\(\\) {[\\s\\S]*' +
124-
'\\$scope\\.slowAngularTimeoutStatus = \'done\';[\\s\\S]' +
122+
{message: 'The following tasks were pending[\\s\\S]*' +
123+
'\\$timeout: function \\(\\) {[\\s\\S]*' +
124+
'\\$scope\\.slowAngularTimeoutStatus = \'done\';[\\s\\S]' +
125125
'*}'}
126126
]);
127127

spec/basic/elements_spec.js

+10-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
var util = require('util');
2-
31
describe('ElementFinder', function() {
42
beforeEach(function() {
53
// Clear everything between each test.
@@ -346,7 +344,7 @@ describe('ElementArrayFinder', function() {
346344
expect(element.all(by.binding('doesnotexist')).count()).toEqual(0);
347345
});
348346

349-
it('should return not present when an element disappears within an array',
347+
it('should return not present when an element disappears within an array',
350348
function() {
351349
browser.get('index.html#/form');
352350
element.all(by.model('color')).then(function(elements) {
@@ -367,6 +365,15 @@ describe('ElementArrayFinder', function() {
367365
expect(colorList.get(2).getAttribute('value')).toEqual('red');
368366
});
369367

368+
it('should get an element from an array by promise index', function() {
369+
var colorList = element.all(by.model('color'));
370+
var index = protractor.promise.fulfilled(1);
371+
372+
browser.get('index.html#/form');
373+
374+
expect(colorList.get(index).getAttribute('value')).toEqual('green');
375+
});
376+
370377
it('should get an element from an array using negative indices', function() {
371378
var colorList = element.all(by.model('color'));
372379

0 commit comments

Comments
 (0)