我有一个示例fiddle,我正在尝试使用量角器进行测试。
以下是我的测试
describe("Fiddle homepage", function() {
beforeEach(function() {
browser.get('http://fiddle.jshell.net/yfUQ8/9/show');
browser.rootEl = 'div';
});
describe("binding", function() {
var inputByModel;
beforeEach(function() {
inputByModel = element(by.model('model.yourName'));
})
// Fail
it("should have value Julie1", function() {
inputByModel.sendKeys('Julie1');
// browser.waitForAngular();
expect(inputByModel.getText()).to.eventually.equal('Julie1');
});
// Fail
it("should have value Julie2", function() {
inputByModel.sendKeys('Julie2');
var greeting = element(by.model('model.yourName'));
expect(greeting.getText()).to.eventually.equal('Julie2');
});
// Pass
it("should have value Julie3", function() {
inputByModel.sendKeys('Julie3');
var byBinding = element(by.binding('model.yourName'));
expect(byBinding.getText()).to.eventually.equal('Julie');
});
// Fail
it("should get value by id and should pass the test", function() {
inputByModel.sendKeys('Julie4');
var byID = element(by.id('myinput'));
expect(byID.getText()).to.eventually.equal('Julie4');
})
});
});
我正在使用mocha,chaiAsPromised来运行我的测试。任何人都可以解释为什么我的前两个测试失败了吗?
答案 0 :(得分:7)
要获取输入元素的文本,您必须使用:
getAttribute('value')
而不是
getText()
量角器常见问题解答中记录了这一点:https://github.com/angular/protractor/blob/master/docs/faq.md#the-result-of-gettext-from-an-input-element-is-always-empty