Skip to content

Commit cc64239

Browse files
test: Migrate test automation scripts and pipeline for Code Modernization
2 parents 092fd4a + b772d74 commit cc64239

18 files changed

Lines changed: 620 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
name: Test Automation Code Modernization
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- dev
8+
paths:
9+
- 'tests/e2e-test/**'
10+
schedule:
11+
- cron: '0 13 * * *' # Runs at 1 PM UTC
12+
workflow_dispatch:
13+
14+
env:
15+
url: ${{ vars.CODEMOD_WEB_URL }}
16+
accelerator_name: "Code Modernization"
17+
18+
jobs:
19+
test:
20+
21+
runs-on: ubuntu-latest
22+
steps:
23+
- name: Checkout repository
24+
uses: actions/checkout@v4
25+
26+
- name: Set up Python
27+
uses: actions/setup-python@v4
28+
with:
29+
python-version: '3.13'
30+
31+
- name: Azure CLI Login
32+
uses: azure/login@v2
33+
with:
34+
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
35+
36+
- name: Start Container App
37+
id: start-container-app
38+
uses: azure/cli@v2
39+
with:
40+
azcliversion: 'latest'
41+
inlineScript: |
42+
az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.CODEMOD_RG }}/providers/Microsoft.App/containerApps/${{ vars.CODEMOD_FRONTEND_CONTAINER_NAME }}/start?api-version=2025-01-01"
43+
az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.CODEMOD_RG }}/providers/Microsoft.App/containerApps/${{ vars.CODEMOD_BACKEND_CONTAINER_NAME }}/start?api-version=2025-01-01"
44+
45+
- name: Install dependencies
46+
run: |
47+
python -m pip install --upgrade pip
48+
pip install -r tests/e2e-test/requirements.txt
49+
50+
- name: Ensure browsers are installed
51+
run: python -m playwright install --with-deps chromium
52+
53+
- name: Run tests(1)
54+
id: test1
55+
run: |
56+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
57+
working-directory: tests/e2e-test
58+
continue-on-error: true
59+
60+
- name: Sleep for 30 seconds
61+
if: ${{ steps.test1.outcome == 'failure' }}
62+
run: sleep 30s
63+
shell: bash
64+
65+
- name: Run tests(2)
66+
id: test2
67+
if: ${{ steps.test1.outcome == 'failure' }}
68+
run: |
69+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
70+
working-directory: tests/e2e-test
71+
continue-on-error: true
72+
73+
- name: Sleep for 60 seconds
74+
if: ${{ steps.test2.outcome == 'failure' }}
75+
run: sleep 60s
76+
shell: bash
77+
78+
- name: Run tests(3)
79+
id: test3
80+
if: ${{ steps.test2.outcome == 'failure' }}
81+
run: |
82+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
83+
working-directory: tests/e2e-test
84+
85+
- name: Upload test report
86+
id: upload_report
87+
uses: actions/upload-artifact@v4
88+
if: ${{ !cancelled() }}
89+
with:
90+
name: test-report
91+
path: tests/e2e-test/report/*
92+
93+
- name: Send Notification
94+
if: always()
95+
run: |
96+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
97+
REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
98+
IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }}
99+
# Construct the email body
100+
if [ "$IS_SUCCESS" = "true" ]; then
101+
EMAIL_BODY=$(cat <<EOF
102+
{
103+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has completed successfully.</p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\"${REPORT_URL}\">${REPORT_URL}</a></p><p>Best regards,<br>Your Automation Team</p>",
104+
"subject": "${{ env.accelerator_name }} Test Automation - Success"
105+
}
106+
EOF
107+
)
108+
else
109+
EMAIL_BODY=$(cat <<EOF
110+
{
111+
"body": "<p>Dear Team,</p><p>We would like to inform you that the ${{ env.accelerator_name }} Test Automation process has encountered an issue and has failed to complete successfully.</p><p><strong>Run URL:</strong> <a href=\"${RUN_URL}\">${RUN_URL}</a><br></p><p><strong>Test Report:</strong> <a href=\"${REPORT_URL}\">${REPORT_URL}</a></p><p>Please investigate the matter at your earliest convenience.</p><p>Best regards,<br>Your Automation Team</p>",
112+
"subject": "${{ env.accelerator_name }} Test Automation - Failure"
113+
}
114+
EOF
115+
)
116+
fi
117+
118+
# Send the notification
119+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
120+
-H "Content-Type: application/json" \
121+
-d "$EMAIL_BODY" || echo "Failed to send notification"
122+
123+
- name: Stop Container App
124+
if: always()
125+
uses: azure/cli@v2
126+
with:
127+
azcliversion: 'latest'
128+
inlineScript: |
129+
az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.CODEMOD_RG }}/providers/Microsoft.App/containerApps/${{ vars.CODEMOD_FRONTEND_CONTAINER_NAME }}/stop?api-version=2025-01-01"
130+
az rest -m post -u "/subscriptions/${{ secrets.AZURE_SUBSCRIPTION_ID }}/resourceGroups/${{ vars.CODEMOD_RG }}/providers/Microsoft.App/containerApps/${{ vars.CODEMOD_BACKEND_CONTAINER_NAME }}/stop?api-version=2025-01-01"
131+
az logout

tests/e2e-test/.gitignore

Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
110+
.pdm.toml
111+
.pdm-python
112+
.pdm-build/
113+
114+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
115+
__pypackages__/
116+
117+
# Celery stuff
118+
celerybeat-schedule
119+
celerybeat.pid
120+
121+
# SageMath parsed files
122+
*.sage.py
123+
124+
# Environments
125+
.env
126+
.venv
127+
env/
128+
venv/
129+
ENV/
130+
env.bak/
131+
venv.bak/
132+
microsoft/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
.idea/
164+
archive/
165+
report/
166+
screenshots/
167+
report.html
168+
assets/
169+
.vscode/

tests/e2e-test/base/__init__.py

Whitespace-only changes.

tests/e2e-test/base/base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class BasePage:
2+
def __init__(self, page):
3+
self.page = page
4+
5+
def scroll_into_view(self, locator):
6+
reference_list = locator
7+
locator.nth(reference_list.count() - 1).scroll_into_view_if_needed()
8+
9+
def is_visible(self, locator):
10+
locator.is_visible()

tests/e2e-test/config/constants.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
3+
from dotenv import load_dotenv
4+
5+
load_dotenv()
6+
URL = os.getenv("url")
7+
if URL.endswith("/"):
8+
URL = URL[:-1]

tests/e2e-test/pages/HomePage.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import os.path
2+
3+
from base.base import BasePage
4+
5+
from playwright.sync_api import expect
6+
7+
8+
class HomePage(BasePage):
9+
TITLE_TEXT = "//h1[normalize-space()='Modernize your code']"
10+
BROWSE_FILES = "//button[normalize-space()='Browse files']"
11+
SUCCESS_MSG = "//span[contains(text(),'All valid files uploaded successfully!')]"
12+
TRANSLATE_BTN = "//button[normalize-space()='Start translating']"
13+
BATCH_HISTORY = "//button[@aria-label='View batch history']"
14+
CLOSE_BATCH_HISTORY = "//button[@aria-label='Close panel']"
15+
BATCH_DETAILS = "//div[@class='batch-details']"
16+
DOWNLOAD_FILES = "//button[normalize-space()='Download all as .zip']"
17+
RETURN_HOME = "//button[normalize-space()='Return home']"
18+
SUMMARY = "//span[normalize-space()='Summary']"
19+
FILE_PROCESSED_MSG = "//span[normalize-space()='3 files processed successfully']"
20+
21+
def __init__(self, page):
22+
self.page = page
23+
24+
def validate_home_page(self):
25+
expect(self.page.locator(self.TITLE_TEXT)).to_be_visible()
26+
27+
def upload_files(self):
28+
with self.page.expect_file_chooser() as fc_info:
29+
self.page.locator(self.BROWSE_FILES).click()
30+
self.page.wait_for_timeout(5000)
31+
self.page.wait_for_load_state("networkidle")
32+
file_chooser = fc_info.value
33+
current_working_dir = os.getcwd()
34+
file_path1 = os.path.join(current_working_dir, "testdata/q1_informix.sql")
35+
file_path2 = os.path.join(current_working_dir, "testdata/f1.sql")
36+
file_path3 = os.path.join(current_working_dir, "testdata/f2.sql")
37+
file_chooser.set_files([file_path1, file_path2, file_path3])
38+
self.page.wait_for_timeout(10000)
39+
self.page.wait_for_load_state("networkidle")
40+
expect(self.page.locator(self.SUCCESS_MSG)).to_be_visible()
41+
42+
def upload_unsupported_files(self):
43+
with self.page.expect_file_chooser() as fc_info:
44+
self.page.locator(self.BROWSE_FILES).click()
45+
self.page.wait_for_timeout(5000)
46+
self.page.wait_for_load_state("networkidle")
47+
file_chooser = fc_info.value
48+
current_working_dir = os.getcwd()
49+
file_path = os.path.join(current_working_dir, "testdata/invalid.py")
50+
file_chooser.set_files([file_path])
51+
self.page.wait_for_timeout(4000)
52+
self.page.wait_for_load_state("networkidle")
53+
expect(self.page.locator(self.TRANSLATE_BTN)).to_be_disabled()
54+
55+
def validate_translate(self):
56+
self.page.locator(self.TRANSLATE_BTN).click()
57+
expect(self.page.locator(self.DOWNLOAD_FILES)).to_be_enabled(timeout=200000)
58+
self.page.locator(self.SUMMARY).click()
59+
expect(self.page.locator(self.FILE_PROCESSED_MSG)).to_be_visible()
60+
self.page.wait_for_timeout(3000)
61+
62+
def validate_batch_history(self):
63+
self.page.locator(self.BATCH_HISTORY).click()
64+
self.page.wait_for_timeout(3000)
65+
batch_details = self.page.locator(self.BATCH_DETAILS)
66+
for i in range(batch_details.count()):
67+
expect(batch_details.nth(i)).to_be_visible()
68+
self.page.locator(self.CLOSE_BATCH_HISTORY).click()
69+
70+
def validate_download_files(self):
71+
self.page.locator(self.DOWNLOAD_FILES).click()
72+
self.page.wait_for_timeout(7000)
73+
self.page.locator(self.RETURN_HOME).click()
74+
self.page.wait_for_timeout(3000)
75+
expect(self.page.locator(self.TITLE_TEXT)).to_be_visible()

tests/e2e-test/pages/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)