Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save console messages for debugging in nightwatch.js

Tags:

How can I get all console messages on nightwatch.js debugging?

At phantom it's possible to use page.onError handler. Can I do the same with nightwatch?

I know about window.onerror but is there way to save all console messages?

Can anyone share working config / code ?

like image 499
Vasiliy Vanchuk Avatar asked Apr 04 '15 07:04

Vasiliy Vanchuk


People also ask

How do you run a single test on Nightwatch?

You can also execute a single test with the --test flag, e.g. Show activity on this post. just add it to your test case: module.

What does console log () do?

The console. log() is a function in JavaScript which is used to print any kind of variables defined before in it or to just print any message that needs to be displayed to the user.

What is Nightwatch API?

Nightwatch API is JavaScript (Node. js) programming interface for controlling Nightwatch. js which is an End-to-End (E2E) testing solution for browser based apps and websites. Nightwatch. js uses the powerful W3C WebDriver API to perform commands and assertions on DOM elements.


1 Answers

Solution:

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;   }, 

It will give output

[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. 

Commands getLogTypes and getLog are already implemented at client commands but their description are absent at site API

Looks like it worth read source code instead of documentation

Below jsdoc for this functions from source code :

/**  * 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  */ 

and

/**  * 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  */ 
like image 72
Vasiliy Vanchuk Avatar answered Oct 26 '22 02:10

Vasiliy Vanchuk