Skip to content

Commit 57d6b8a

Browse files
test: Migrate test automation scripts and pipeline for DKM
2 parents 96c5987 + 5e40115 commit 57d6b8a

File tree

15 files changed

+760
-0
lines changed

15 files changed

+760
-0
lines changed
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
name: Test Automation DKM
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.DKM_URL }}
16+
accelerator_name: "DKM"
17+
18+
jobs:
19+
test:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout repository
23+
uses: actions/checkout@v4
24+
25+
- name: Set up Python
26+
uses: actions/setup-python@v4
27+
with:
28+
python-version: '3.13'
29+
30+
- name: Azure CLI Login
31+
uses: azure/login@v2
32+
with:
33+
creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ secrets.AZURE_TENANT_ID }}"}'
34+
35+
- name: Start AKS
36+
id: start-aks
37+
uses: azure/cli@v2
38+
with:
39+
azcliversion: 'latest'
40+
inlineScript: |
41+
az aks install-cli
42+
if [ "$(az aks show --resource-group ${{ vars.DKM_RG }} --name ${{ vars.DKM_AKS_NAME }} --query "powerState.code" -o tsv)" = "Running" ]; then echo "AKS is running"; else az aks start --resource-group ${{ vars.DKM_RG }} --name ${{ vars.DKM_AKS_NAME }}; fi
43+
44+
- name: Install dependencies
45+
run: |
46+
python -m pip install --upgrade pip
47+
pip install -r tests/e2e-test/requirements.txt
48+
49+
- name: Ensure browsers are installed
50+
run: python -m playwright install --with-deps chromium
51+
52+
- name: Run tests(1)
53+
id: test1
54+
run: |
55+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
56+
working-directory: tests/e2e-test
57+
continue-on-error: true
58+
59+
- name: Sleep for 30 seconds
60+
if: ${{ steps.test1.outcome == 'failure' }}
61+
run: sleep 30s
62+
shell: bash
63+
64+
- name: Run tests(2)
65+
id: test2
66+
if: ${{ steps.test1.outcome == 'failure' }}
67+
run: |
68+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
69+
working-directory: tests/e2e-test
70+
continue-on-error: true
71+
72+
- name: Sleep for 60 seconds
73+
if: ${{ steps.test2.outcome == 'failure' }}
74+
run: sleep 60s
75+
shell: bash
76+
77+
- name: Run tests(3)
78+
id: test3
79+
if: ${{ steps.test2.outcome == 'failure' }}
80+
run: |
81+
xvfb-run pytest --headed --html=report/report.html --self-contained-html
82+
working-directory: tests/e2e-test
83+
84+
- name: Upload test report
85+
id: upload_report
86+
uses: actions/upload-artifact@v4
87+
if: ${{ !cancelled() }}
88+
with:
89+
name: test-report
90+
path: tests/e2e-test/report/*
91+
92+
- name: Send Notification
93+
if: always()
94+
run: |
95+
RUN_URL="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
96+
REPORT_URL=${{ steps.upload_report.outputs.artifact-url }}
97+
IS_SUCCESS=${{ steps.test1.outcome == 'success' || steps.test2.outcome == 'success' || steps.test3.outcome == 'success' }}
98+
# Construct the email body
99+
if [ "$IS_SUCCESS" = "true" ]; then
100+
EMAIL_BODY=$(cat <<EOF
101+
{
102+
"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>",
103+
"subject": "${{ env.accelerator_name }} Test Automation - Success"
104+
}
105+
EOF
106+
)
107+
else
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 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>",
111+
"subject": "${{ env.accelerator_name }} Test Automation - Failure"
112+
}
113+
EOF
114+
)
115+
fi
116+
117+
# Send the notification
118+
curl -X POST "${{ secrets.EMAILNOTIFICATION_LOGICAPP_URL_TA }}" \
119+
-H "Content-Type: application/json" \
120+
-d "$EMAIL_BODY" || echo "Failed to send notification"
121+
122+
- name: Stop AKS
123+
if: always()
124+
uses: azure/cli@v2
125+
with:
126+
azcliversion: 'latest'
127+
inlineScript: |
128+
az aks install-cli
129+
if [ "$(az aks show --resource-group ${{ vars.DKM_RG }} --name ${{ vars.DKM_AKS_NAME }} --query "powerState.code" -o tsv)" = "Running" ]; then az aks stop --resource-group ${{ vars.DKM_RG }} --name ${{ vars.DKM_AKS_NAME }}; else echo "AKS is already stopped"; fi
130+
az logout

tests/e2e-test/.gitignore

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

tests/e2e-test/README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Test Automation for Document Knowledge Mining 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+
24+
Run test cases
25+
26+
- To run test cases from your 'tests' folder : "pytest --html=report.html --self-contained-html"
27+
28+
Create .env file in project root level with web app url and client credentials
29+
30+
- create a .env file in project root level and the application url. please refer 'sample_dotenv_file.txt' file.
31+
32+
## Documentation
33+
34+
See on [playwright.dev](https://playwright.dev/python/docs/test-runners) for examples and more detailed information.

tests/e2e-test/base/__init__.py

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

tests/e2e-test/base/base.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from config.constants import *
2+
import requests
3+
import json
4+
from dotenv import load_dotenv
5+
import os
6+
7+
class BasePage:
8+
def __init__(self, page):
9+
self.page = page
10+
11+
def scroll_into_view(self,locator):
12+
reference_list = locator
13+
locator.nth(reference_list.count()-1).scroll_into_view_if_needed()
14+
15+
def is_visible(self,locator):
16+
locator.is_visible()
17+
18+
def validate_response_status(self, question_api):
19+
load_dotenv()
20+
# The URL of the API endpoint you want to access
21+
url = f"{URL}/backend/chat"
22+
23+
headers = {
24+
"Content-Type": "application/json",
25+
"Accept": "*/*",
26+
}
27+
payload = {
28+
"Question": question_api, # This is your example question, you can modify it as needed
29+
}
30+
# Make the POST request
31+
response = self.page.request.post(url, headers=headers, data=json.dumps(payload), timeout=200000)
32+
33+
# Check the response status code
34+
assert response.status == 200, "Response code is " + str(response.status) + " " + str(response.json())
35+
36+

tests/e2e-test/config/constants.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from dotenv import load_dotenv
2+
import os
3+
4+
load_dotenv()
5+
URL = os.getenv('url')
6+
if URL.endswith('/'):
7+
URL = URL[:-1]
8+
9+
# DKM input data
10+
chat_question1 = "What are the main factors contributing to the current housing affordability issues?"
11+
chat_question2 = "Analyze the two annual reports and compare the positive and negative outcomes YoY. Show the results in a table."
12+
house_10_11_question ="Can you summarize and compare the tables on page 10 and 11?"
13+
handwritten_question1 ="Analyze these forms and create a table with all buyers, sellers, and corresponding purchase prices."
14+
search_1= "Housing Report"
15+
search_2= "Contracts"
16+
contract_details_question = "What liabilities is the buyer responsible for within the contract?"

tests/e2e-test/pages/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from. import loginPage
2+
from. import dkmPage

0 commit comments

Comments
 (0)