Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

fix(tests): attach the BiDi trace of each browser to a failed test

damenchobc9728f421f1
diff --git a/tests/wdio.conf.ts b/tests/wdio.conf.ts
index a88e94de6c..6212e5098c 100644
--- a/tests/wdio.conf.ts
+++ b/tests/wdio.conf.ts
@@ -237,6 +237,51 @@ function completionSentinelPath(cid: string): string {
return path.join(TEST_RESULTS_DIR, `completed-${cid}.json`);
}
+/**
+ * How many WebDriver BiDi commands and results to keep per browser instance for the failure report.
+ */
+const BIDI_TRACE_SIZE = 2000;
+
+/**
+ * How much of each traced BiDi command or result to keep. Script calls carry the whole wrapped function
+ * source, which is noise here; the method, target context and result are what matter.
+ */
+const BIDI_TRACE_LINE_LENGTH = 800;
+
+/**
+ * The last BiDi commands and results of each browser instance, attached to the report when a test fails.
+ *
+ * The classic WebDriver commands are already in the report (wdio logs them into the junit output), but the
+ * BiDi ones are not: the webdriver logger writes them to the worker log, which only ever receives
+ * launcher-level lines (see completionSentinelPath). Script calls and frame switches go over BiDi, and a
+ * failure like a frame switch landing on a browsing context that never answers cannot be understood
+ * without seeing which context ids were requested and what the browser reported.
+ */
+const bidiTraces = new Map<string, string[]>();
+
+/**
+ * Starts recording the BiDi traffic of a browser instance into its ring buffer.
+ *
+ * @param instance - The multiremote instance name.
+ * @param browser - The browser instance.
+ */
+function traceBidi(instance: string, browser: WebdriverIO.Browser) {
+ const trace: string[] = [];
+ const record = (direction: string, payload: unknown) => {
+ trace.push(`${new Date().toISOString()} ${direction} ${
+ JSON.stringify(payload).slice(0, BIDI_TRACE_LINE_LENGTH)}`);
+
+ if (trace.length > BIDI_TRACE_SIZE) {
+ trace.splice(0, trace.length - BIDI_TRACE_SIZE);
+ }
+ };
+
+ bidiTraces.set(instance, trace);
+
+ browser.on('bidiCommand', (command: unknown) => record('>>', command));
+ browser.on('bidiResult', (result: unknown) => record('<<', result));
+}
+
/**
* Reads a worker's completion sentinel, if it wrote one.
*
@@ -436,6 +481,10 @@ export const config: WebdriverIO.MultiremoteConfig = {
return `${instance}:${browserName}/${browserVersion}`;
}).join(' ')}`);
+ multiRemoteBrowser.instances.forEach((instance: string) => {
+ traceBidi(instance, multiRemoteBrowser.getInstance(instance));
+ });
+
const globalAny: any = global;
globalAny.ctx = {
@@ -737,6 +786,15 @@ export const config: WebdriverIO.MultiremoteConfig = {
content: pretty(source),
type: 'text/plain' });
}));
+
+ const bidiTrace = bidiTraces.get(instance);
+
+ if (bidiTrace?.length) {
+ attachments.push({
+ filename: `${instance}-bidi-trace`,
+ content: bidiTrace.join('\n'),
+ type: 'text/plain' });
+ }
});
await Promise.allSettled(allProcessing);