Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial end to end test included in build workflow #1109

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
b04281f
Initial e2e test setup
ritwik-g Jan 31, 2025
04428a1
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
1f2b526
Merge branch 'main' into initial_e2e_test
ritwik-g Jan 31, 2025
f0bbc43
Corrected the runplatform script portion to use sh
ritwik-g Jan 31, 2025
f51b3b3
Merge branch 'initial_e2e_test' of github.com:Zipstack/unstract into …
ritwik-g Jan 31, 2025
ba5c957
Removed the e2e test from env list
ritwik-g Jan 31, 2025
d3d91ed
Trying to run the e2e tox in build workflow
ritwik-g Jan 31, 2025
643ea78
Corrected build workflow yaml indendation
ritwik-g Jan 31, 2025
e88b137
Added waiting logic for container load
ritwik-g Jan 31, 2025
6346ba4
Debugging network issue
ritwik-g Jan 31, 2025
05879cf
Corrected the docker compose down part
ritwik-g Jan 31, 2025
93b3677
Merge remote-tracking branch 'origin/main' into initial_e2e_test
ritwik-g Jan 31, 2025
2cd421e
Added docker tear down step
ritwik-g Jan 31, 2025
131a3ba
Changed the css selector for login button
ritwik-g Jan 31, 2025
4058d2f
Added explicit wait
ritwik-g Jan 31, 2025
e1bc12a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
09b4c30
added chrome and chrome dirver installtion
ritwik-g Jan 31, 2025
e63a2bf
added chrome and chrome dirver installtion
ritwik-g Jan 31, 2025
9c7b9e9
Added driver installation via code
ritwik-g Jan 31, 2025
bbfb5b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Jan 31, 2025
c2f62e1
Added additional log and logic for debugging
ritwik-g Jan 31, 2025
2c17354
Merge branch 'initial_e2e_test' of github.com:Zipstack/unstract into …
ritwik-g Jan 31, 2025
903ab81
corrected the report path for e2e test
ritwik-g Jan 31, 2025
bfcf2ea
Added title to E2E test report message
ritwik-g Feb 2, 2025
3a7005d
Updated echo with printf to preserve special characters in the report
ritwik-g Feb 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 50 additions & 1 deletion .github/workflows/ci-container-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Container Run
run: |
./run-platform.sh -b
Expand All @@ -48,4 +50,51 @@ jobs:
docker compose -f docker/docker-compose.yaml down -v
exit 1
fi
docker compose -f docker/docker-compose.yaml down -v
curl -vvv http://frontend.unstract.localhost

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.9'

- uses: browser-actions/setup-chrome@v1
with:
chrome-version: latest
install-chromedriver: false

- name: Cache tox environments
uses: actions/cache@v4
with:
path: .tox/
key: ${{ runner.os }}-tox-${{ hashFiles('**/pyproject.toml', '**/tox.ini') }}
restore-keys: |
${{ runner.os }}-tox-

- name: Install tox
run: pip install tox

- name: Run tox
id: tox
run: |
tox -e e2e &&
printf '$$\\textcolor{#0051db}{\\tt{E2E\\ Tests}}$$\n\n%s' "$(cat e2e-report.md)" > e2e-report.md

- name: Render the report to the PR
uses: marocchino/sticky-pull-request-comment@v2
with:
header: e2e-test-report
recreate: true
path: e2e-report.md

- name: Output reports to the job summary when tests fail
shell: bash
run: |
if [ -f "e2e-report.md" ]; then
echo "<details><summary>E2E Test Report</summary>" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
cat "e2e-report.md" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "</details>" >> $GITHUB_STEP_SUMMARY
fi
- name: Stop any running containers
run: docker compose -f docker/docker-compose.yaml down -v
6 changes: 6 additions & 0 deletions tests/e2e/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pytest~=8.0
pytest-mock~=3.0
pytest-cov~=6.0
pytest-md-report~=0.6.0
selenium~=4.28
webdriver-manager~=4.0
78 changes: 78 additions & 0 deletions tests/e2e/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.chrome import ChromeDriverManager


class TestLogin:
def setup_method(self, method):
options = Options()
options.add_argument("--headless=new")
self.driver = webdriver.Chrome(
service=ChromeService(ChromeDriverManager().install()), options=options
)
self.driver.implicitly_wait(5)

def teardown_method(self, method):
self.driver.quit()

def _check_page_load(self):
try:
self.driver.get("http://frontend.unstract.localhost")
except Exception as e:
print(f"Page load exception: {e}")
return False
else:
return True

def test_login(self):
# Wait for the page to load
WebDriverWait(self.driver, timeout=30).until(
lambda _: self._check_page_load(),
"Page load failed",
)
WebDriverWait(self.driver, timeout=30).until(
EC.presence_of_element_located((By.CLASS_NAME, "login-main"))
)
print(self.driver.find_element(By.CLASS_NAME, "login-main").text)
# Set the window size
self.driver.set_window_size(960, 615)

# Explicit wait for the button to be clickable
WebDriverWait(self.driver, timeout=10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "span")),
"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 or URL did not change.",
)

# Close the browser
self.driver.close()
6 changes: 6 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ commands_pre =
sh -c '[ -f cloud_requirements.txt ] && pip install -r cloud_requirements.txt || echo "cloud_requirements.txt not found"'
commands =
pytest -v --md-report-verbose=1 --md-report --md-report-flavor gfm --md-report-output ../runner-report.md

[testenv:e2e]
commands_pre =
pip install -r tests/e2e/requirements.txt
commands =
pytest -s -v --md-report-verbose=1 --md-report --md-report-flavor gfm --md-report-output e2e-report.md tests/e2e/