|
| 1 | +import pytest |
| 2 | +import os |
| 3 | +import time |
1 | 4 | from selenium import webdriver
|
2 | 5 | import chromedriver_autoinstaller
|
3 | 6 | from selenium.webdriver.common.by import By
|
4 | 7 | from selenium.webdriver.common.keys import Keys
|
5 | 8 | from selenium.webdriver.support.ui import WebDriverWait
|
6 |
| -from selenium.webdriver.chrome.options import Options |
7 |
| -from selenium.webdriver.chrome.service import Service |
8 | 9 | from selenium.webdriver.support import expected_conditions as EC
|
9 |
| -import time |
10 |
| -import os |
11 | 10 | from pyvirtualdisplay import Display
|
12 | 11 |
|
13 | 12 | FRONTEND_URL = "http://localhost:3001"
|
| 13 | +keywords = [ |
| 14 | + "Analysis Result", |
| 15 | + "Consistency and Chronology", |
| 16 | + "Education", |
| 17 | + "Project and Work Experience", |
| 18 | + "Resume Structure and Presentation", |
| 19 | + "Skills and Certifications", |
| 20 | + "Soft Skills" |
| 21 | +] |
14 | 22 |
|
15 |
| -display = Display(visible=0, size=(800, 800)) |
16 |
| -display.start() |
17 | 23 |
|
18 |
| -chromedriver_autoinstaller.install() |
| 24 | +@pytest.fixture(scope="module") |
| 25 | +def driver(): |
| 26 | + # Start display |
| 27 | + display = Display(visible=0, size=(800, 800)) |
| 28 | + display.start() |
19 | 29 |
|
20 |
| -chrome_options = webdriver.ChromeOptions() |
21 |
| -options = [ |
22 |
| - "--window-size=1200,1200", |
23 |
| - "--ignore-certificate-errors" |
24 |
| - "--headless", |
25 |
| -] |
| 30 | + # Install and set up Chrome driver |
| 31 | + chromedriver_autoinstaller.install() |
| 32 | + chrome_options = webdriver.ChromeOptions() |
| 33 | + chrome_options.add_argument("--window-size=1200,1200") |
| 34 | + chrome_options.add_argument("--ignore-certificate-errors") |
| 35 | + chrome_options.add_argument("--headless") |
26 | 36 |
|
27 |
| -for option in options: |
28 |
| - chrome_options.add_argument(option) |
| 37 | + driver = webdriver.Chrome(options=chrome_options) |
| 38 | + yield driver |
| 39 | + driver.quit() |
| 40 | + display.stop() |
29 | 41 |
|
30 |
| -driver = webdriver.Chrome(options=chrome_options) |
31 | 42 |
|
32 |
| -driver.get(FRONTEND_URL) |
33 |
| -wait = WebDriverWait(driver, 20) |
| 43 | +@pytest.fixture |
| 44 | +def wait(driver): |
| 45 | + return WebDriverWait(driver, 20) |
34 | 46 |
|
35 |
| -try: |
36 |
| - wait.until( |
37 |
| - lambda driver: driver.execute_script("return document.readyState") == "complete" |
38 |
| - ) |
39 | 47 |
|
40 |
| - # Google login |
41 |
| - # google_login_button = driver.find_element(By.CSS_SELECTOR, '[aria-labelledby="button-label"]') |
42 |
| - # google_login_button.click() |
| 48 | +def test_resume_upload(driver, wait): |
| 49 | + driver.get(FRONTEND_URL) |
| 50 | + wait.until(lambda d: d.execute_script("return document.readyState") == "complete") |
43 | 51 |
|
44 |
| - # Upload Resume |
| 52 | + # Upload resume |
45 | 53 | upload_div = driver.find_element(By.CSS_SELECTOR, "div[style*='cursor: pointer'][style*='display: flex']")
|
46 |
| - # upload_div.click() |
47 |
| - |
48 | 54 | file_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "input[type='file']")))
|
49 | 55 |
|
50 | 56 | file_path = os.path.join(os.path.dirname(__file__), 'test_resume.pdf')
|
51 | 57 | file_input.send_keys(file_path)
|
52 | 58 |
|
| 59 | + # Check for alert after upload |
53 | 60 | alert = wait.until(EC.alert_is_present())
|
54 | 61 | alert_text = alert.text
|
55 | 62 | assert "Resume uploaded successfully" in alert_text
|
56 | 63 | alert.accept()
|
57 | 64 |
|
| 65 | + |
| 66 | +def test_analyze_resume(driver, wait): |
58 | 67 | # Analyze resume
|
59 | 68 | analyze_button = driver.find_element(By.CLASS_NAME, "cursor-pointer")
|
60 | 69 | analyze_button.click()
|
61 | 70 |
|
62 | 71 | submit_button = driver.find_element(By.CLASS_NAME, "mt-6")
|
63 | 72 | submit_button.click()
|
64 | 73 |
|
65 |
| - time.sleep(20) |
66 |
| - |
67 |
| - keywords = [ |
68 |
| - "Analysis Result", |
69 |
| - "Consistency and Chronology", |
70 |
| - "Education", |
71 |
| - "Project and Work Experience", |
72 |
| - "Resume Structure and Presentation", |
73 |
| - "Skills and Certifications", |
74 |
| - "Soft Skills" |
75 |
| - ] |
| 74 | + time.sleep(20) # Ensure analysis completes |
76 | 75 |
|
77 | 76 | elements = driver.find_elements(By.CLASS_NAME, "font-bold")
|
78 | 77 | content_text = " ".join([element.text for element in elements])
|
79 | 78 | for keyword in keywords:
|
80 | 79 | count = content_text.count(keyword)
|
81 |
| - assert count == 1, f"'{keyword}' does not appear exactly twice in the content (found {count} times)" |
| 80 | + assert count == 1, f"'{keyword}' does not appear exactly once in the content (found {count} times)" |
82 | 81 |
|
| 82 | + |
| 83 | +def test_analyze_resume_with_jd(driver, wait): |
83 | 84 | # Analyze resume with JD
|
| 85 | + analyze_button = driver.find_element(By.CLASS_NAME, "cursor-pointer") |
84 | 86 | analyze_button.click()
|
85 |
| - textarea = wait.until( |
86 |
| - EC.presence_of_element_located((By.CSS_SELECTOR, "textarea.w-full.h-40.p-4.border-2")) |
87 |
| - ) |
| 87 | + textarea = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "textarea.w-full.h-40.p-4.border-2"))) |
88 | 88 | textarea.send_keys("Sample job description text")
|
| 89 | + |
89 | 90 | submit_button = driver.find_element(By.CLASS_NAME, "mt-6")
|
90 | 91 | submit_button.click()
|
91 | 92 |
|
92 |
| - time.sleep(20) |
| 93 | + time.sleep(20) # Ensure analysis completes |
93 | 94 |
|
94 | 95 | elements = driver.find_elements(By.CLASS_NAME, "font-bold")
|
95 | 96 | content_text = " ".join([element.text for element in elements])
|
96 | 97 | for keyword in keywords:
|
97 | 98 | count = content_text.count(keyword)
|
98 | 99 | assert count == 2, f"'{keyword}' does not appear exactly twice in the content (found {count} times)"
|
99 |
| - |
100 |
| -finally: |
101 |
| - driver.quit() |
0 commit comments