b8e1ef1c46936830b5066f7917d1af149679a65a gperez2 Thu Mar 26 13:36:47 2026 -0700 Fixing Selenium timing crashes by replacing time.sleep() with WebDriverWait and fixing ActionChains reuse in cartReset, No RM diff --git src/utils/qa/qaTestScript.py src/utils/qa/qaTestScript.py index 57191b5e465..d33da8cff47 100755 --- src/utils/qa/qaTestScript.py +++ src/utils/qa/qaTestScript.py @@ -25,30 +25,31 @@ # os.environ['TMPDIR'] = "/hive/users/lrnassar/selenium/chrom113/TMP" # ^IGNORE # Imports module from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service 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 +from selenium.common.exceptions import StaleElementReferenceException import unittest, time, re, sys, argparse import getpass import os import psutil user = getpass.getuser() def kill_user_processes(proc_names_to_check): """ Kills processes with names in the specified list that belong to the user. Parameters: proc_names_to_check (list): A list of process names to check. """ # Iterate over all running processes @@ -101,41 +102,51 @@ # Parses the command-line arguments args = parser.parse_args() # Asks the user for the website URL if not provided as a command-line argument if not args.machine: args.machine = input("Enter the machine URL (Ex. https://hgwbeta.soe.ucsc.edu):") # Initializes the driver based on the chosen mode driver = initialize_driver(args.headless) # Loads the machine website machine= args.machine def cartReset(): """The function does a cart reset""" - a = ActionChains(driver) - #identify element - m = driver.find_element(By.LINK_TEXT, "Genome Browser") + #identify element, wait for page to load + m = WebDriverWait(driver, 10).until( + EC.presence_of_element_located((By.LINK_TEXT, "Genome Browser"))) #hover over element + a = ActionChains(driver) a.move_to_element(m).perform() - #identify sub menu element - n = driver.find_element(By.LINK_TEXT, "Reset All User Settings") - # hover over element and click - a.move_to_element(n).click().perform() + #identify sub menu element, wait for submenu to appear + n = WebDriverWait(driver, 10).until( + EC.visibility_of_element_located((By.LINK_TEXT, "Reset All User Settings"))) + # hover over element and click with fresh ActionChains + a2 = ActionChains(driver) + a2.move_to_element(n).click().perform() driver.implicitly_wait(2) +def wait_for_position_input(): + """Waits for the position input to be present and interactable after a page reload""" + time.sleep(1) # Let the page reload begin before searching for elements + return WebDriverWait(driver, 10, + ignored_exceptions=[StaleElementReferenceException]).until( + EC.element_to_be_clickable((By.NAME, "hgt.positionInput"))) + def hover_and_click(driver, main_id, submenu_id): """Function that hovers the blue bar menu and clicks a menu item""" action = ActionChains(driver) main = driver.find_element(By.ID, main_id) action.move_to_element(main).perform() WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, submenu_id))) action2 = ActionChains(driver) submenu = driver.find_element(By.ID, submenu_id) action2.move_to_element(submenu).click().perform() # Tests the Gateway page and home page driver.get(machine + "/cgi-bin/hgGateway") driver.get(machine + "/index.html") driver.find_element(By.LINK_TEXT, "Home").click() @@ -344,73 +355,62 @@ driver.find_element(By.NAME, "goButton").click() time.sleep(2) # Tests HGVS searches driver.get(machine + "/cgi-bin/cartReset") driver.get(machine + "/cgi-bin/hgTracks?db=hg38") driver.find_element(By.NAME, "hgt.positionInput").clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_000310.4(PPT1):c.271_287del17insTT") driver.find_element(By.ID, "goButton").click() time.sleep(2) driver.find_element(By.XPATH, "//td[@id='td_data_ncbiRefSeqSelect']/div[2]/map/area[7]").click() driver.get(machine + "/cgi-bin/hgTracks?db=hg38") driver.find_element(By.NAME, "hgt.positionInput").clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_007262.5(PARK7):c.-24+75_-24+92dup") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_006172.4(NPPA):c.456_*1delAA") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("MYH11:c.503-14_503-12del") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_198576.4(AGRN):c.1057C>T") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_198056.3:c.1654G>T") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NP_002993.1:p.Asp92Glu") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NP_002993.1:p.D92E") driver.find_element(By.ID, "goButton").click() -time.sleep(2) -driver.find_element(By.NAME, "hgt.positionInput").clear() +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("BRCA1 Ala744Cys") driver.find_element(By.ID, "goButton").click() time.sleep(2) driver.find_element(By.XPATH, "//td[@id='td_data_ncbiRefSeqCurated']/div[2]/map/area[3]").click() driver.get(machine + "/cgi-bin/hgTracks?db=hg38") -driver.find_element(By.NAME, "hgt.positionInput").clear() -time.sleep(3) +wait_for_position_input().clear() driver.find_element(By.NAME, "hgt.positionInput").send_keys("NM_000828.5:c.-2G>A") driver.find_element(By.ID, "goButton").click() -time.sleep(3) -driver.find_element(By.NAME, "hgt.positionInput").send_keys("chr18:g.55234435G>T") +wait_for_position_input().send_keys("chr18:g.55234435G>T") driver.find_element(By.ID, "goButton").click() -time.sleep(3) -driver.find_element(By.NAME, "hgt.positionInput").send_keys("LRG_321:g.16409_16461del") +wait_for_position_input().send_keys("LRG_321:g.16409_16461del") driver.find_element(By.ID, "goButton").click() -time.sleep(3) -driver.find_element(By.NAME, "hgt.positionInput").send_keys("chrX:g.31500000_31600000del") +wait_for_position_input().send_keys("chrX:g.31500000_31600000del") driver.find_element(By.ID, "goButton").click() time.sleep(3) # Tests hgBlat driver.get(machine + "/cgi-bin/cartReset") driver.get(machine + "/cgi-bin/hgGateway?db=hg19") hover_and_click(driver, "tools3", "blatMenuLink") driver.find_element(By.NAME, "userSeq").clear() driver.find_element(By.NAME, "userSeq").send_keys("AACAAAATCAAACTGTTTTTGTTGGACAATTCTCTGTTAAGCAGCTATAA\\nGCTGAATGACATTAACCGCAAAATGTAACCATAAAGGCCATAAACCCGAC\\nATTGTTAATTAATTAAATGCCTCATTAACTTTTTTAAAAACATGATTTAT\\nTCGATTCATAGAAAACTTAACCATCACTACTAAATGCACACACATGCGGT\\nTCCACATTGGCATCTTAGCCTAAGAACAGACAGGTTCAACTGTAACTGGC\\nCTTTCAGGTGGTCTATTACAGATCTGAAGACAGAGGGTGTTTCTAAACCT\\nCAAGAACCAGATTAACAGAAAACAAAGCTTGAGCAGCCTTTTTATTGCAT\\nGTGGTATCTTTTTAGCTAAGCAGAAGACAATGATAAAGAGGGGTTTTGGG\\nAAACCTCTCCCAAAGCTGTGCATTCATACCGTACCTTATCCTGTTAAGCA\\nAACTGTTCTTTTATTTTAAAGGGTTTACACTGCCACATCTGAATGGACTA") driver.find_element(By.NAME, "Submit").click() time.sleep(3) driver.find_element(By.LINK_TEXT, "browser").click() driver.find_element(By.XPATH, "//td[@id='td_data_ct_blatYourSeq_5589']/div[2]/map/area").click() #driver.find_element(By.XPATH, "//div[@id='firstSection']/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td[2]/div[2]/pre/a").click() #driver.find_element(By.XPATH, "//td[@id='td_data_hgUserPsl']/div[2]/map/area").click()