Merge pull request #15903 from BrentBaccala/testsuite-console-log
Testsuite console log
This commit is contained in:
commit
a2d6a45782
@ -49,3 +49,18 @@ You can also use this also through the test tree, adding the test suite / group
|
||||
```bash
|
||||
$ npm run test:filter "notifications chat"
|
||||
```
|
||||
|
||||
You can print the browser console log to standard output by setting the environment variable `CONSOLE`:
|
||||
```
|
||||
$ CONSOLE= npm test chat -- --project=firefox
|
||||
```
|
||||
|
||||
`CONSOLE` can be blank (as in the example), or can be a comma-separated list of the following options:
|
||||
|
||||
| Option | Meaning |
|
||||
| ------ | ------- |
|
||||
| color | (or "colour") colorize the output |
|
||||
| label | label each line with the BigBlueButton user |
|
||||
| norefs | remove JavaScript reference URLs |
|
||||
| nots | remove timestamps |
|
||||
| nocl | remove "clientLogger:" strings |
|
||||
|
@ -1,13 +1,86 @@
|
||||
require('dotenv').config();
|
||||
const { expect, default: test } = require('@playwright/test');
|
||||
const { readFileSync } = require('fs');
|
||||
const { format } = require('node:util');
|
||||
|
||||
// This is version 4 of chalk, not version 5, which uses ESM
|
||||
const chalk = require('chalk');
|
||||
|
||||
const parameters = require('./parameters');
|
||||
const helpers = require('./helpers');
|
||||
const e = require('./elements');
|
||||
const { env } = require('node:process');
|
||||
const { ELEMENT_WAIT_TIME, ELEMENT_WAIT_LONGER_TIME, VIDEO_LOADING_WAIT_TIME } = require('./constants');
|
||||
const { checkElement, checkElementLengthEqualTo } = require('./util');
|
||||
const { generateSettingsData, getSettings } = require('./settings');
|
||||
|
||||
function formatWithCss(CONSOLE_options, ...args) {
|
||||
// For Chrome, args[0] is a format string that we will process using
|
||||
// node.js's util.format, but that function discards css style
|
||||
// information from "%c" format specifiers. So first loop over the
|
||||
// format string, replacing every "%c" with "%s" and replacing the
|
||||
// corresponding css style with an ANSI color sequence.
|
||||
//
|
||||
// See https://console.spec.whatwg.org/ sections 2.2.1 and 2.3.4
|
||||
|
||||
let split_arg0 = args[0].split("%");
|
||||
for (let i=1, j=1; i<split_arg0.length; i++, j++) {
|
||||
if (split_arg0[i].startsWith('c')) {
|
||||
split_arg0[i] = 's' + split_arg0[i].substr(1);
|
||||
const styles = args[j].split(';');
|
||||
args[j] = '';
|
||||
for (const style of styles) {
|
||||
const stdStyle = style.trim().toLowerCase();
|
||||
if (stdStyle.startsWith('color:') && CONSOLE_options.colorize) {
|
||||
const color = stdStyle.substr(6).trim();
|
||||
args[j] = chalk.keyword(color)._styler.open;
|
||||
} else if (stdStyle.startsWith('font-size:') && CONSOLE_options.drop_references) {
|
||||
// For Chrome, we "drop references" by discarding everything after a font size change
|
||||
split_arg0.length = i;
|
||||
args.length = j;
|
||||
}
|
||||
}
|
||||
} else if (split_arg0[i] == "") {
|
||||
// format is "%%", so don't do special processing for
|
||||
// split_arg0[i+1], and only increment i, not j
|
||||
i ++; // NOSONAR
|
||||
}
|
||||
}
|
||||
args[0] = split_arg0.join('%');
|
||||
return format(...args);
|
||||
}
|
||||
|
||||
async function console_format(msg, CONSOLE_options) {
|
||||
// see playwright consoleMessage class documentation
|
||||
const args = await Promise.all(msg.args().map(itm => itm.jsonValue()));
|
||||
let result = formatWithCss(CONSOLE_options, ...args);
|
||||
|
||||
if (CONSOLE_options.drop_references) {
|
||||
// For Firefox, we "drop references" by discarding a URL at the end of the line
|
||||
result = result.replace(/https:\/\/\S*$/, '');
|
||||
}
|
||||
|
||||
if (CONSOLE_options.noClientLogger) {
|
||||
result = result.replace(/clientLogger: /, '');
|
||||
}
|
||||
|
||||
if (CONSOLE_options.drop_timestamps) {
|
||||
// timestamp formatting is a bit complicated, with four "%s" fields and corresponding arguments,
|
||||
// so just filter them out (if requested) after all the other formatting is done
|
||||
result = result.replace(/\[\d\d:\d\d:\d\d:\d\d\d\d\] /, '');
|
||||
}
|
||||
|
||||
if (CONSOLE_options.line_label) {
|
||||
if (CONSOLE_options.colorize) {
|
||||
result = chalk.keyword('green')(CONSOLE_options.line_label) + result;
|
||||
} else {
|
||||
result = CONSOLE_options.line_label + result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
class Page {
|
||||
constructor(browser, page) {
|
||||
this.browser = browser;
|
||||
@ -31,6 +104,18 @@ class Page {
|
||||
if (fullName) this.initParameters.fullName = fullName;
|
||||
this.username = this.initParameters.fullName;
|
||||
|
||||
if (env.CONSOLE !== undefined) {
|
||||
const CONSOLE_strings = env.CONSOLE.split(',').map(opt => opt.trim().toLowerCase());
|
||||
const CONSOLE_options = {
|
||||
colorize: CONSOLE_strings.includes('color') || CONSOLE_strings.includes('colour'),
|
||||
drop_references: CONSOLE_strings.includes('norefs'),
|
||||
drop_timestamps: CONSOLE_strings.includes('nots'),
|
||||
line_label: CONSOLE_strings.includes('label') ? this.username + " " : undefined,
|
||||
noClientLogger: CONSOLE_strings.includes('nocl') || CONSOLE_strings.includes('noclientlogger'),
|
||||
};
|
||||
this.page.on('console', async (msg) => console.log(await console_format(msg, CONSOLE_options)));
|
||||
}
|
||||
|
||||
this.meetingId = (meetingId) ? meetingId : await helpers.createMeeting(parameters, customParameter);
|
||||
const joinUrl = helpers.getJoinURL(this.meetingId, this.initParameters, isModerator, customParameter);
|
||||
const response = await this.page.goto(joinUrl);
|
||||
|
108
bigbluebutton-tests/playwright/package-lock.json
generated
108
bigbluebutton-tests/playwright/package-lock.json
generated
@ -7,6 +7,7 @@
|
||||
"dependencies": {
|
||||
"@playwright/test": "^1.19.2",
|
||||
"axios": "^0.26.1",
|
||||
"chalk": "^4.1.2",
|
||||
"dotenv": "^16.0.0",
|
||||
"playwright": "^1.19.2",
|
||||
"sha1": "^1.1.1",
|
||||
@ -33,6 +34,20 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.40.tgz",
|
||||
"integrity": "sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg=="
|
||||
},
|
||||
"node_modules/ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"dependencies": {
|
||||
"color-convert": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/ansi-styles?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
@ -41,6 +56,21 @@
|
||||
"follow-redirects": "^1.14.8"
|
||||
}
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||
"dependencies": {
|
||||
"ansi-styles": "^4.1.0",
|
||||
"supports-color": "^7.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/chalk/chalk?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/charenc": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
|
||||
@ -49,6 +79,22 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"dependencies": {
|
||||
"color-name": "~1.1.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=7.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||
},
|
||||
"node_modules/crypt": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||
@ -84,6 +130,14 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/playwright": {
|
||||
"version": "1.22.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.22.2.tgz",
|
||||
@ -127,6 +181,17 @@
|
||||
"node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||
"dependencies": {
|
||||
"has-flag": "^4.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/xml2js": {
|
||||
"version": "0.4.23",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
|
||||
@ -163,6 +228,14 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.40.tgz",
|
||||
"integrity": "sha512-UXdBxNGqTMtm7hCwh9HtncFVLrXoqA3oJW30j6XWp5BH/wu3mVeaxo7cq5benFdBw34HB3XDT2TRPI7rXZ+mDg=="
|
||||
},
|
||||
"ansi-styles": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
|
||||
"integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
|
||||
"requires": {
|
||||
"color-convert": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.26.1",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.26.1.tgz",
|
||||
@ -171,11 +244,33 @@
|
||||
"follow-redirects": "^1.14.8"
|
||||
}
|
||||
},
|
||||
"chalk": {
|
||||
"version": "4.1.2",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
|
||||
"integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
|
||||
"requires": {
|
||||
"ansi-styles": "^4.1.0",
|
||||
"supports-color": "^7.1.0"
|
||||
}
|
||||
},
|
||||
"charenc": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/charenc/-/charenc-0.0.2.tgz",
|
||||
"integrity": "sha512-yrLQ/yVUFXkzg7EDQsPieE/53+0RlaWTs+wBrvW36cyilJ2SaDWfl4Yj7MtLTXleV9uEKefbAGUPv2/iWSooRA=="
|
||||
},
|
||||
"color-convert": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
|
||||
"integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
|
||||
"requires": {
|
||||
"color-name": "~1.1.4"
|
||||
}
|
||||
},
|
||||
"color-name": {
|
||||
"version": "1.1.4",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
|
||||
"integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA=="
|
||||
},
|
||||
"crypt": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/crypt/-/crypt-0.0.2.tgz",
|
||||
@ -191,6 +286,11 @@
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
|
||||
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA=="
|
||||
},
|
||||
"has-flag": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
|
||||
},
|
||||
"playwright": {
|
||||
"version": "1.22.2",
|
||||
"resolved": "https://registry.npmjs.org/playwright/-/playwright-1.22.2.tgz",
|
||||
@ -218,6 +318,14 @@
|
||||
"crypt": ">= 0.0.1"
|
||||
}
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
"integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
|
||||
"requires": {
|
||||
"has-flag": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"xml2js": {
|
||||
"version": "0.4.23",
|
||||
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",
|
||||
|
@ -10,6 +10,7 @@
|
||||
"dependencies": {
|
||||
"@playwright/test": "^1.19.2",
|
||||
"axios": "^0.26.1",
|
||||
"chalk": "^4.1.2",
|
||||
"dotenv": "^16.0.0",
|
||||
"playwright": "^1.19.2",
|
||||
"sha1": "^1.1.1",
|
||||
|
Loading…
Reference in New Issue
Block a user