如何在没有ng-bind和ng-model的情况下检查范围内的变量?
<span ng-if="user.code === 'YELLOW'"> <span class="glyphicons glyphicons-circle-remove text-danger"></span> Yellow </span> <span ng-if="user.code === 'GREEN'"> <span class="glyphicons glyphicons-circle-exclamation-mark text-warning"></span> Green </span>
我想用量角器检查user.code
使用ng-bind和ng-model它不起作用
browser.expect(element(by.binding('user.code')).getText()).to.eventually.equal('');
要么
browser.expect(element(by.model('user.code')).getAttribute('value')).to.eventually.equal('');
错误:
NoSuchElementError: No element found using locator: by.binding("user.code") NoSuchElementError: No element found using locator: by.model("user.code")
解决方法
你不应该在量角器中测试那种东西.您应该从用户的角度编写测试.
但是,如果要测试使用评估.获取对DOM元素的引用,然后调用evaluate:
// Choose a DOM element bound to a scope that contains the value you // want to test expect($('span').evaluate('user.code')).toBe('some value');
http://www.protractortest.org/#/api?view=ElementArrayFinder.prototype.evaluate