0

I am new to protractor and JavaScript and struggling trying to compare a delimited string to an array.

What I am trying to do is to find a list of all elements and then from each element, loop through the arrays to compare the text values to the delimited string but the delimited string values are 'undefined'

element.all(by.css('.itemField')).then(function (allFieldItems) {
  var  toCompare= ["AGO", "9"]
  for (var i = 0; i < toCompare.length; i++) {
    var valueToCompare = toCompare[i]
    allFieldItems[i].getText().then(function (text) {
      if(text != valueToCompare[i]){
        console.log("Values don't match")
          }
        }.bind( i))
      }
})

The problem is that the line "if(text != valueToCompare[i]) the "valueToCompare[i]" is always 'undefined' and I am looking for help on how to resolve this without using expect statements.

1 Answer 1

1

You can call getText() on the result of element.all() directly:

var toCompare = ["AGO", "9"];
element.all(by.css('.itemField')).getText().then(function (texts) {
    for (var i = 0; i < toCompare.length; i++) {  
        if (texts[i] != toCompare[i]) { 
            console.log("Values don't match");
        } 
    }
});

Or, you may even expect it like this (not sure if this is what you are actually trying to do):

expect($$('.itemField').getText()).toEqual(toCompare);
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.