Can't get value at input with protractor

I am using angularJS to develop an application. To check this, I use a protractor.

I want to check the value in the input area. This is my input:

<input id="rank-max-range" class="form-control has-feedback" name="inputMax" type="number" placeholder="Maximum" ng-model="selectedItem.range.max" min="{{selectedItem.range.min}}" max="{{selectedItem.answers.length}}">

      

And this is the test:

it('should be fill the max range with the given value', function() {
  element(by.id('rank-max-range')).sendKeys(2);
  expect(element(by.id('rank-max-range')).getText()).toEqual(2);
});

      

The problem is, it didn't work. I found in the documentation what can be used getAttribute('value')

. But in my case, there is no value attribute on my input.

I wonder if the content can be checked ng-model

, but I haven't found a solution.

Do you have any idea how I can achieve this test?

+3


source to share


2 answers


getAttribute('value')

Should usually work. getText()

won't work because the input elements have no inner text.

expect(element(by.id('rank-max-range')).getAttribute('value')).toEqual(2);

      



Have you tried recording the result getAttribute('value')

?

+4


source


getText()

will definitely not work as it is input

, and this value will be inside the attribute value

once it is set. The HTML you submitted does not contain value

because it is the original HTML when no page is displayed and no value is set. getAttribute('value')

- path here:

var numberInput = element(by.id('rank-max-range'));
numberInput.sendKeys("2");
expect(numberInput.getAttribute('value')).toEqual("2");

      

You can actually install value

by resetting innerHTML

in the console:

numberInput.sendKeys("2");
numberInput.getInnerHtml().then(function (html) {
    console.log(html);
});

      




I wonder if it is possible to check the contents of the ng model, but I haven't found a solution.

You can use evaluate()

to see / check the value of the model:

expect(numberInput.evaluate('selectedItem.range.max')).toEqual(2);

      

+1


source







All Articles