Sto testando un'applicazione Web utilizzando Mocha e WebDriverJS, più o meno come indicato here. Quando i test passano, tutto va bene. Tuttavia, se un test fallisce, il resto dei test nella suite scadrà e il corridore uscirà alla fine della suite, senza chiudere l'istanza di Webdriver. Esempio test case:Node.js + mocha + webdriverjs: Test fallito kill suite
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();
});
});
});
uscita:
~> 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)
Per quanto posso dire, questo è perché la coda WebDriverJS viene bloccato quando un test fallisce. C'è un modo per risolvere questo problema? Non ottimale anche per il test della riga di comando locale e rende i test in esecuzione automatica e/o in background difficili da eseguire.
Aggiornamento: credo di poter risolvere il guasto coda di istanziando un nuovo client per ogni test, ma questo renderebbe le cose molto più lenti (come istanza WebDriver avrebbe bisogno di iniziare da zero ogni volta) e lascerebbe I processi di WebDriver restano impunturati in caso di fallimento del test. Idealmente, mi piacerebbe qualcosa di simile alla struttura offerta da Soda, in cui un errore da qualche parte nella coda salta alla fine della coda e poi genera l'errore per il framework di test da catturare.
L'unica differenza con questo approccio è che il test si blocca dopo il primo test, il timeout su "afterEach" e il secondo test non viene mai eseguito. Il problema è lo stesso. – nrabinowitz
Cosa succede quando non usi 'after()' e invece aggiungi semplicemente '.end() 'chiama all'oggetto' client' in ogni test? Essenzialmente sei incappato in un inferno asincrono tra le due API, ma dovrebbe essere risolvibile con alcune modifiche minori. – srquinn
Vorrei poterti aiutare di più, ma senza accesso al server Selenium non riesco a eseguire test. – srquinn