Subscribing to network and console logs

This part of user documentation is describing an obsolete version 2.5.2 (or older) of Suitest JavaScript API and is meant only for users who have not yet switched to the version 3. If you are new to Suitest JavaScript API, please use the version 3 instead.

You can listen to network traffic and console output of the device during a test run by subscribing to the corresponding events with the Suitest JS API.

Network and console logs availability varies depending on the device platform. You can check if logs are available for your device on the network requests page and Suitest console section.


Subscribing to network logs

The main suitest object of the JS API implements EventEmitter interface, so you can subscribe for network log events like so:

const suitest = require('suitest-js-api');

// Listen to every network log
suitest.on('networkLog', function handler(data) {
    // Process the data somehow..
    console.log(data);
});

// Unsubscribe from network logs
suitest.off('networkLog', handler);

// Subscribe to a single network log entry and unsubscribe automatically
suitest.once('networkLog', data => {
    // Process the data somehow..
    console.log(data);
});

Suitest would emit two events for every network request - one for request and another one for response section.

The handler would receive a single argument with a network log entry details. You can review the format of such entry in our GitHub repository.

Subscribing to Console logs

You can subscribe to console logs similarly:

const suitest = require('suitest-js-api');

// Listen to every console log
suitest.on('consoleLog', function handler(data) {
    // Process the data somehow..
    console.log(data);
});

// Unsubscribe from console logs
suitest.off('consoleLog', handler);

// Subscribe to a single console log entry and unsubscribe automatically
suitest.once('consoleLog', data => {
    // Process the data somehow..
    console.log(data);
});

The format of the payload is described in this TypeScript definition in our GitHub repository.