Skip to content

Commit 0dd9491

Browse files
test: DKM-Fixed issues and updated script for validating response status
2 parents 6c08ca9 + 9024f3f commit 0dd9491

File tree

9 files changed

+187
-160
lines changed

9 files changed

+187
-160
lines changed

tests/e2e-test/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ This will create a virtual environment directory named microsoft inside your cur
2020
Installing Playwright Pytest from Virtual Environment
2121

2222
- To install libraries run "pip install -r requirements.txt"
23+
- To install Playwright run "playwright install"
2324

2425
Run test cases
2526

tests/e2e-test/base/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
from . import base
1+
"""Initiate base package"""

tests/e2e-test/base/base.py

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,48 @@
1-
from config.constants import *
2-
import requests
31
import json
4-
from dotenv import load_dotenv
5-
import os
2+
3+
from config.constants import URL
4+
65

76
class BasePage:
87
def __init__(self, page):
98
self.page = page
109

11-
def scroll_into_view(self,locator):
10+
async def scroll_into_view(self, locator):
1211
reference_list = locator
13-
locator.nth(reference_list.count()-1).scroll_into_view_if_needed()
12+
await locator.nth(reference_list.count() - 1).scroll_into_view_if_needed()
1413

15-
def is_visible(self,locator):
16-
locator.is_visible()
14+
async def is_visible(self, locator):
15+
return await locator.is_visible()
1716

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

2321
headers = {
2422
"Content-Type": "application/json",
2523
"Accept": "*/*",
2624
}
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)
3225

33-
# Check the response status code
34-
assert response.status == 200, "Response code is " + str(response.status) + " " + str(response.json())
26+
payload = {"Question": question_api}
27+
28+
try:
29+
response = await self.page.context.request.post(
30+
url=url, headers=headers, data=json.dumps(payload), timeout=200_000
31+
)
32+
33+
error_msg = f"Response code is {response.status}"
34+
try:
35+
response_json = await response.json()
36+
error_msg += f" Response: {response_json}"
37+
except Exception:
38+
response_text = await response.text()
39+
error_msg += f" Response text: {response_text}"
40+
41+
assert response.status == expected_status, error_msg
42+
43+
await self.page.wait_for_timeout(4000)
44+
return response
3545

36-
46+
except Exception as e:
47+
print(f"Request failed: {e}")
48+
raise

tests/e2e-test/config/constants.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
from dotenv import load_dotenv
21
import os
32

3+
from dotenv import load_dotenv
4+
45
load_dotenv()
5-
URL = os.getenv('url')
6-
if URL.endswith('/'):
6+
URL = os.getenv("url")
7+
if URL.endswith("/"):
78
URL = URL[:-1]
89

910
# DKM input data
1011
chat_question1 = "What are the main factors contributing to the current housing affordability issues?"
1112
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?"
13+
house_10_11_question = "Can you summarize and compare the tables on page 10 and 11?"
14+
handwritten_question1 = "Analyze these forms and create a table with all buyers, sellers, and corresponding purchase prices."
15+
search_1 = "Housing Report"
16+
search_2 = "Contracts"
17+
contract_details_question = (
18+
"What liabilities is the buyer responsible for within the contract?"
19+
)

tests/e2e-test/pages/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
from. import loginPage
2-
from. import dkmPage
1+
"""Initiate pages package"""

tests/e2e-test/pages/dkmPage.py

Lines changed: 43 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,54 @@
1-
from base.base import BasePage
2-
from playwright.sync_api import expect
31
import time
2+
43
from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
4+
from playwright.sync_api import expect
5+
6+
from base.base import BasePage
7+
58

69
class DkmPage(BasePage):
710
WELCOME_PAGE_TITLE = "(//div[@class='order-5 my-auto pb-3 text-lg font-semibold leading-tight text-white mt-3'])[1]"
811
NEWTOPIC = "//button[normalize-space()='New Topic']"
9-
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)"
12+
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)"
1013
SCROLL_DOWN = "//div[10]//div[2]//div[2]//i[1]//img[1]"
11-
ASK_QUESTION ="//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)']"
12-
SEARCH_BOX="//input[@type='search']"
13-
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]"
14-
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]"
14+
ASK_QUESTION = (
15+
"//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)']"
16+
)
17+
SEARCH_BOX = "//input[@type='search']"
18+
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]"
19+
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]"
1520
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)"
16-
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)"
17-
POP_UP_CHAT="//button[@value='Chat Room']"
18-
CLOSE_POP_UP ="//button[@aria-label='close']"
19-
CLLEAR_ALL_POP_UP ="//button[normalize-space()='Clear all']"
20-
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]"
21-
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]"
22-
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]"
21+
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)"
22+
POP_UP_CHAT = "//button[@value='Chat Room']"
23+
CLOSE_POP_UP = "//button[@aria-label='close']"
24+
CLLEAR_ALL_POP_UP = "//button[normalize-space()='Clear all']"
25+
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]"
26+
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]"
27+
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]"
2328
SEND_BUTTON = "//button[@aria-label='Send']"
2429
POP_UP_CHAT_SEARCH = "(//textarea[@placeholder='Ask a question or request (ctrl + enter to submit)'])[2]"
2530
POP_UP_CHAT_SEND = "(//button[@type='submit'])[2]"
2631
DOCUMENT_FILTER = "//button[normalize-space()='Accessibility Features']"
2732
HEADING_TITLE = "//div[.='Document Knowledge Mining']"
28-
29-
33+
3034
def __init__(self, page):
3135
self.page = page
3236

33-
34-
3537
def validate_home_page(self):
3638
self.page.wait_for_timeout(5000)
37-
expect(self.page.locator(self.DOCUMENT_FILTER)).to_be_visible()
39+
# expect(self.page.locator(self.DOCUMENT_FILTER)).to_be_visible()
3840
expect(self.page.locator(self.HEADING_TITLE)).to_be_visible()
3941
self.page.wait_for_timeout(2000)
4042

41-
42-
def enter_a_question(self,text):
43+
def enter_a_question(self, text):
4344
self.page.locator(self.ASK_QUESTION).fill(text)
4445
self.page.wait_for_timeout(5000)
4546

46-
def enter_in_search(self,text):
47+
def enter_in_search(self, text):
4748
self.page.locator(self.SEARCH_BOX).fill(text)
4849
self.page.wait_for_timeout(5000)
4950

50-
def enter_in_popup_search(self,text):
51+
def enter_in_popup_search(self, text):
5152
self.page.locator(self.POP_UP_CHAT_SEARCH).fill(text)
5253
self.page.wait_for_timeout(5000)
5354
self.page.locator(self.POP_UP_CHAT_SEND).click()
@@ -67,7 +68,7 @@ def click_on_popup_chat(self):
6768
self.page.locator(self.POP_UP_CHAT).click()
6869
self.page.wait_for_timeout(5000)
6970

70-
def close_pop_up(self):
71+
def close_pop_up(self):
7172
self.page.locator(self.CLOSE_POP_UP).click()
7273
self.page.wait_for_timeout(2000)
7374
self.page.locator(self.CLLEAR_ALL_POP_UP).click()
@@ -78,15 +79,15 @@ def select_handwritten_doc(self):
7879
self.page.locator(self.HANDWRITTEN_DOC2).click()
7980
self.page.locator(self.HANDWRITTEN_DOC3).click()
8081
self.page.wait_for_timeout(2000)
81-
82+
8283
def click_send_button(self):
8384
# Click on send button in question area
8485
self.page.locator(self.SEND_BUTTON).click()
8586
self.page.wait_for_timeout(5000)
8687

87-
#self.page.wait_for_load_state('networkidle')
88+
# self.page.wait_for_load_state('networkidle')
8889

89-
def wait_until_response_loaded(self,timeout=200000):
90+
def wait_until_response_loaded(self, timeout=200000):
9091
start_time = time.time()
9192
interval = 0.1
9293
end_time = start_time + timeout / 1000
@@ -97,17 +98,18 @@ def wait_until_response_loaded(self,timeout=200000):
9798
return
9899
time.sleep(interval)
99100

100-
raise PlaywrightTimeoutError("Response is not generated and it has been timed out.")
101+
raise PlaywrightTimeoutError(
102+
"Response is not generated and it has been timed out."
103+
)
101104
# try:
102105
# # Wait for it to appear in the DOM and be visible
103106
# locator = self.page.locator(self.ASK_QUESTION)
104107
# locator.wait_for(state="enabled", timeout=200000) # adjust timeout as needed
105108
# except PlaywrightTimeoutError:
106109
# raise Exception("Response is not generated and it has been timed out.")
107-
108-
109-
def wait_until_chat_details_response_loaded(self,timeout=200000):
110-
110+
111+
def wait_until_chat_details_response_loaded(self, timeout=200000):
112+
111113
start_time = time.time()
112114
interval = 0.1
113115
end_time = start_time + timeout / 1000
@@ -118,30 +120,26 @@ def wait_until_chat_details_response_loaded(self,timeout=200000):
118120
return
119121
time.sleep(interval)
120122

121-
raise PlaywrightTimeoutError("Response is not generated and it has been timed out.")
122-
123-
123+
raise PlaywrightTimeoutError(
124+
"Response is not generated and it has been timed out."
125+
)
124126

125127
def click_new_topic(self):
126128
self.page.locator(self.NEWTOPIC).click()
127129
self.page.wait_for_timeout(2000)
128-
self.page.wait_for_load_state('networkidle')
130+
self.page.wait_for_load_state("networkidle")
129131

130132
def get_follow_ques_text(self):
131-
follow_up_question = self.page.locator(self.Suggested_follow_up_questions).text_content()
133+
follow_up_question = self.page.locator(
134+
self.Suggested_follow_up_questions
135+
).text_content()
132136
return follow_up_question
133137

134-
def click_suggested_question(self):
138+
def click_suggested_question(self):
135139
self.page.locator(self.Suggested_follow_up_questions).click()
136140
self.page.wait_for_timeout(2000)
137-
self.page.wait_for_load_state('networkidle')
138-
139-
141+
self.page.wait_for_load_state("networkidle")
140142

141143
def click_on_contract_details(self):
142144
self.page.locator(self.CONTRACTS_DETAILS_PAGE).click()
143145
self.page.wait_for_timeout(12000)
144-
145-
146-
147-

tests/e2e-test/pages/loginPage.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class LoginPage(BasePage):
1313
def __init__(self, page):
1414
self.page = page
1515

16-
def authenticate(self, username,password):
16+
def authenticate(self, username, password):
1717
# login with username and password in web url
1818
self.page.locator(self.EMAIL_TEXT_BOX).fill(username)
1919
self.page.locator(self.NEXT_BUTTON).click()
2020
# Wait for the password input field to be available and fill it
21-
self.page.wait_for_load_state('networkidle')
21+
self.page.wait_for_load_state("networkidle")
2222
# Enter password
2323
self.page.locator(self.PASSWORD_TEXT_BOX).fill(password)
2424
# Click on SignIn button
@@ -33,4 +33,4 @@ def authenticate(self, username,password):
3333
self.page.locator(self.YES_BUTTON).click()
3434
self.page.wait_for_timeout(10000)
3535
# Wait for the "Articles" button to be available and click it
36-
self.page.wait_for_load_state('networkidle')
36+
self.page.wait_for_load_state("networkidle")

0 commit comments

Comments
 (0)