我已經開始嘗試使用Nightmare和mocha執行自動化測試。儘管遵循錯誤本身的指示,但我仍在獲取下面的錯誤。噩夢:錯誤:超過2000ms的超時。異步測試和掛鉤
var Nightmare = require('nightmare');
var expect = require('chai').expect;
var url = 'http://www.google.com/'
describe('Page availability', function() {
it('Should open homepage', function(done) {
var nightmare = Nightmare();
nightmare
.goto(url)
.wait('body')
.evaluate(function() {
return document.querySelector('.gb_P').innerHTML
})
.end()
.then(function(text) {
expect(text).to.equal('images');
done();
})
});
});
運行與'摩卡test.js'上述腳本時
,這是輸出,我得到:
Page availability
1) Should open homepage
0 passing (2s)
1 failing
1) Page availability Should open homepage:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
自白:我(還)沒有精通與承諾,但我不明白爲什麼摩卡沒有考慮到完成回調,我已經在那裏提供。
哦,當我在閱讀問題概述中的標題時,我以爲你有一個_nightmare_ ...但它只是一個圖書館。 – KarelG
你找到了解決方案嗎? – user3142695