hello123 hello123 - 1 year ago 108
AngularJS Question

Issues with protractor test when finding element array using repeatable

I've created a protractor test for the following html:

<div class="well well-sm" data-ng-repeat="feedback in f.feedbackList">
<blockquote class="small">{{feedback.comment}}</blockquote>

In the page.js file I have:

"use strict";

module.exports = (function () {
function AdminFeedbackPage() {
this.comments = element.all(by.repeater('feedback in f.feedbackList').column('feedback.comment')).map(function (comments) {
return comments.getText();

this.ratings = element.all(by.repeater('feedback in f.feedbackList').column('feedback.rating')).map(function (ratings) {
return ratings.getText();

return AdminFeedbackPage; })();

and then in the test in my step.js file:

var feedbackFound = false;
var feedbackIndex;

adminFeedbackPage.comments.then(function (commments) {
for (var i = 0; i < commments.length; i++) {

console.log("Comments " + i + ": " + commments[i]);

if (commments[i] == "TestApplicationFeedback") {
feedbackIndex = i;
console.log("FEEDBACK INDEX - " + feedbackIndex)
feedbackFound = true;
}).then(function () {
}).then(function() {
adminFeedbackPage.ratings.then(function (ratings) {
console.log("RATINGS length " + ratings.length + " and rating is " + ratings[feedbackIndex]);

And I get the following logs:

Comments 0: Decent App

Comments 1: Really like it

Comments 2: TestApplicationFeedback



RATINGS length 0 and rating is undefined

AssertionError: expected undefined to equal 3

This is really confusing my since the comments are being found without any issue, but the ratings are just an empty array and as far as I can tell I have done the same thing for both.

Does anybody have any suggestions/reasons why the ratings aren't being found? I suspect it's something to do with what is in the page.js file, but I have no idea what could be wrong?


Answer Source

Solved this in the comments above, posting as an answer:

It was just a guess/suggestion based on the HTML, one was a child element and the other was directly inside the repeater (this one was failing to be captured). So my suggestion was to try using .evaluate() source, which acts as if on scope of the given element. So replacing .column() seems to work:

element.all(by.repeater('feedback in f.feedbackList')).evaluate('feedback.rating').then(function(val) {
    console.log(val) // should return an array of values (feedback.rating)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download