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
1 change: 1 addition & 0 deletions tests/e2e-test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ This will create a virtual environment directory named microsoft inside your cur
Installing Playwright Pytest from Virtual Environment

- To install libraries run "pip install -r requirements.txt"
- To install Playwright run "playwright install"

Run test cases

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e-test/base/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from . import base
"""Initiate base package"""
50 changes: 31 additions & 19 deletions tests/e2e-test/base/base.py
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
from config.constants import *
import requests
import json
from dotenv import load_dotenv
import os

from config.constants import URL


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

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

def is_visible(self,locator):
locator.is_visible()
async def is_visible(self, locator):
return await locator.is_visible()

def validate_response_status(self, question_api):
load_dotenv()
# The URL of the API endpoint you want to access
async def validate_response_status(self, question_api, expected_status=200):
"""Validate API response status for chat endpoint."""
url = f"{URL}/backend/chat"

headers = {
"Content-Type": "application/json",
"Accept": "*/*",
}
payload = {
"Question": question_api, # This is your example question, you can modify it as needed
}
# Make the POST request
response = self.page.request.post(url, headers=headers, data=json.dumps(payload), timeout=200000)

# Check the response status code
assert response.status == 200, "Response code is " + str(response.status) + " " + str(response.json())
payload = {"Question": question_api}

try:
response = await self.page.context.request.post(
url=url, headers=headers, data=json.dumps(payload), timeout=200_000
)

error_msg = f"Response code is {response.status}"
try:
response_json = await response.json()
error_msg += f" Response: {response_json}"
except Exception:
response_text = await response.text()
error_msg += f" Response text: {response_text}"

assert response.status == expected_status, error_msg

await self.page.wait_for_timeout(4000)
return response


except Exception as e:
print(f"Request failed: {e}")
raise
19 changes: 11 additions & 8 deletions tests/e2e-test/config/constants.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
from dotenv import load_dotenv
import os

from dotenv import load_dotenv

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

# DKM input data
chat_question1 = "What are the main factors contributing to the current housing affordability issues?"
chat_question2 = "Analyze the two annual reports and compare the positive and negative outcomes YoY. Show the results in a table."
house_10_11_question ="Can you summarize and compare the tables on page 10 and 11?"
handwritten_question1 ="Analyze these forms and create a table with all buyers, sellers, and corresponding purchase prices."
search_1= "Housing Report"
search_2= "Contracts"
contract_details_question = "What liabilities is the buyer responsible for within the contract?"
house_10_11_question = "Can you summarize and compare the tables on page 10 and 11?"
handwritten_question1 = "Analyze these forms and create a table with all buyers, sellers, and corresponding purchase prices."
search_1 = "Housing Report"
search_2 = "Contracts"
contract_details_question = (
"What liabilities is the buyer responsible for within the contract?"
)
3 changes: 1 addition & 2 deletions tests/e2e-test/pages/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
from. import loginPage
from. import dkmPage
"""Initiate pages package"""
88 changes: 43 additions & 45 deletions tests/e2e-test/pages/dkmPage.py
Original file line number Diff line number Diff line change
@@ -1,53 +1,54 @@
from base.base import BasePage
from playwright.sync_api import expect
import time

from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
from playwright.sync_api import expect

from base.base import BasePage


class DkmPage(BasePage):
WELCOME_PAGE_TITLE = "(//div[@class='order-5 my-auto pb-3 text-lg font-semibold leading-tight text-white mt-3'])[1]"
NEWTOPIC = "//button[normalize-space()='New Topic']"
Suggested_follow_up_questions="body > div:nth-child(3) > div:nth-child(1) > main:nth-child(2) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(6) > div:nth-child(3) > button:nth-child(2)"
Suggested_follow_up_questions = "body > div:nth-child(3) > div:nth-child(1) > main:nth-child(2) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(1) > div:nth-child(6) > div:nth-child(3) > button:nth-child(2)"
SCROLL_DOWN = "//div[10]//div[2]//div[2]//i[1]//img[1]"
ASK_QUESTION ="//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)']"
SEARCH_BOX="//input[@type='search']"
HOUSING_2022 ="//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[4]/div[2]/div[2]/span[1]"
HOUSING_2023 ="//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[3]/div[2]/div[2]/span[1]"
ASK_QUESTION = (
"//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)']"
)
SEARCH_BOX = "//input[@type='search']"
HOUSING_2022 = "//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[4]/div[2]/div[2]/span[1]"
HOUSING_2023 = "//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[3]/div[2]/div[2]/span[1]"
CONTRACTS_DETAILS_PAGE = "body > div:nth-child(3) > div:nth-child(1) > main:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > div:nth-child(1) > div:nth-child(1) > div:nth-child(6) > div:nth-child(2) > div:nth-child(2) > div:nth-child(3) > button:nth-child(2)"
DETAILS_PAGE ="body > div:nth-child(3) > div:nth-child(1) > main:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(2) > div:nth-child(3) > button:nth-child(2)"
POP_UP_CHAT="//button[@value='Chat Room']"
CLOSE_POP_UP ="//button[@aria-label='close']"
CLLEAR_ALL_POP_UP ="//button[normalize-space()='Clear all']"
HANDWRITTEN_DOC1="//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[6]/div[2]/div[2]/span[1]"
HANDWRITTEN_DOC2="//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[1]/div[2]/div[2]/span[1]"
HANDWRITTEN_DOC3="//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[5]/div[2]/div[2]/span[1]"
DETAILS_PAGE = "body > div:nth-child(3) > div:nth-child(1) > main:nth-child(2) > div:nth-child(1) > div:nth-child(2) > div:nth-child(4) > div:nth-child(1) > div:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(2) > div:nth-child(3) > button:nth-child(2)"
POP_UP_CHAT = "//button[@value='Chat Room']"
CLOSE_POP_UP = "//button[@aria-label='close']"
CLLEAR_ALL_POP_UP = "//button[normalize-space()='Clear all']"
HANDWRITTEN_DOC1 = "//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[6]/div[2]/div[2]/span[1]"
HANDWRITTEN_DOC2 = "//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[1]/div[2]/div[2]/span[1]"
HANDWRITTEN_DOC3 = "//body[1]/div[2]/div[1]/main[1]/div[1]/div[2]/div[4]/div[1]/div[1]/div[5]/div[2]/div[2]/span[1]"
SEND_BUTTON = "//button[@aria-label='Send']"
POP_UP_CHAT_SEARCH = "(//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)'])[2]"
POP_UP_CHAT_SEND = "(//button[@type='submit'])[2]"
DOCUMENT_FILTER = "//button[normalize-space()='Accessibility Features']"
HEADING_TITLE = "//div[.='Document Knowledge Mining']"



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



def validate_home_page(self):
self.page.wait_for_timeout(5000)
expect(self.page.locator(self.DOCUMENT_FILTER)).to_be_visible()
# expect(self.page.locator(self.DOCUMENT_FILTER)).to_be_visible()
expect(self.page.locator(self.HEADING_TITLE)).to_be_visible()
self.page.wait_for_timeout(2000)


def enter_a_question(self,text):
def enter_a_question(self, text):
self.page.locator(self.ASK_QUESTION).fill(text)
self.page.wait_for_timeout(5000)

def enter_in_search(self,text):
def enter_in_search(self, text):
self.page.locator(self.SEARCH_BOX).fill(text)
self.page.wait_for_timeout(5000)

def enter_in_popup_search(self,text):
def enter_in_popup_search(self, text):
self.page.locator(self.POP_UP_CHAT_SEARCH).fill(text)
self.page.wait_for_timeout(5000)
self.page.locator(self.POP_UP_CHAT_SEND).click()
Expand All @@ -67,7 +68,7 @@ def click_on_popup_chat(self):
self.page.locator(self.POP_UP_CHAT).click()
self.page.wait_for_timeout(5000)

def close_pop_up(self):
def close_pop_up(self):
self.page.locator(self.CLOSE_POP_UP).click()
self.page.wait_for_timeout(2000)
self.page.locator(self.CLLEAR_ALL_POP_UP).click()
Expand All @@ -78,15 +79,15 @@ def select_handwritten_doc(self):
self.page.locator(self.HANDWRITTEN_DOC2).click()
self.page.locator(self.HANDWRITTEN_DOC3).click()
self.page.wait_for_timeout(2000)

def click_send_button(self):
# Click on send button in question area
self.page.locator(self.SEND_BUTTON).click()
self.page.wait_for_timeout(5000)

#self.page.wait_for_load_state('networkidle')
# self.page.wait_for_load_state('networkidle')

def wait_until_response_loaded(self,timeout=200000):
def wait_until_response_loaded(self, timeout=200000):
start_time = time.time()
interval = 0.1
end_time = start_time + timeout / 1000
Expand All @@ -97,17 +98,18 @@ def wait_until_response_loaded(self,timeout=200000):
return
time.sleep(interval)

raise PlaywrightTimeoutError("Response is not generated and it has been timed out.")
raise PlaywrightTimeoutError(
"Response is not generated and it has been timed out."
)
# try:
# # Wait for it to appear in the DOM and be visible
# locator = self.page.locator(self.ASK_QUESTION)
# locator.wait_for(state="enabled", timeout=200000) # adjust timeout as needed
# except PlaywrightTimeoutError:
# raise Exception("Response is not generated and it has been timed out.")


def wait_until_chat_details_response_loaded(self,timeout=200000):


def wait_until_chat_details_response_loaded(self, timeout=200000):

start_time = time.time()
interval = 0.1
end_time = start_time + timeout / 1000
Expand All @@ -118,30 +120,26 @@ def wait_until_chat_details_response_loaded(self,timeout=200000):
return
time.sleep(interval)

raise PlaywrightTimeoutError("Response is not generated and it has been timed out.")


raise PlaywrightTimeoutError(
"Response is not generated and it has been timed out."
)

def click_new_topic(self):
self.page.locator(self.NEWTOPIC).click()
self.page.wait_for_timeout(2000)
self.page.wait_for_load_state('networkidle')
self.page.wait_for_load_state("networkidle")

def get_follow_ques_text(self):
follow_up_question = self.page.locator(self.Suggested_follow_up_questions).text_content()
follow_up_question = self.page.locator(
self.Suggested_follow_up_questions
).text_content()
return follow_up_question

def click_suggested_question(self):
def click_suggested_question(self):
self.page.locator(self.Suggested_follow_up_questions).click()
self.page.wait_for_timeout(2000)
self.page.wait_for_load_state('networkidle')


self.page.wait_for_load_state("networkidle")

def click_on_contract_details(self):
self.page.locator(self.CONTRACTS_DETAILS_PAGE).click()
self.page.wait_for_timeout(12000)




6 changes: 3 additions & 3 deletions tests/e2e-test/pages/loginPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class LoginPage(BasePage):
def __init__(self, page):
self.page = page

def authenticate(self, username,password):
def authenticate(self, username, password):
# login with username and password in web url
self.page.locator(self.EMAIL_TEXT_BOX).fill(username)
self.page.locator(self.NEXT_BUTTON).click()
# Wait for the password input field to be available and fill it
self.page.wait_for_load_state('networkidle')
self.page.wait_for_load_state("networkidle")
# Enter password
self.page.locator(self.PASSWORD_TEXT_BOX).fill(password)
# Click on SignIn button
Expand All @@ -33,4 +33,4 @@ def authenticate(self, username,password):
self.page.locator(self.YES_BUTTON).click()
self.page.wait_for_timeout(10000)
# Wait for the "Articles" button to be available and click it
self.page.wait_for_load_state('networkidle')
self.page.wait_for_load_state("networkidle")
Loading