Skip to content

Commit f73d75c

Browse files
test: Refactor US04 test to improve result page navigation and visibility checks for current weighted average calculation
1 parent 2a97432 commit f73d75c

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

tests/us4.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ def _add_grade_and_percentage(self, grade, percentage):
181181
def _get_current_weighted_average(self):
182182
raw_text = ""
183183
try:
184-
# Ensure we are on the result page
185-
self.wait_long.until(EC.url_contains("/result"))
186-
self.wait_long.until(EC.presence_of_element_located((By.CSS_SELECTOR, self.RESULT_PAGE_CONTAINER_SELECTOR)))
184+
# The calling test method now ensures that we are on the result page
185+
# and the main result container is present.
186+
# This function will now directly wait for the specific average element to be visible.
187187

188188
average_element = self.wait_long.until(
189189
EC.visibility_of_element_located((By.CSS_SELECTOR, self.CURRENT_AVERAGE_DISPLAY_SELECTOR))
@@ -251,12 +251,13 @@ def test_us04_verify_calculation_of_current_weighted_average(self):
251251
logger.info(f"Before clicking 'Calcular'. Current URL: {self.driver.current_url}")
252252
calculate_button.click()
253253
logger.info(f"Immediately after attempting to click 'Calcular'. Current URL: {self.driver.current_url}")
254-
self._take_screenshot("after_calculate_click_attempt") # Screenshot right after click
255-
time.sleep(1) # Small pause to allow DOM changes/navigation to initiate
254+
self._take_screenshot("after_calculate_click_attempt_1")
255+
time.sleep(1)
256256

257-
logger.info(f"After 1s delay. Current URL: {self.driver.current_url}. Now waiting for URL to contain '/result'...")
258-
self.wait_long.until(EC.url_contains("/result")) # This is where the timeout occurs
259-
logger.info(f"Successfully navigated to {self.driver.current_url}. Checking for result container.")
257+
logger.info(f"After 1s delay. Current URL: {self.driver.current_url}. Now waiting for result page container '{self.RESULT_PAGE_CONTAINER_SELECTOR}'...")
258+
self.wait_long.until(EC.presence_of_element_located((By.CSS_SELECTOR, self.RESULT_PAGE_CONTAINER_SELECTOR)))
259+
logger.info(f"Result page container '{self.RESULT_PAGE_CONTAINER_SELECTOR}' is present. Current URL: {self.driver.current_url}. Verifying URL and then getting average.")
260+
self.assertIn("/result", self.driver.current_url, "URL should contain /result after result container is present for 1st calculation")
260261

261262
current_avg_1 = self._get_current_weighted_average()
262263
expected_avg_1 = 0.9 # (4.5 * 20) / 100 = 90 / 100 = 0.9
@@ -275,9 +276,12 @@ def test_us04_verify_calculation_of_current_weighted_average(self):
275276

276277
calculate_button = self.wait_long.until(EC.element_to_be_clickable((By.CSS_SELECTOR, self.CALCULATE_BUTTON_SELECTOR))) # Re-locate button
277278
calculate_button.click()
278-
logger.info("Clicked 'Calcular' button again.")
279-
self.wait_long.until(EC.url_contains("/result"))
280-
logger.info(f"Navigated to {self.driver.current_url}")
279+
logger.info("Clicked 'Calcular' button again for 2nd calculation.")
280+
self._take_screenshot("after_calculate_click_attempt_2")
281+
time.sleep(1)
282+
self.wait_long.until(EC.presence_of_element_located((By.CSS_SELECTOR, self.RESULT_PAGE_CONTAINER_SELECTOR)))
283+
logger.info(f"Result page container '{self.RESULT_PAGE_CONTAINER_SELECTOR}' is present after 2nd calc. Current URL: {self.driver.current_url}. Verifying URL.")
284+
self.assertIn("/result", self.driver.current_url, "URL should contain /result after 2nd calc and result container is present")
281285

282286
current_avg_2 = self._get_current_weighted_average()
283287
expected_avg_2 = 1.8 # (4.5 * 20 + 3.0 * 30) / 100 = (90 + 90)/100 = 1.8
@@ -296,9 +300,12 @@ def test_us04_verify_calculation_of_current_weighted_average(self):
296300

297301
calculate_button = self.wait_long.until(EC.element_to_be_clickable((By.CSS_SELECTOR, self.CALCULATE_BUTTON_SELECTOR))) # Re-locate button
298302
calculate_button.click()
299-
logger.info("Clicked 'Calcular' button again.")
300-
self.wait_long.until(EC.url_contains("/result"))
301-
logger.info(f"Navigated to {self.driver.current_url}")
303+
logger.info("Clicked 'Calcular' button again for 3rd calculation.")
304+
self._take_screenshot("after_calculate_click_attempt_3")
305+
time.sleep(1)
306+
self.wait_long.until(EC.presence_of_element_located((By.CSS_SELECTOR, self.RESULT_PAGE_CONTAINER_SELECTOR)))
307+
logger.info(f"Result page container '{self.RESULT_PAGE_CONTAINER_SELECTOR}' is present after 3rd calc. Current URL: {self.driver.current_url}. Verifying URL.")
308+
self.assertIn("/result", self.driver.current_url, "URL should contain /result after 3rd calc and result container is present")
302309

303310
current_avg_3 = self._get_current_weighted_average()
304311
# (4.5*20 + 3.0*30 + 5.0*50)/100 = (90 + 90 + 250)/100 = 430/100 = 4.3

0 commit comments

Comments
 (0)