Subscribing to network and console logs

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