Skip to content

Commit 08bb0d4

Browse files
committed
feat: Integrate e2e testing with pytest
1 parent a6cd0d7 commit 08bb0d4

File tree

2 files changed

+47
-49
lines changed

2 files changed

+47
-49
lines changed

.github/workflows/ci_e2e.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,11 @@ jobs:
6969
run: sudo apt purge google-chrome-stable
7070

7171
- name: Installing all necessary packages
72-
run: pip install chromedriver-autoinstaller selenium pyvirtualdisplay
72+
run: pip install chromedriver-autoinstaller selenium pyvirtualdisplay pytest
7373
- name: Install xvfb
7474
run: sudo apt-get install xvfb
7575

7676

7777
- name: Run E2E tests
7878
run: |
79-
python ./be_repo/tests/test_e2e.py
79+
pytest ./be_repo/tests/test_e2e.py

be_repo/tests/test_e2e.py

Lines changed: 45 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,99 @@
1+
import pytest
2+
import os
3+
import time
14
from selenium import webdriver
25
import chromedriver_autoinstaller
36
from selenium.webdriver.common.by import By
47
from selenium.webdriver.common.keys import Keys
58
from selenium.webdriver.support.ui import WebDriverWait
6-
from selenium.webdriver.chrome.options import Options
7-
from selenium.webdriver.chrome.service import Service
89
from selenium.webdriver.support import expected_conditions as EC
9-
import time
10-
import os
1110
from pyvirtualdisplay import Display
1211

1312
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+
]
1422

15-
display = Display(visible=0, size=(800, 800))
16-
display.start()
1723

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()
1929

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")
2636

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()
2941

30-
driver = webdriver.Chrome(options=chrome_options)
3142

32-
driver.get(FRONTEND_URL)
33-
wait = WebDriverWait(driver, 20)
43+
@pytest.fixture
44+
def wait(driver):
45+
return WebDriverWait(driver, 20)
3446

35-
try:
36-
wait.until(
37-
lambda driver: driver.execute_script("return document.readyState") == "complete"
38-
)
3947

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")
4351

44-
# Upload Resume
52+
# Upload resume
4553
upload_div = driver.find_element(By.CSS_SELECTOR, "div[style*='cursor: pointer'][style*='display: flex']")
46-
# upload_div.click()
47-
4854
file_input = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "input[type='file']")))
4955

5056
file_path = os.path.join(os.path.dirname(__file__), 'test_resume.pdf')
5157
file_input.send_keys(file_path)
5258

59+
# Check for alert after upload
5360
alert = wait.until(EC.alert_is_present())
5461
alert_text = alert.text
5562
assert "Resume uploaded successfully" in alert_text
5663
alert.accept()
5764

65+
66+
def test_analyze_resume(driver, wait):
5867
# Analyze resume
5968
analyze_button = driver.find_element(By.CLASS_NAME, "cursor-pointer")
6069
analyze_button.click()
6170

6271
submit_button = driver.find_element(By.CLASS_NAME, "mt-6")
6372
submit_button.click()
6473

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
7675

7776
elements = driver.find_elements(By.CLASS_NAME, "font-bold")
7877
content_text = " ".join([element.text for element in elements])
7978
for keyword in keywords:
8079
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)"
8281

82+
83+
def test_analyze_resume_with_jd(driver, wait):
8384
# Analyze resume with JD
85+
analyze_button = driver.find_element(By.CLASS_NAME, "cursor-pointer")
8486
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")))
8888
textarea.send_keys("Sample job description text")
89+
8990
submit_button = driver.find_element(By.CLASS_NAME, "mt-6")
9091
submit_button.click()
9192

92-
time.sleep(20)
93+
time.sleep(20) # Ensure analysis completes
9394

9495
elements = driver.find_elements(By.CLASS_NAME, "font-bold")
9596
content_text = " ".join([element.text for element in elements])
9697
for keyword in keywords:
9798
count = content_text.count(keyword)
9899
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

Comments
 (0)