t.getBrowserConsoleMessages Method

Returns messages posted to the browser console. Cannot be chained with other methods of the test controller.

t.getBrowserConsoleMessages() → Promise<Object>

This method returns an object that contains the following fields.

Field Type Description
error Array of String Error messages printed in the console.
warn Array of String Warning messages printed in the console.
log Array of String Log messages printed in the console.
info Array of String Information messages printed in the console.

Note that this method returns only messages posted via the console.error, console.warn, console.log and console.info methods. Messages output by the browser (like when an unhandled exception occurs on the page) will not be returned.

Example

// check-console-messages.js
import { t } from 'testcafe';

export default async function () {
    const { error, log } = await t.getBrowserConsoleMessages();

    await t.expect(error[0]).notOk();
    await t.expect(log[0]).eql('Typed name is Name');
}
// test.js
import checkConsoleMessages from './check-console-messages';

fixture`TestController.getBrowserConsoleMessages`
    .page`./index.html`
    .afterEach(() => checkConsoleMessages());

test('Send name', async t => {
    await t
        .typeText('#name', 'Name')
        .click('#button');
});