Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
166 changes: 166 additions & 0 deletions tests/e2e-tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
.pdm.toml
.pdm-python
.pdm-build/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
microsoft/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
archive/
report/
screenshots/
42 changes: 42 additions & 0 deletions tests/e2e-tests/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Automation Proof Of Concept for BYOc Research Assistant Accelerator



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

- Support for **all modern browsers** including Chromium, WebKit and Firefox.
- Support for **headless and headed** execution.
- **Built-in fixtures** that provide browser primitives to test functions.

Pre-Requisites:
- Install Visual Studio Code: Download and Install Visual Studio Code(VSCode).
- Install NodeJS: Download and Install Node JS

Create and Activate Python Virtual Environment
- From your directory open and run cmd : "python -m venv microsoft"
This will create a virtual environment directory named microsoft inside your current directory
- To enable virtual environment, copy location for "microsoft\Scripts\activate.bat" and run from cmd


Installing Playwright Pytest from Virtual Environment
- To install libraries run "pip install -r requirements.txt"
- Install the required browsers "playwright install"


Run test cases
- To run test cases from your 'tests' folder : "pytest --headed --html=report/report.html"

Steps need to be followed to enable Access Token and Client Credentials
- Go to App Service from the resource group and select the Access Tokens check box in 'Manage->Authentication' tab
![img.png](img.png)
- Go to Manage->Certificates & secrets tab to generate Client Secret value
![img_1.png](img_1.png)
- Go to Overview tab to get the client id and tenant id.

Create .env file in project root level with web app url and client credentials
- create a .env file in project root level and add your user_name, pass_word, client_id,client_secret,
tenant_id and url for the resource group. please refer 'sample_dotenv_file.txt' file.

## Documentation

See on [playwright.dev](https://playwright.dev/python/docs/test-runners) for examples and more detailed information.
1 change: 1 addition & 0 deletions tests/e2e-tests/base/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import base
97 changes: 97 additions & 0 deletions tests/e2e-tests/base/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from config.constants import *
import requests
import json
from dotenv import load_dotenv
import os

class BasePage:
def __init__(self, page):
self.page = page

def scroll_into_view(self,locator):
reference_list = locator
locator.nth(reference_list.count()-1).scroll_into_view_if_needed()

def is_visible(self,locator):
locator.is_visible()

def validate_response_status(self,indexName):
load_dotenv()
client_id = os.getenv('client_id')
client_secret = os.getenv('client_secret')
tenant_id = os.getenv('tenant_id')
token_url = f"https://login.microsoft.com/{tenant_id}/oauth2/v2.0/token"
# The URL of the API endpoint you want to access
url = f"{URL}/conversation"
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': f'api://{client_id}/.default'
}
response = requests.post(token_url, data=data)
if response.status_code == 200:
token_info = response.json()
access_token = token_info['access_token']
headers = {
'Authorization': f'Bearer {access_token}',
"Content-Type": "application/json",
"Accept": "*/*",
"Accept-Encoding": "gzip, deflate, br, zstd",
"Accept-Language": "en-US,en;q=0.9",
"Connection": "keep-alive",
"Referer": f"{URL}/",
"Origin": URL,
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin"
}
payload = {
"index_name": indexName,
"messages": [
{
"role": "user"
}
]
}
# Make the POST request
response = self.page.request.post(url, headers=headers,data=json.dumps(payload))
# Check the response status code
assert response.status == 200, "response code is "+str(response.status)+" "+str(response.json())
else:
assert response.status_code == 200,"Failed to get token "+response.text

def validate_draft_response_status(self,section_title,topic_text):
load_dotenv()
client_id = os.getenv('client_id')
client_secret = os.getenv('client_secret')
tenant_id = os.getenv('tenant_id')
token_url = f"https://login.microsoft.com/{tenant_id}/oauth2/v2.0/token"
# The URL of the API endpoint you want to access
url = f"{URL}/draft_document/generate_section"
data = {
'grant_type': 'client_credentials',
'client_id': client_id,
'client_secret': client_secret,
'scope': f'api://{client_id}/.default'
}
response = requests.post(token_url, data=data)
if response.status_code == 200:
token_info = response.json()
access_token = token_info['access_token']
headers = {
'Authorization': f'Bearer {access_token}',
"Content-Type": "application/json"
}
payload = {
"grantTopic":topic_text,
"sectionContext": "",
"sectionTitle": section_title
}

# Make the POST request
response = self.page.request.post(url, headers=headers,data=json.dumps(payload))
# Check the response status code
assert response.status == 200, "response code is "+str(response.status)+" "+str(response.json())
else:
assert response.status_code == 200,"Failed to get token "+response.text
19 changes: 19 additions & 0 deletions tests/e2e-tests/config/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from dotenv import load_dotenv
import os

load_dotenv()
URL = os.getenv('url')
if URL.endswith('/'):
URL = URL[:-1]

# Articles input data
articles_question1 = "What are the effects of influenza vaccine on immunocompromised populations?"
articles_question2 = "How do co-morbidities such as hypertension and obesity affect vaccine effectiveness?"
index_name_articles = "Articles"
# Grants input data
grants_question1 = "are there any grants that focus on clinical research concerning influenza vaccination?"
grants_question2 = "Do any of these grant requests mention variables such as demographics, socio-economics, or comorbidities? "
index_name_grants = "Grants"
# Draft input data
draft_topic_text = "The effects of influenza vaccine on immunocompromised persons"

Binary file added tests/e2e-tests/img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/e2e-tests/img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions tests/e2e-tests/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from. import loginPage
from. import articlesPage
from. import grantsPage
from. import draftPage
Loading
Loading