diff --git a/packages/wdio-cli/src/constants.ts b/packages/wdio-cli/src/constants.ts index 773bf1879fb..2a37997ebde 100644 --- a/packages/wdio-cli/src/constants.ts +++ b/packages/wdio-cli/src/constants.ts @@ -902,6 +902,13 @@ export const TESTRUNNER_DEFAULTS: Options.Definition = { type: 'boolean', default: true }, + /** + * whether or not print the log output grouped by test files + */ + groupLogsByTestSpec: { + type: 'boolean', + default: false + }, /** * list of strings to watch of `wdio` command is called with `--watch` flag */ @@ -952,3 +959,8 @@ export const TESTRUNNER_DEFAULTS: Options.Definition = { beforeAssertion: HOOK_DEFINITION, afterAssertion: HOOK_DEFINITION } + +export const WORKER_GROUPLOGS_MESSAGES = { + normalExit: (cid: string) => `\n***** List of steps of WorkerID=[${cid}] *****`, + exitWithError: (cid: string) => `\n***** List of steps of WorkerID=[${cid}] that preceded the error above *****` +} diff --git a/packages/wdio-cli/src/launcher.ts b/packages/wdio-cli/src/launcher.ts index 32915026c8e..98be6618896 100644 --- a/packages/wdio-cli/src/launcher.ts +++ b/packages/wdio-cli/src/launcher.ts @@ -11,7 +11,7 @@ import type { Options, Capabilities, Services } from '@wdio/types' import CLInterface from './interface.js' import { runLauncherHook, runOnCompleteHook, runServiceHook } from './utils.js' -import { TESTRUNNER_DEFAULTS } from './constants.js' +import { TESTRUNNER_DEFAULTS, WORKER_GROUPLOGS_MESSAGES } from './constants.js' import type { HookError } from './utils.js' import type { RunCommandArguments } from './types.js' @@ -470,6 +470,19 @@ class Launcher { }) worker.on('message', this.interface.onMessage.bind(this.interface)) worker.on('error', this.interface.onMessage.bind(this.interface)) + worker.on('exit', (code) => { + if (!this.configParser.getConfig().groupLogsByTestSpec) { + return + } + if (code.exitCode === 0) { + console.log(WORKER_GROUPLOGS_MESSAGES.normalExit(code.cid)) + } else { + console.log(WORKER_GROUPLOGS_MESSAGES.exitWithError(code.cid)) + } + worker.logsAggregator.forEach((logLine) => { + console.log(logLine.replace(new RegExp('\\n$'), '')) + }) + }) worker.on('exit', this._endHandler.bind(this)) } diff --git a/packages/wdio-config/src/constants.ts b/packages/wdio-config/src/constants.ts index 50709ee757e..228aa73b9d3 100644 --- a/packages/wdio-config/src/constants.ts +++ b/packages/wdio-config/src/constants.ts @@ -10,6 +10,7 @@ export const DEFAULT_CONFIGS: () => Omit = ( outputDir: undefined, logLevel: 'info' as const, logLevels: {}, + groupLogsByTestSpec: false, excludeDriverLogs: [], bail: 0, waitforInterval: 500, diff --git a/packages/wdio-local-runner/src/transformStream.ts b/packages/wdio-local-runner/src/transformStream.ts index ddbd26ee545..2799b6d258b 100644 --- a/packages/wdio-local-runner/src/transformStream.ts +++ b/packages/wdio-local-runner/src/transformStream.ts @@ -3,11 +3,15 @@ import type { Readable, TransformCallback } from 'node:stream' import { Transform } from 'node:stream' import { DEBUGGER_MESSAGES } from './constants.js' -export default function runnerTransformStream(cid: string, inputStream: Readable): Readable { +export default function runnerTransformStream(cid: string, inputStream: Readable, aggregator?: string[]): Readable { return inputStream .pipe(split(/\r?\n/, line => `${line}\n`)) .pipe(ignore(DEBUGGER_MESSAGES)) - .pipe(map(line => `[${cid}] ${line}`)) + .pipe(map((line) => { + const newLine = `[${cid}] ${line}` + aggregator?.push(newLine) + return newLine + })) } function ignore(patternsToIgnore: string[]) { diff --git a/packages/wdio-local-runner/src/worker.ts b/packages/wdio-local-runner/src/worker.ts index 46df175aa0f..c902dac35cd 100644 --- a/packages/wdio-local-runner/src/worker.ts +++ b/packages/wdio-local-runner/src/worker.ts @@ -53,6 +53,7 @@ export default class WorkerInstance extends EventEmitter implements Workers.Work childProcess?: ChildProcess sessionId?: string server?: Record + logsAggregator: string[] = [] instances?: Record isMultiremote?: boolean @@ -149,7 +150,14 @@ export default class WorkerInstance extends EventEmitter implements Workers.Work /* istanbul ignore if */ if (!process.env.VITEST_WORKER_ID) { if (childProcess.stdout !== null) { - runnerTransformStream(cid, childProcess.stdout).pipe(stdOutStream) + if (this.config.groupLogsByTestSpec) { + // Test spec logs are collected only from child stdout stream + // and then printed when the worker exits + // As a result, there is no pipe to parent stdout stream here + runnerTransformStream(cid, childProcess.stdout, this.logsAggregator) + } else { + runnerTransformStream(cid, childProcess.stdout).pipe(stdOutStream) + } } if (childProcess.stderr !== null) { diff --git a/packages/wdio-types/src/Options.ts b/packages/wdio-types/src/Options.ts index db0d0ff1f0b..ddd4fbd2769 100644 --- a/packages/wdio-types/src/Options.ts +++ b/packages/wdio-types/src/Options.ts @@ -415,6 +415,16 @@ export interface Testrunner extends Hooks, Omit, We * Whether or not retried spec files should be retried immediately or deferred to the end of the queue */ specFileRetriesDeferred?: boolean + /** + * Choose the log output view. + * If set to "false" logs from different test files will be printed in real-time. + * Please note that this may result in the mixing of log outputs from different Test Specs when running in parallel. + * If set to "true" log outputs will be grouped by test files and printed only when the test is completed. + * By default, it is set to "false" so logs are printed in real-time. + * + * @default false + */ + groupLogsByTestSpec?: boolean, /** * Services take over a specific job you don't want to take care of. They enhance * your test setup with almost no effort. diff --git a/packages/wdio-types/src/Services.ts b/packages/wdio-types/src/Services.ts index c4b7b51cf9e..a2aac019cf6 100644 --- a/packages/wdio-types/src/Services.ts +++ b/packages/wdio-types/src/Services.ts @@ -1,13 +1,14 @@ import type { DesiredCapabilities, RemoteCapability, RemoteCapabilities } from './Capabilities.js' import type { Testrunner as TestrunnerOptions, WebdriverIO as WebdriverIOOptions } from './Options.js' import type { Suite, Test, TestResult } from './Frameworks.js' +import type { Worker } from './Workers.js' export interface RunnerInstance { initialize(): Promise shutdown(): Promise closeSession?: (cid: number) => Promise getWorkerCount(): number - run(args: any): NodeJS.EventEmitter + run(args: any): Worker workerPool: any browserPool: any } diff --git a/packages/wdio-types/src/Workers.ts b/packages/wdio-types/src/Workers.ts index 9462dca2891..5a803e2106d 100644 --- a/packages/wdio-types/src/Workers.ts +++ b/packages/wdio-types/src/Workers.ts @@ -51,6 +51,7 @@ export interface Worker postMessage: (command: string, args: WorkerMessageArgs) => void; specs: string[]; sessionId?: string; + logsAggregator: string[] } export type WorkerPool = Record; diff --git a/website/docs/Configuration.md b/website/docs/Configuration.md index 475f6b1dbec..72aa81d2466 100644 --- a/website/docs/Configuration.md +++ b/website/docs/Configuration.md @@ -330,6 +330,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/ar/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/ar/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/ar/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/ar/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/bg/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/bg/docusaurus-plugin-content-docs/current/Configuration.md index 2f4727e97d0..774b86e8a47 100644 --- a/website/i18n/bg/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/bg/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/de/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/de/docusaurus-plugin-content-docs/current/Configuration.md index 853d6faf14c..097b9f07cc2 100644 --- a/website/i18n/de/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/de/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services WebdriverIO Services übernehmen eine bestimmte Aufgabe, um die Sie sich nicht kümmern möchten. Sie erweitern Ihren Testaufbau nahezu ohne Aufwand. diff --git a/website/i18n/es/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/es/docusaurus-plugin-content-docs/current/Configuration.md index 91d08073db1..0e224ff6c68 100644 --- a/website/i18n/es/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/es/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Los servicios se hacen cargo de un trabajo específico que no desea cuidar. Mejoran su configuración de prueba sin casi ningún esfuerzo. diff --git a/website/i18n/fa/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/fa/docusaurus-plugin-content-docs/current/Configuration.md index 0175c9616dd..6722895af21 100644 --- a/website/i18n/fa/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/fa/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services سرویس ها کار خاصی را به عهده می گیرند که شما نمی خواهید از آن مراقبت کنید. آنها تقریباً بدون هیچ تلاشی تنظیمات تست شما را بهبود می بخشند. diff --git a/website/i18n/fr/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/fr/docusaurus-plugin-content-docs/current/Configuration.md index d8f9be54225..c38a444d355 100644 --- a/website/i18n/fr/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/fr/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/hi/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/hi/docusaurus-plugin-content-docs/current/Configuration.md index 0ff9edc8782..64f0d293431 100644 --- a/website/i18n/hi/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/hi/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services सेवाएँ एक विशिष्ट कार्य लेती हैं जिसकी आप देखभाल नहीं करना चाहते हैं। वे लगभग बिना किसी प्रयास के आपके परीक्षण सेटअप को बढ़ाते हैं। diff --git a/website/i18n/it/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/it/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/it/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/it/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/ja/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/ja/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/ja/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/ja/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/pl/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/pl/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/pl/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/pl/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/ru/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/ru/docusaurus-plugin-content-docs/current/Configuration.md index fe6c6a52432..00e91cb159c 100644 --- a/website/i18n/ru/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/ru/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/ta/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/ta/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/ta/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/ta/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/uk/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/uk/docusaurus-plugin-content-docs/current/Configuration.md index 461f8bd07e5..4bf0fce1da8 100644 --- a/website/i18n/uk/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/uk/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort. diff --git a/website/i18n/zh/docusaurus-plugin-content-docs/current/Configuration.md b/website/i18n/zh/docusaurus-plugin-content-docs/current/Configuration.md index a90b52428c1..d390e271e14 100644 --- a/website/i18n/zh/docusaurus-plugin-content-docs/current/Configuration.md +++ b/website/i18n/zh/docusaurus-plugin-content-docs/current/Configuration.md @@ -289,6 +289,19 @@ Whether or not retried spec files should be retried immediately or deferred to t Type: `Boolean`
Default: `true` +### groupLogsByTestSpec + +Choose the log output view. + +If set to `false` logs from different test files will be printed in real-time. Please note that this may result in the mixing of log outputs from different files when running in parallel. + +If set to `true` log outputs will be grouped by Test Spec and printed only when the Test Spec is completed. + +By default, it is set to `false` so logs are printed in real-time. + +Type: `Boolean`
+Default: `false` + ### services Services take over a specific job you don't want to take care of. They enhance your test setup with almost no effort.