Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the capability to get browser console messages (closes #1738) #1818

Merged
merged 7 commits into from
Oct 9, 2017

Conversation

AlexanderMoskovkin
Copy link
Contributor

@AlexanderMoskovkin AlexanderMoskovkin commented Sep 26, 2017

Feature summary

API

const consoleMessages = await t.getBrowserConsoleMessages();

// returns arrays of messages in the browser console for...
// ...console.log()
const logs = consoleMessages.log;         // -> ['some log message 1', 'some log message 2']
// ...console.error()
const errors = consoleMessages.error;   // -> ['some error message'] 
// ...console.warn()
const warnings = consoleMessages.warn;   // -> ['some warning message'] 
// ...console.info()
const info = consoleMessages.info;   // -> ['some info message'] 

Some browsers can write messages to the console with a little bit different formatting. We just call toString() for arguments that were passed to the console methods (see an example in the test)

Real-World Use Case

Check your react application doesn't have prop type errors:

// check-prop-types.js
import { t } from 'testcafe';

export default async function () {
    const { error } = await t.getBrowserConsoleMessages();
        
    await t.expect(error[0]).notOk();
}

// test.js
import { Selector } from 'testcafe';
import checkPropTypes from './check-prop-types';

fixture `react example`
    .page `http://localhost:8080/`  // https://github.com/mzabriskie/react-example
    .afterEach(() => checkPropTypes());

test('test', async t => {
    await t
        .typeText(Selector('.form-control'), 'devexpress')
        .click(Selector('button').withText('Go'))
        .click(Selector('h4').withText('Organizations'));
});

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 568cb32 have failed. See details:

interface ConsoleMessagesCollection {
/**
* TODO:
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /**
     * Messages output to the browser console by the console.log() method.
     */

log: string[],
/**
* TODO:
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /**
     * Warning messages output to the browser console by the console.warn() method.
     */

/**
* TODO:
*/
error: string[],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /**
     * Error messages output to the browser console by the console.error() method.
     */

/**
* TODO:
*/
info: string[]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /**
     * Information messages output to the browser console by the console.info() method.
     */

@@ -1005,6 +1024,10 @@ interface TestController {
*/
getNativeDialogHistory(): Promise<NativeDialogHistoryItem[]>;
/**
* TODO: Returns a collection of browser console messages.
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

    /**
     * Returns an object that contains messages output to the browser console.
     *
     * This object exposes the following properties.
     *
     * -- `log` contains log messages written by the console.log() method
     * -- `error` contains error messages written by the console.error() method
     * -- `warn` contains warning messages written by the console.warn() method
     * -- `info` contains information messages written by the console.info() method
     */

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to list the return object's properties here? If not, just remove them.

@AlexanderMoskovkin AlexanderMoskovkin changed the title [WIP] Add the capability to get browser console messages (closes #1738) Add the capability to get browser console messages (closes #1738) Sep 27, 2017
@AlexanderMoskovkin
Copy link
Contributor Author

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit e70563e have failed. See details:

@@ -0,0 +1,39 @@
fixture `Double Click`;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's rename fixture

@@ -1,6 +1,6 @@
/// <reference path="../../../../../ts-defs/index.d.ts" />
import { Selector, ClientFunction } from 'testcafe';
import { expect } from 'chai';
import {Selector, ClientFunction} from 'testcafe';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrong formating

Copy link
Contributor

@AndreyBelym AndreyBelym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit 9889217 have failed. See details:

}

set consoleMessages (messages) {
return this.contextStorage.setItem(CONSOLE_MESSAGES, messages);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ehmm, we can run out of storage quite quickly with this approach

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thought about this.. Now the max size of the session storage in browsers is 5-10MB, so it looks not so crusial since we reset the session storage for each test run. But I agree, it would be better to keep the messages on the server.

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit 9889217 have passed. See details:

@testcafe-build-bot
Copy link
Collaborator

✅ Tests for the commit e970116 have passed. See details:

@AlexanderMoskovkin
Copy link
Contributor Author

FPR /cc @helen-dikareva @AndreyBelym @inikulin

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit c4358a6 have failed. See details:

Copy link
Contributor

@AndreyBelym AndreyBelym left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@testcafe-build-bot
Copy link
Collaborator

❌ Tests for the commit c4358a6 have failed. See details:

@AlexanderMoskovkin AlexanderMoskovkin merged commit 7dc8cd4 into DevExpress:master Oct 9, 2017
@markusguenther
Copy link

Thanks for that adjustment 👍

kirovboris pushed a commit to kirovboris/testcafe-phoenix that referenced this pull request Dec 18, 2019
…#1738) (DevExpress#1818)

* Add the capability to get browser console messages (closes DevExpress#1738)

* Rename to `getBrowserConsoleMessages`

* Address Helen's remarks

* Fix the test for node 4

* Store messages on the server

* Integrating with Roles. Refactoring.

* Fix tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants