forked from DevExpress/testcafe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the capability to get browser console messages (closes DevExpress…
…#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.
- Loading branch information
1 parent
c337d2f
commit e0a69c9
Showing
16 changed files
with
297 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// ------------------------------------------------------------- | ||
// WARNING: this file is used by both the client and the server. | ||
// Do not use any browser or node-specific API! | ||
// ------------------------------------------------------------- | ||
import { assignIn } from 'lodash'; | ||
import Assignable from '../utils/assignable'; | ||
|
||
|
||
export default class BrowserConsoleMessages extends Assignable { | ||
constructor (obj) { | ||
super(); | ||
|
||
this.log = []; | ||
this.info = []; | ||
this.warn = []; | ||
this.error = []; | ||
|
||
this._assignFrom(obj); | ||
} | ||
|
||
_getAssignableProperties () { | ||
return [ | ||
{ name: 'log' }, | ||
{ name: 'info' }, | ||
{ name: 'warn' }, | ||
{ name: 'error' } | ||
]; | ||
} | ||
|
||
concat (consoleMessages) { | ||
this.log = this.log.concat(consoleMessages.log); | ||
this.info = this.info.concat(consoleMessages.info); | ||
this.warn = this.warn.concat(consoleMessages.warn); | ||
this.error = this.error.concat(consoleMessages.error); | ||
} | ||
|
||
addMessage (type, msg) { | ||
this[type].push(msg); | ||
} | ||
|
||
getCopy () { | ||
const { log, info, warn, error } = this; | ||
|
||
return assignIn({}, { log, info, warn, error }); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
test/functional/fixtures/api/es-next/console/pages/empty.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Console messages (empty page)</title> | ||
</head> | ||
<body> | ||
</body> | ||
</html> |
27 changes: 27 additions & 0 deletions
27
test/functional/fixtures/api/es-next/console/pages/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Console messages</title> | ||
</head> | ||
<body> | ||
<button id="trigger-messages">Trigger Messages</button> | ||
|
||
<a id="reload" href="./empty.html">Reload</a> | ||
|
||
<script> | ||
var counter = 1; | ||
|
||
function triggerMessages () { | ||
console.log('log' + counter); | ||
console.warn('warn' + counter); | ||
console.error('error' + counter); | ||
console.info('info' + counter); | ||
|
||
counter++; | ||
} | ||
|
||
triggerMessages(); | ||
document.querySelector('#trigger-messages').addEventListener('click', triggerMessages); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe('[API] t.getBrowserConsoleMessages()', function () { | ||
it('Should return messages from the console', function () { | ||
return runTests('./testcafe-fixtures/console-test.js', 't.getBrowserConsoleMessages'); | ||
}); | ||
|
||
it('Should format messages if several args were passed', function () { | ||
return runTests('./testcafe-fixtures/console-test.js', 'messages formatting'); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
test/functional/fixtures/api/es-next/console/testcafe-fixtures/console-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
fixture `getBrowserConsoleMessages`; | ||
|
||
|
||
test | ||
.page `http://localhost:3000/fixtures/api/es-next/console/pages/index.html` | ||
('t.getBrowserConsoleMessages', async t => { | ||
let messages = await t.getBrowserConsoleMessages(); | ||
|
||
await t | ||
.expect(messages.error).eql(['error1']) | ||
.expect(messages.warn).eql(['warn1']) | ||
.expect(messages.log).eql(['log1']) | ||
.expect(messages.info).eql(['info1']) | ||
|
||
.click('#trigger-messages') | ||
|
||
// Check the driver keeps the messages between page reloads | ||
.click('#reload'); | ||
|
||
// Changes in the getBrowserConsoleMessages result object should | ||
// not affect the console messages state in the test run. | ||
messages.log.push('unexpected'); | ||
|
||
messages = await t.getBrowserConsoleMessages(); | ||
|
||
await t | ||
.expect(messages.error).eql(['error1', 'error2']) | ||
.expect(messages.warn).eql(['warn1', 'warn2']) | ||
.expect(messages.log).eql(['log1', 'log2']) | ||
.expect(messages.info).eql(['info1', 'info2']); | ||
}); | ||
|
||
test | ||
.page `http://localhost:3000/fixtures/api/es-next/console/pages/empty.html` | ||
('messages formatting', async t => { | ||
/* eslint-disable no-console */ | ||
await t.eval(() => console.log('a', 1, null, void 0, ['b', 2], { c: 3 })); | ||
/* eslint-enable no-console */ | ||
|
||
const { log } = await t.getBrowserConsoleMessages(); | ||
|
||
await t.expect(log[0]).eql('a 1 null undefined b,2 [object Object]'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.