Tuesday 30 May 2017

Aurelia e2e: text.indexOf() not correctly comparing string to that contained in a div

I'm trying to check to see if text contained in a div header matches what I have inside in my text.indexOf() function and if it does, it will print 'true' on the console and if not, it will print 'false'. I don't want to check if the text is an exact match, I just want to see if "EUR" is contained inside in the Div. Here is the code from my page object file

this.checkIfEur = function(eur) {
     var checkCurrency = element(by.className("m-l-sm"));
        checkCurrency.getText().then(function (text) {
            if (text.indexOf("EUR">= 0))   {
              console.log("true");
            }
            else if (text.indexOf("EUR"<= 0)){
              console.log("false");
            }
          });
};
<div class="currencies">
               <span>Opening Currency</span>
               <span class="m-l-sm">
               <b>EUR 1,000</b>
               </span><span class="m-l-sm">`
               <b>GBP 5,000</b>
               </span><!--anchor-->
        </div>

The problem is that if I was to replace EUR with zzzzzzz the console will still print 'true'. It doesn't seem to matter what I text I want to be accepted, it will always print true.

I'm possibly doing this completely wrong, any help is appreciated



via Edmond

No comments:

Post a Comment