From 4058d2f32acd2d8267de1ef98e63732ac9302635 Mon Sep 17 00:00:00 2001 From: Ritwik G Date: Fri, 31 Jan 2025 20:41:20 +0530 Subject: [PATCH] Added explicit wait --- tests/e2e/test_login.py | 54 +++++++++++++++++++++++++++++++---------- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/tests/e2e/test_login.py b/tests/e2e/test_login.py index 925331bb1..2fc1c02d4 100644 --- a/tests/e2e/test_login.py +++ b/tests/e2e/test_login.py @@ -2,12 +2,17 @@ from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait +from selenium.webdriver.support import expected_conditions as EC class TestLogin: def setup_method(self, method): options = Options() options.add_argument("--headless=new") + options.add_argument("--disable-gpu") + options.add_argument("--window-size=1920,1080") + options.add_argument("--disable-dev-shm-usage") + options.add_argument("--no-sandbox") self.driver = webdriver.Chrome(options=options) def teardown_method(self, method): @@ -23,24 +28,47 @@ def _check_page_load(self): return True def test_login(self): + # Wait for the page to load WebDriverWait(self.driver, timeout=30, poll_frequency=2).until( lambda _: self._check_page_load(), "Page load failed", ) - self.driver.implicitly_wait(0.5) + + # Set the window size self.driver.set_window_size(960, 615) - # 3 | click | css=span | - self.driver.find_element(By.CSS_SELECTOR, "button").click() - # 4 | click | id=username | - self.driver.find_element(By.ID, "username").click() - # 5 | type | id=username | unstract - self.driver.find_element(By.ID, "username").send_keys("unstract") - # 6 | type | id=password | unstract - self.driver.find_element(By.ID, "password").send_keys("unstract") - # 7 | click | css=input:nth-child(11) | - self.driver.find_element(By.CSS_SELECTOR, "input:nth-child(11)").click() - WebDriverWait(self.driver, timeout=5).until( + + # Explicit wait for the button to be clickable + WebDriverWait(self.driver, timeout=10).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, "button")), + "Button not clickable.", + ).click() + + # Explicit wait for the username field to be visible + username_field = WebDriverWait(self.driver, timeout=10).until( + EC.visibility_of_element_located((By.ID, "username")), + "Username field not visible.", + ) + username_field.click() + username_field.send_keys("unstract") + + # Explicit wait for the password field to be visible + password_field = WebDriverWait(self.driver, timeout=10).until( + EC.visibility_of_element_located((By.ID, "password")), + "Password field not visible.", + ) + password_field.send_keys("unstract") + + # Explicit wait for the login button to be clickable + WebDriverWait(self.driver, timeout=10).until( + EC.element_to_be_clickable((By.CSS_SELECTOR, "input:nth-child(11)")), + "Login button not clickable.", + ).click() + + # Wait for the URL to change to indicate successful login + WebDriverWait(self.driver, timeout=10).until( lambda _: self.driver.current_url.endswith("/mock_org/onboard"), - "Login failed.", + "Login failed or URL did not change.", ) + + # Close the browser self.driver.close()