17825a7edae00c426167a3269f135ef1601f4c3b gperez2 Mon Sep 9 09:03:57 2024 -0700 Adding code to kill chromdriver processes that don't get closed, No RM diff --git src/utils/qa/qaTestScript.py src/utils/qa/qaTestScript.py index 0d75e02..a25f0b3 100755 --- src/utils/qa/qaTestScript.py +++ src/utils/qa/qaTestScript.py @@ -27,33 +27,44 @@ # Imports module from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.common.action_chains import ActionChains from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re, sys, argparse import getpass import os +import psutil user = getpass.getuser() +# List of process names to check +proc_names_to_check = ["chrome", "chromedriver", "google-chrome", "chrome_crashpad_handler"] +# Iterate over all running processes +for proc in psutil.process_iter(): + # Check if the process name matches any in the list + if proc.name() in proc_names_to_check: + # Check if the process belongs to the specified user + if proc.username() == user: + # Kill the process + proc.kill() #Make tmpdir for the cron try: os.makedirs("/hive/users/"+user+"/selenium/chrom113/cron/TMP", exist_ok=True) except OSError as e: print(f"Error creating directory: {e}") os.environ['TMPDIR'] = "/hive/users/"+user+"/selenium/chrom113/cron/TMP" def initialize_driver(headless): """Initiates which webdriver to run for headless mode or local mode""" options = Options() if headless: options.add_argument('--headless') options.add_argument('--no-sandbox') options.add_argument("--headless")