7
在我的HTML文檔後閱讀的文本,我有以下代碼:量角器:試圖寫入文本框端對端測試
<label class="field" for="first_name">First Name:</label>
<span class="pull-right"><input type="text" id="first_name">
name="first_name" ng-model="first_name">
</span>
這會給我帶標籤的文本框旁邊說:「名」。
我然後在文本框中使用下面的代碼寫我的名字:
element(by.model('first_name')).sendKeys('Frank');
該代碼會寫弗蘭克在文本框中,但現在我的目標是試圖讀取文本框中的文本,使確定它實際上寫了我的名字。這樣做我有很多麻煩。
我使用下面的代碼從文本框讀取嘗試:
expect(element(by.model('first_name')).getText()).to.equal('Frank');
但我得到這個錯誤:
AssertionError: expected { Object (locator_, parentElementFinder_, ...) } to equal 'Frank'
而且當我嘗試做一個:
console.log(element(by.model('first_name')).getText());
我得到這個錯誤:
嘗試使用getAttribute('value')
當我得到同樣的錯誤。我不確定錯誤意味着什麼,我不太清楚當我使用console.log()
時我正在看什麼。我有點新使用量角器。任何幫助非常感謝,並提前謝謝你。
編輯:FULL spec.js
var chai = require('chai'),
chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
expect = chai.expect;
before(function() {
// suite wide initial setup here
browser.get("http://127.0.0.1:5000/");
browser.waitForAngular();
});
it('Should redirect and load template',function(){
element(by.id('authentication'))
.element(by.css('.text-center'))
.element(by.linkText('Click here'))
.click();
expect(browser.getCurrentUrl()).to.eventually.have.string('/#/home');
});
it('Should Enter name into text box', function(){
element(by.model('first_name')).sendKeys('Frank');
expect(element(by.model('first_name')).getAttribute('value'))
.to.equal('Frank');
});
我已經試過這個,但我得到了同樣的錯誤:AssertionError:expected {Object(locator_,parentElementFinder_,...)}等於'Frank' – Frank 2015-01-26 21:11:49
@FrankInsana你可以發佈你的規範的完整代碼,並注意量角器版本是否使用?謝謝。 – alecxe 2015-01-26 21:17:23
OMG我愛你!有用!!我嘗試使用「.then」,但顯然我做錯了。哇謝謝你!! +1 – Frank 2015-01-26 21:34:02