1

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

<div class="well well-sm" data-ng-repeat="feedback in f.feedbackList">
   Rating:&nbsp;{{feedback.rating}}
   <blockquote class="small">{{feedback.comment}}</blockquote>
</div>

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;
                    break;
                }
            }
        }).then(function () {
            expect(feedbackFound).to.be.true;
        }).then(function() {
          adminFeedbackPage.ratings.then(function (ratings) {
              console.log(ratings);
              console.log("RATINGS length " + ratings.length + " and rating is " + ratings[feedbackIndex]);
              expect(ratings[feedbackIndex]).to.equal(3);
          })
        });

And I get the following logs:

Comments 0: Decent App

Comments 1: Really like it

Comments 2: TestApplicationFeedback

FEEDBACK INDEX - 2

[]

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?

Thanks!

6
  • Looks correct... Maybe try .evaluate() (docs) instead of .column() for that, since it's within the ng-repeat and not on a child element like feedback.comments? Commented Oct 5, 2016 at 13:37
  • Whereabouts? I tried instead of getText, but I'm guessing you mean instead of .column or possibly in place of the map function somehow? Commented Oct 5, 2016 at 13:42
  • 1
    Yea I was suggesting in place of .column, might even remove the need for map too. Try this: element.all(by.repeater('feedback in f.feedbackList')).evaluate('feedback.ratings').then(function(val) { console.log(val) }). I tried on our app with a different repeater, and it returned an array of values like I was expecting Commented Oct 5, 2016 at 13:49
  • Instead of an empty array that gave an array of length 3, but all the values were null. Commented Oct 5, 2016 at 13:57
  • Actually, I just needed to change to feedback.rating instead of feedback.ratings and that's worked! Thanks a lot! Commented Oct 5, 2016 at 14:00

1 Answer 1

1

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)
})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.