ここで説明されているように、多かれ少なかれMocha とWebDriverJSを使用して Web アプリケーションをテストしています。テストに合格すると、すべて問題ありません。ただし、1 つのテストが失敗した場合、スイート内の残りのテストはタイムアウトし、ランナーは Webdriver インスタンスを閉じずにスイートの最後で終了します。テストケースの例:
var assert = require('assert'),
client = require("webdriverjs").remote({
logLevel: 'silent'
});
describe('Self-test', function() {
before(function(done) {
client
.init()
.url('http://www.wikipedia.org/', function() {
done();
});
});
after(function(done) {
client.end(function() {
done();
});
});
// tests
it('should fail properly', function(done) {
client.getTitle(function(result) {
assert(false, 'This should fail');
done();
});
});
it('should pass afterwards', function(done) {
client.getTitle(function(result) {
assert(true, 'This should still pass');
done();
});
});
});
出力:
~> mocha test/self-test.js
Self-test
1) should fail properly
2) should pass afterwards
3) "after all" hook
✖ 3 of 2 tests failed:
1) Self-test should fail properly:
AssertionError: This should fail
at null.<anonymous> (./test/self-test.js:24:17)
at QueueItem (./node_modules/webdriverjs/lib/webdriverjs.js:242:15)
at null.<anonymous> (./node_modules/webdriverjs/lib/commands/getTitle.js:12:6)
at QueueItem (./node_modules/webdriverjs/lib/webdriverjs.js:242:15)
at IncomingMessage.WebdriverJs.proxyResponse (./node_modules/webdriverjs/lib/webdriverjs.js:782:6)
at IncomingMessage.EventEmitter.emit (events.js:115:20)
at IncomingMessage._emitEnd (http.js:366:10)
at HTTPParser.parserOnMessageComplete [as onMessageComplete] (http.js:149:23)
at Socket.socketOnData [as ondata] (http.js:1366:20)
at TCP.onread (net.js:402:27)
2) Self-test should pass afterwards:
Error: timeout of 10000ms exceeded
at Object.<anonymous> (./node_modules/mocha/lib/runnable.js:158:14)
at Timer.list.ontimeout (timers.js:101:19)
3) Self-test "after all" hook:
Error: timeout of 10000ms exceeded
at Object.<anonymous> (./node_modules/mocha/lib/runnable.js:158:14)
at Timer.list.ontimeout (timers.js:101:19)
私が知る限り、これはテストが失敗したときに WebDriverJS キューが停止するためです。これを修正する方法はありますか?ローカルのコマンドライン テストでも最適ではなく、テストを自動的に実行したり、バックグラウンドで実行したりすることは困難または不可能です。
更新:テストごとに新しいクライアントをインスタンス化することでキューの失敗を修正できると思いますが、これにより処理が大幅に遅くなり (WebDriver インスタンスを毎回ゼロから起動する必要があるため)、WebDriver プロセスがキルされずにぶら下がったままになります。テストの失敗。理想的には、キューのどこかでエラーが発生するとキューの最後までスキップし、テスト フレームワークがキャッチするエラーをスローするSodaが提供する構造のようなものが欲しいです。