Skip to content

Commit

Permalink
Added explicit wait
Browse files Browse the repository at this point in the history
  • Loading branch information
ritwik-g committed Jan 31, 2025
1 parent 131a3ba commit 4058d2f
Showing 1 changed file with 41 additions and 13 deletions.
54 changes: 41 additions & 13 deletions tests/e2e/test_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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()

0 comments on commit 4058d2f

Please sign in to comment.