Skip to content

Commit dc4f784

Browse files
Added Test Automation scripts and pipeline
1 parent 092fd4a commit dc4f784

18 files changed

Lines changed: 646 additions & 0 deletions

File tree

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

TestAutomation/.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/

TestAutomation/base/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import base

TestAutomation/base/base.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from config.constants import *
2+
from dotenv import load_dotenv
3+
4+
5+
class BasePage:
6+
def __init__(self, page):
7+
self.page = page
8+
9+
def scroll_into_view(self,locator):
10+
reference_list = locator
11+
locator.nth(reference_list.count()-1).scroll_into_view_if_needed()
12+
13+
def is_visible(self,locator):
14+
locator.is_visible()
15+
16+

TestAutomation/config/constants.py

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

0 commit comments

Comments
 (0)