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

Commit

Permalink
feat(ElementArrayFinder#get): Implemented ability to pass promise as …
Browse files Browse the repository at this point in the history
…index to ElementArrayFinder#get
  • Loading branch information
stalniy authored and sjelin committed Nov 9, 2015
1 parent deba67d commit a40a4ba
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
8 changes: 5 additions & 3 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions scripts/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]' +
'*}'}
]);

Expand Down
13 changes: 10 additions & 3 deletions spec/basic/elements_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
var util = require('util');

describe('ElementFinder', function() {
beforeEach(function() {
// Clear everything between each test.
Expand Down Expand Up @@ -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) {
Expand All @@ -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'));

Expand Down

0 comments on commit a40a4ba

Please sign in to comment.