I have the most bizarre problem with my Selenium test. I have the following classes:
class DataStorageTestSuiteChrome(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome(executable_path="chrome_driver_path")
self.driver.maximize_window()
self.driver.get("www.data_storage_website.com")
self.page = DataStoragePage(self.driver)
def tearDown(self):
self.driver.quit()
def test_sn_validation(self):
self.page.sn_element = 20001234567 # This line takes 2.5min to execute in Linux
self.assertFalse(self.page.is_valid_sn())
self.page.sn_element = self.ID_GENERATOR.sn
self.assertTrue(self.page.is_valid_sn())
class DataStoragePage:
'''Page Object for DataStorage page'''
sn_element = SnElement()
def __init__(self, driver):
self.driver = driver
class SnElement:
'''This class gets the search text from the specified locator'''
locator = "some_working_locator"
def __set__(self, obj, value):
"""Sets the text to the value supplied"""
driver = obj.driver
WebDriverWait(driver, 100).until(
lambda driver: driver.find_element(By.XPATH, self.locator))
driver.find_element(By.XPATH, self.locator).clear()
driver.find_element(By.XPATH, self.locator).send_keys(value) # This line takes 2.5min to execute in Linux
Now, the problem is that test case "test_sn_validation" takes a seconds to execute in Windows (both with headless mode on&off), and it takes 2.5 minutes in WSL2 Ubuntu. This is obviously quite perplexing to me, as I expected tests like that to run a lot faster on Linux.
I have tracked the reason for the slow behaviour down to driver.find_element(By.XPATH, self.locator).send_keys(value)
in SnElement class, due to send_keys() method. Moreover, that delay occurs only on the first run of send_keys() - every subsequent execution I ran via PDB was instantenous.
Has anyone seen a similar behaviour in WSL2 for send_keys(), and can recommend a solution?