Skip to content

Commit e16c743

Browse files
feat: implement test automation and integrating it with deployment pipeline
1 parent f1686b7 commit e16c743

17 files changed

Lines changed: 692 additions & 8 deletions

.github/workflows/deploy.yml

Lines changed: 52 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ name: Validate Deployment
33
on:
44
push:
55
branches:
6-
- main
7-
schedule:
8-
- cron: '0 9,21 * * *' # Runs at 9:00 AM and 9:00 PM GMT
6+
- deploy-and-test
7+
# - main
8+
# schedule:
9+
# - cron: '0 9,21 * * *' # Runs at 9:00 AM and 9:00 PM GMT
910

1011
env:
11-
GPT_MIN_CAPACITY: 10
12-
TEXT_EMBEDDING_MIN_CAPACITY: 10
12+
GPT_MIN_CAPACITY: 250
13+
TEXT_EMBEDDING_MIN_CAPACITY: 40
1314

1415
jobs:
1516
deploy:
@@ -102,9 +103,9 @@ jobs:
102103
id: generate_solution_prefix
103104
run: |
104105
set -e
105-
COMMON_PART="pslr"
106+
COMMON_PART="psldg"
106107
TIMESTAMP=$(date +%s)
107-
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 3)
108+
UPDATED_TIMESTAMP=$(echo $TIMESTAMP | tail -c 6)
108109
UNIQUE_SOLUTION_PREFIX="${COMMON_PART}${UPDATED_TIMESTAMP}"
109110
echo "SOLUTION_PREFIX=${UNIQUE_SOLUTION_PREFIX}" >> $GITHUB_ENV
110111
echo "Generated SOLUTION_PREFIX: ${UNIQUE_SOLUTION_PREFIX}"
@@ -114,6 +115,7 @@ jobs:
114115
run: |
115116
set -e
116117
az deployment group create \
118+
--name ${{ env.SOLUTION_PREFIX }}-deployment \
117119
--resource-group ${{ env.RESOURCE_GROUP_NAME }} \
118120
--template-file infra/main.json \
119121
--parameters \
@@ -126,7 +128,49 @@ jobs:
126128
embeddingModel="text-embedding-ada-002" \
127129
embeddingDeploymentCapacity=${{ env.TEXT_EMBEDDING_MIN_CAPACITY }} \
128130
imageTag="latest"
129-
131+
132+
- name: Get Deployment Output
133+
id: get_output
134+
run: |
135+
set -e
136+
echo "Fetching deployment output..."
137+
BICEP_OUTPUT=$(az deployment group show --name ${{ env.SOLUTION_PREFIX }}-deployment --resource-group ${{ env.RESOURCE_GROUP_NAME }} --query "properties.outputs" -o json)
138+
echo "BICEP_OUTPUT=$BICEP_OUTPUT" >> $GITHUB_ENV
139+
echo "Deployment output: $BICEP_OUTPUT"
140+
141+
- name: Run Post-Deployment Script
142+
id: post_deploy
143+
run: |
144+
set -e
145+
echo "Extracting deployment output..."
146+
WEBAPP_URL=$(echo $BICEP_OUTPUT | jq -r '.WEB_APP_URL.value')
147+
STORAGE_ACCOUNT_NAME=$(echo $BICEP_OUTPUT | jq -r '.STORAGE_ACCOUNT_NAME.value')
148+
STORAGE_CONTAINER_NAME=$(echo $BICEP_OUTPUT | jq -r '.STORAGE_CONTAINER_NAME.value')
149+
KEY_VAULT_NAME=$(echo $BICEP_OUTPUT | jq -r '.KEY_VAULT_NAME.value')
150+
COSMOSDB_ACCOUNT_NAME=$(echo $BICEP_OUTPUT | jq -r '.COSMOSDB_ACCOUNT_NAME.value')
151+
152+
echo "Opening webapp URL in browser..."
153+
xdg-open "$WEBAPP_URL" || echo "xdg-open command not found."
154+
echo "Webapp URL: $WEBAPP_URL" >> $GITHUB_ENV
155+
156+
az account set --subscription "$SUBSCRIPTION_ID"
157+
158+
echo "Running post-deployment script..."
159+
bash ./infra/scripts/process_sample_data.sh \
160+
"$STORAGE_ACCOUNT_NAME" \
161+
"$STORAGE_CONTAINER_NAME" \
162+
"$KEY_VAULT_NAME" \
163+
"$COSMOSDB_ACCOUNT_NAME" \
164+
"${{ env.RESOURCE_GROUP_NAME }}" \
165+
166+
- name: Call Test Automation Workflow
167+
if: success()
168+
id: call_test_automation
169+
uses: ./.github/workflows/gp-test-automation.yml
170+
with:
171+
webapp_url: ${{ env.WEBAPP_URL }}
172+
173+
130174
- name: Extract AI Services and Key Vault Names
131175
if: always() && steps.check_create_rg.outcome == 'success'
132176
run: |
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Test Automation DocGen
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
DOCGEN_URL:
7+
required: true
8+
type: string
9+
description: "Web URL for DocGen"
10+
11+
env:
12+
url: ${{ inputs.DOCGEN_URL }}
13+
accelerator_name: "DocGen"
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.13'
26+
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -r playwright-tests/requirements.txt
31+
32+
- name: Ensure browsers are installed
33+
run: python -m playwright install --with-deps chromium
34+
35+
- name: Run tests(1)
36+
id: test1
37+
run: |
38+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
39+
working-directory: playwright-tests
40+
continue-on-error: true
41+
42+
- name: Sleep for 30 seconds
43+
if: ${{ steps.test1.outcome == 'failure' }}
44+
run: sleep 30s
45+
shell: bash
46+
47+
- name: Run tests(2)
48+
if: ${{ steps.test1.outcome == 'failure' }}
49+
id: test2
50+
run: |
51+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
52+
working-directory: playwright-tests
53+
continue-on-error: true
54+
55+
- name: Sleep for 60 seconds
56+
if: ${{ steps.test2.outcome == 'failure' }}
57+
run: sleep 60s
58+
shell: bash
59+
60+
- name: Run tests(3)
61+
if: ${{ steps.test2.outcome == 'failure' }}
62+
id: test3
63+
run: |
64+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
65+
working-directory: playwright-tests
66+
67+
- name: Upload test report
68+
id: upload_report
69+
uses: actions/upload-artifact@v4
70+
if: ${{ !cancelled() }}
71+
with:
72+
name: test-report
73+
path: playwright-tests/report/*
74+
75+
- name: Send Notification on Failure
76+
if: always()
77+
run: |
78+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
79+
REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
80+
IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }}
81+
# Construct the email body
82+
if [ "$IS_SUCCESS" = "true" ]; then
83+
EMAIL_BODY=$(cat <<EOF
84+
{
85+
"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>",
86+
"subject": "${{ env.accelerator_name }} Test Automation - Success"
87+
}
88+
EOF
89+
)
90+
else
91+
EMAIL_BODY=$(cat <<EOF
92+
{
93+
"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>",
94+
"subject": "${{ env.accelerator_name }} Test Automation - Failure"
95+
}
96+
EOF
97+
)
98+
fi
99+
100+
# Send the notification
101+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL }}" \
102+
-H "Content-Type: application/json" \
103+
-d "$EMAIL_BODY" || echo "Failed to send notification"

playwright-tests/.gitignore

Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
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/

playwright-tests/README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Test Automation for DOC_GEN Accelerator
2+
3+
Write end-to-end tests for your web apps with [Playwright](https://github.com/microsoft/playwright-python) and [pytest](https://docs.pytest.org/en/stable/).
4+
5+
- Support for **all modern browsers** including Chromium, WebKit and Firefox.
6+
- Support for **headless and headed** execution.
7+
- **Built-in fixtures** that provide browser primitives to test functions.
8+
9+
Pre-Requisites:
10+
11+
- Install Visual Studio Code: Download and Install Visual Studio Code(VSCode).
12+
- Install NodeJS: Download and Install Node JS
13+
14+
Create and Activate Python Virtual Environment
15+
16+
- From your directory open and run cmd : "python -m venv microsoft"
17+
This will create a virtual environment directory named microsoft inside your current directory
18+
- To enable virtual environment, copy location for "microsoft\Scripts\activate.bat" and run from cmd
19+
20+
Installing Playwright Pytest from Virtual Environment
21+
22+
- To install libraries run "pip install -r requirements.txt"
23+
- Install the required browsers "playwright install"
24+
25+
Run test cases
26+
27+
- To run test cases from your 'tests' folder : "pytest --headed --html=report/report.html"
28+
29+
Create .env file in project root level with web app url and client credentials
30+
31+
- create a .env file in project root level and add your web url. please refer 'sample_dotenv_file.txt' file.
32+
33+
## Documentation
34+
35+
See on [playwright.dev](https://playwright.dev/python/docs/test-runners) for examples and more detailed information.

0 commit comments

Comments
 (0)