无法使用量角器获取输入中的值
Can't get the value in an input with protractor
我正在使用 angularJS 开发应用程序。为了测试它,我使用量角器。
我想检查输入区域中的值。这是我的输入:
<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}}">
这是测试:
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);
});
问题是它不起作用。我在文档中发现可以使用 getAttribute('value')
。但就我而言,我的输入没有值属性。
我想知道是否可以查看 ng-model
的内容,但我没有找到解决方案。
你知道我怎样才能完成这个测试吗?
通常 getAttribute('value')
应该可以。 getText()
将不起作用,因为输入元素没有内部文本。
expect(element(by.id('rank-max-range')).getAttribute('value')).toEqual(2);
您是否尝试记录 getAttribute('value')
的结果?
getText()
肯定不会起作用,因为这是一个 input
,一旦设置,它的值将在 value
属性内。您呈现的 HTML 不包含 value
,因为当页面未呈现且未设置值时,这是源 HTML。 getAttribute('value')
是去这里的路:
var numberInput = element(by.id('rank-max-range'));
numberInput.sendKeys("2");
expect(numberInput.getAttribute('value')).toEqual("2");
您实际上可以通过在控制台上转储 innerHTML
来看到正在设置的 value
:
numberInput.sendKeys("2");
numberInput.getInnerHtml().then(function (html) {
console.log(html);
});
I wonder if it possible to check the content of the ng-model but I didn't find the solution.
可以使用evaluate()
来see/check模型的值:
expect(numberInput.evaluate('selectedItem.range.max')).toEqual(2);
我正在使用 angularJS 开发应用程序。为了测试它,我使用量角器。
我想检查输入区域中的值。这是我的输入:
<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}}">
这是测试:
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);
});
问题是它不起作用。我在文档中发现可以使用 getAttribute('value')
。但就我而言,我的输入没有值属性。
我想知道是否可以查看 ng-model
的内容,但我没有找到解决方案。
你知道我怎样才能完成这个测试吗?
通常 getAttribute('value')
应该可以。 getText()
将不起作用,因为输入元素没有内部文本。
expect(element(by.id('rank-max-range')).getAttribute('value')).toEqual(2);
您是否尝试记录 getAttribute('value')
的结果?
getText()
肯定不会起作用,因为这是一个 input
,一旦设置,它的值将在 value
属性内。您呈现的 HTML 不包含 value
,因为当页面未呈现且未设置值时,这是源 HTML。 getAttribute('value')
是去这里的路:
var numberInput = element(by.id('rank-max-range'));
numberInput.sendKeys("2");
expect(numberInput.getAttribute('value')).toEqual("2");
您实际上可以通过在控制台上转储 innerHTML
来看到正在设置的 value
:
numberInput.sendKeys("2");
numberInput.getInnerHtml().then(function (html) {
console.log(html);
});
I wonder if it possible to check the content of the ng-model but I didn't find the solution.
可以使用evaluate()
来see/check模型的值:
expect(numberInput.evaluate('selectedItem.range.max')).toEqual(2);