2015-04-04 14 views
15

Come posso ottenere tutti i messaggi della console sul debug di nightwatch.js?Salva i messaggi della console per il debug in nightwatch.js

A phantom è possibile utilizzare il gestore page.onError. Posso fare lo stesso con Nightwatch?

So di window.onerror ma è possibile salvare tutti i messaggi della console?

Qualcuno può condividere configurazione/codice di lavoro?

risposta

12

Soluzione:

module.exports = { 
    'Check getting log messages' : function (client) { 
    client 
     .url('http://jsbin.com/rohilugegi/1/') 
     .getLogTypes(function(result) { 
     console.log(result); 
     }) 
     .getLog('browser', function(result) { 
     console.log(result); 
     }) 
    ; 

    return client; 
    }, 

Si darà uscita

[Start] Test Suite 
================== 

Running: Check getting log messages 
[ 'har', 'browser', 'client', 'server' ] 
[ { message: 'Test error\n error (:0)', 
    timestamp: 1428447687315, 
    level: 'WARNING' }, 
    { message: 'Test log (:)', 
    timestamp: 1428447687315, 
    level: 'INFO' } ] 
No assertions ran. 

Comandi getLogTypes e getLog già realizzate in client commands ma la loro descrizione sono assenti nel sito API

sembra che vale la pena leggere il codice sorgente, invece di documentazione

Sotto jsdoc per queste funzioni dal codice sorgente:

/** 
* Gets the available log types 
* 
* ``` 
* this.demoTest = function(client) { 
* this.getLogTypes(function(typesArray) { 
*  
* }); 
* }; 
* ``` 
* 
* @method getLogTypes 
* @param {function} [callback] Optional callback function to be called when the command finishes. 
* @api commands 
* @see logTypes 
*/ 

e

/** 
* Gets a log from selenium 
* 
* ``` 
* this.demoTest = function(client) { 
* this.getLog('browser', function(logEntriesArray) { 
*  console.log("Log length: " + logEntriesArray.length); 
*  logEntriesArray.forEach(function(log) { 
*  console.log("[" + log.level + "] " + log.timestamp + " : " + log.message); 
*  }); 
* }); 
* }; 
* ``` 
* 
* @method getLog 
* @param {string} typeString Log type to request 
* @param {function} [callback] Optional callback function to be called when the command finishes. 
* @api commands 
* @see log 
*/ 
+0

Ricevo un registro vuoto utilizzando questa tecnica con Chrome. Quale browser stai usando? Hai qualche suggerimento? –

+0

Io uso chrome e phantom. Hai controllato la console manualmente? –

+0

Questo cestino è stato creato in modo anonimo e il suo tempo di anteprima gratuito è scaduto - basta crearne un altro per il test –

Problemi correlati