From 2f75b6aa750dafd8a88bc7efae8e8f13955492fc Mon Sep 17 00:00:00 2001 From: ravinque <74673799+ravinque@users.noreply.github.com> Date: Tue, 11 Mar 2025 23:46:22 +0800 Subject: [PATCH 1/4] WAT-4497 Kill chromedriver process when test case ends --- .../src/plugin/index.ts | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/plugin-selenium-driver/src/plugin/index.ts b/packages/plugin-selenium-driver/src/plugin/index.ts index 14f91415e..fabd28938 100644 --- a/packages/plugin-selenium-driver/src/plugin/index.ts +++ b/packages/plugin-selenium-driver/src/plugin/index.ts @@ -5,7 +5,7 @@ import { WindowFeaturesConfig, } from '@testring/types'; -import {ChildProcess} from 'child_process'; +import {ChildProcess, exec} from 'child_process'; import {remote} from 'webdriverio'; import * as deepmerge from 'deepmerge'; @@ -475,6 +475,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin { `Selenium did not exit in time. Sending SIGKILL.`, ); this.localSelenium.kill('SIGKILL'); + this.killProcess(); } resolve(); }, 3000); @@ -491,6 +492,38 @@ export class SeleniumPlugin implements IBrowserProxyPlugin { } } + public async killProcess() { + const command = "ps aux | grep '[c]hromedriver' | awk '{print $2}'"; + exec(command, (error, stdout, stderr) => { + if (error) { + this.logger.error(`Error executing command: ${error.message}`); + return; + } + if (stderr) { + this.logger.error(`Error output: ${stderr}`); + return; + } + const pids = stdout.trim().split('\n').filter((pid) => pid); + if (pids.length === 0) { + this.logger.debug('No ChromeDriver processes found.'); + } else { + this.logger.debug(`Killing ChromeDriver processes with PIDs: ${pids.join(', ')}`); + const killCommand = `kill -9 ${pids.join(' ')}`; + exec(killCommand, (killError, killStdout, killStderr) => { + if (killError) { + this.logger.error(`Error killing processes: ${killError.message}`); + return; + } + if (killStderr) { + this.logger.error(`Error output while killing: ${killStderr}`); + return; + } + this.logger.debug('Successfully killed ChromeDriver processes.'); + }); + } + }); + } + public async refresh(applicant: string) { await this.createClient(applicant); const client = this.getBrowserClient(applicant); From 86901f973560f4a56dfbffed59b9c8dd5a05b90d Mon Sep 17 00:00:00 2001 From: ravinque <74673799+ravinque@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:27:22 +0800 Subject: [PATCH 2/4] WAT-4497 Kill chromedriver when test case ends --- .../src/plugin/index.ts | 44 ++++++------------- 1 file changed, 13 insertions(+), 31 deletions(-) diff --git a/packages/plugin-selenium-driver/src/plugin/index.ts b/packages/plugin-selenium-driver/src/plugin/index.ts index fabd28938..890ba38ef 100644 --- a/packages/plugin-selenium-driver/src/plugin/index.ts +++ b/packages/plugin-selenium-driver/src/plugin/index.ts @@ -475,7 +475,6 @@ export class SeleniumPlugin implements IBrowserProxyPlugin { `Selenium did not exit in time. Sending SIGKILL.`, ); this.localSelenium.kill('SIGKILL'); - this.killProcess(); } resolve(); }, 3000); @@ -486,42 +485,25 @@ export class SeleniumPlugin implements IBrowserProxyPlugin { this.localSelenium.removeAllListeners(); + this.killProcess(); + this.logger.debug( 'Selenium process and all associated pipes closed.', ); } } - public async killProcess() { - const command = "ps aux | grep '[c]hromedriver' | awk '{print $2}'"; - exec(command, (error, stdout, stderr) => { - if (error) { - this.logger.error(`Error executing command: ${error.message}`); - return; - } - if (stderr) { - this.logger.error(`Error output: ${stderr}`); - return; - } - const pids = stdout.trim().split('\n').filter((pid) => pid); - if (pids.length === 0) { - this.logger.debug('No ChromeDriver processes found.'); - } else { - this.logger.debug(`Killing ChromeDriver processes with PIDs: ${pids.join(', ')}`); - const killCommand = `kill -9 ${pids.join(' ')}`; - exec(killCommand, (killError, killStdout, killStderr) => { - if (killError) { - this.logger.error(`Error killing processes: ${killError.message}`); - return; - } - if (killStderr) { - this.logger.error(`Error output while killing: ${killStderr}`); - return; - } - this.logger.debug('Successfully killed ChromeDriver processes.'); - }); - } - }); + public killProcess() { + let result = execSync("ps aux | grep '[c]hromedriver' | awk '{print $2}'"); + let pids = result.toString().trim().split('\n').filter((pid) => pid).join(' '); + if (pids && pids.length > 0) { + this.logger.debug(`Killing ChromeDriver processes with PIDs: ${pids}...`); + result = execSync(`kill -9 ${pids}`); + this.logger.debug(`Killed ChromeDriver processes with PIDs: ${pids}.`); + } else { + this.logger.debug('No ChromeDriver processes found.'); + } + return result; } public async refresh(applicant: string) { From fe8d9cde32d256fb1524b0208ca566c68495a39c Mon Sep 17 00:00:00 2001 From: ravinque <74673799+ravinque@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:29:01 +0800 Subject: [PATCH 3/4] WAT-4497 Kill chromedriver when test case ends --- packages/plugin-selenium-driver/src/plugin/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-selenium-driver/src/plugin/index.ts b/packages/plugin-selenium-driver/src/plugin/index.ts index 890ba38ef..9abd5040d 100644 --- a/packages/plugin-selenium-driver/src/plugin/index.ts +++ b/packages/plugin-selenium-driver/src/plugin/index.ts @@ -5,7 +5,7 @@ import { WindowFeaturesConfig, } from '@testring/types'; -import {ChildProcess, exec} from 'child_process'; +import {ChildProcess, execSync} from 'child_process'; import {remote} from 'webdriverio'; import * as deepmerge from 'deepmerge'; From c97d374f52fc0cf369662fc3d47fb55a78313e43 Mon Sep 17 00:00:00 2001 From: ravinque <74673799+ravinque@users.noreply.github.com> Date: Wed, 12 Mar 2025 16:39:59 +0800 Subject: [PATCH 4/4] WAT-4497 Kill chromedriver when test case ends --- packages/plugin-selenium-driver/src/plugin/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/plugin-selenium-driver/src/plugin/index.ts b/packages/plugin-selenium-driver/src/plugin/index.ts index 9abd5040d..097494891 100644 --- a/packages/plugin-selenium-driver/src/plugin/index.ts +++ b/packages/plugin-selenium-driver/src/plugin/index.ts @@ -495,7 +495,7 @@ export class SeleniumPlugin implements IBrowserProxyPlugin { public killProcess() { let result = execSync("ps aux | grep '[c]hromedriver' | awk '{print $2}'"); - let pids = result.toString().trim().split('\n').filter((pid) => pid).join(' '); + const pids = result.toString().trim().split('\n').filter((pid) => pid).join(' '); if (pids && pids.length > 0) { this.logger.debug(`Killing ChromeDriver processes with PIDs: ${pids}...`); result = execSync(`kill -9 ${pids}`);