Skip to content

Commit 1b2c017

Browse files
refactor: reorganize imports and clean up code formatting across multiple files
1 parent 425affc commit 1b2c017

10 files changed

Lines changed: 89 additions & 71 deletions

File tree

playwright-tests/base/__init__.py

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

playwright-tests/base/base.py

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
from config.constants import *
2-
import requests
31
import json
4-
from dotenv import load_dotenv
52
import os
63

4+
import requests
5+
from dotenv import load_dotenv
6+
7+
from config.constants import URL
8+
9+
710
class BasePage:
811
def __init__(self, page=None):
912
self.page = page
@@ -19,7 +22,7 @@ def validate_response_status(self, question_api=""):
1922
load_dotenv() # Ensure environment variables are loaded
2023
# URL of the API endpoint
2124
url = f"{URL}/conversation"
22-
25+
2326
# Prepare headers
2427
headers = {
2528
"Content-Type": "application/json",
@@ -34,61 +37,66 @@ def validate_response_status(self, question_api=""):
3437
"id": "cb9e6c49-0e8c-5f3e-4928-57e55e26896f",
3538
"role": "user",
3639
"content": question_api, # Use the passed question
37-
"date": "2024-12-18T07:49:23.413Z"
40+
"date": "2024-12-18T07:49:23.413Z",
3841
}
39-
]
42+
],
4043
}
41-
42-
43-
# Make the POST request
44-
response = self.page.request.post(url, headers=headers,data=json.dumps(payload), timeout=120000)
45-
assert response.status == 200, "response code is "+str(response.status)+" "+str(response.json())
46-
47-
48-
44+
45+
# Make the POST request
46+
response = self.page.request.post(
47+
url, headers=headers, data=json.dumps(payload), timeout=120000
48+
)
49+
assert response.status == 200, (
50+
"response code is " + str(response.status) + " " + str(response.json())
51+
)
52+
4953
def validate_draft_response_status(self, section_title, topic_text):
5054
load_dotenv() # Ensure environment variables are loaded
51-
52-
client_id = os.getenv('client_id')
53-
client_secret = os.getenv('client_secret')
54-
tenant_id = os.getenv('tenant_id')
55+
56+
client_id = os.getenv("client_id")
57+
client_secret = os.getenv("client_secret")
58+
tenant_id = os.getenv("tenant_id")
5559
token_url = f"https://login.microsoft.com/{tenant_id}/oauth2/v2.0/token"
5660

5761
# URL for generating draft section
5862
url = f"{URL}/draft_document/generate_section"
5963

6064
# Prepare data for token request
6165
data = {
62-
'grant_type': 'client_credentials',
63-
'client_id': client_id,
64-
'client_secret': client_secret,
65-
'scope': f'api://{client_id}/.default'
66+
"grant_type": "client_credentials",
67+
"client_id": client_id,
68+
"client_secret": client_secret,
69+
"scope": f"api://{client_id}/.default",
6670
}
6771

6872
try:
6973
# Request the token
7074
response = requests.post(token_url, data=data)
71-
75+
7276
if response.status_code == 200:
7377
token_info = response.json()
74-
access_token = token_info['access_token']
78+
access_token = token_info["access_token"]
7579
headers = {
76-
'Authorization': f'Bearer {access_token}',
77-
"Content-Type": "application/json"
80+
"Authorization": f"Bearer {access_token}",
81+
"Content-Type": "application/json",
7882
}
7983
payload = {
8084
"grantTopic": topic_text,
8185
"sectionContext": "",
82-
"sectionTitle": section_title
86+
"sectionTitle": section_title,
8387
}
8488

8589
# Make the POST request for draft section generation
8690
response = requests.post(url, headers=headers, data=json.dumps(payload))
8791

8892
# Check if the response status is not 200
8993
if response.status_code != 200:
90-
print(f"Error: {response.status_code}, Response Text: {response.text}")
91-
raise Exception(f"Request failed with status code {response.status_code}")
94+
print(
95+
f"Error: {response.status_code}, Response Text: {response.text}"
96+
)
97+
raise Exception(
98+
f"Request failed with status code {response.status_code}"
99+
)
92100

93101
# Attempt to parse the response as JSON
94102
response_data = response.json()

playwright-tests/config/constants.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
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+
URL = os.getenv("url")
67

7-
if URL.endswith('/'):
8+
if URL.endswith("/"):
89
URL = URL[:-1]
9-
10+
1011

1112
# browse input data
1213
browse_question1 = "What are typical sections in a promissory note?"

playwright-tests/pages/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +0,0 @@
1-
from. import homePage
2-
from. import browsePage
3-
from. import generatePage
4-
from. import draftPage

playwright-tests/pages/browsePage.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from base.base import BasePage
22

3+
34
class BrowsePage(BasePage):
45
TYPE_QUESTION = "//textarea[@placeholder='Type a new question...']"
56
SEND_BUTTON = "//div[@aria-label='Ask question button']"
@@ -16,34 +17,37 @@ def enter_a_question(self, text):
1617
self.page.locator(self.TYPE_QUESTION).fill(text)
1718
self.page.wait_for_timeout(2000)
1819

19-
def click_send_button(self ):
20+
def click_send_button(self):
2021
# Type a question in the text area
2122
self.page.locator(self.SEND_BUTTON).click()
2223
self.page.wait_for_timeout(10000)
2324

24-
def click_generate_button(self ):
25+
def click_generate_button(self):
2526
# Type a question in the text area
2627
self.page.locator(self.GENERATE_BUTTON).click()
2728
self.page.wait_for_timeout(5000)
29+
2830
def click_reference_link_in_response(self):
2931
# Click on reference link response
30-
BasePage.scroll_into_view(self, self.page.locator(self.REFERENCE_LINKS_IN_RESPONSE))
32+
BasePage.scroll_into_view(
33+
self, self.page.locator(self.REFERENCE_LINKS_IN_RESPONSE)
34+
)
3135
self.page.wait_for_timeout(2000)
3236
reference_links = self.page.locator(self.REFERENCE_LINKS_IN_RESPONSE)
3337
reference_links.nth(reference_links.count() - 1).click()
3438
# self.page.locator(self.REFERENCE_LINKS_IN_RESPONSE).click()
35-
self.page.wait_for_load_state('networkidle')
39+
self.page.wait_for_load_state("networkidle")
3640
self.page.wait_for_timeout(2000)
37-
41+
3842
def click_expand_reference_in_response(self):
3943
# Click on expand in response reference area
4044
self.page.wait_for_timeout(5000)
4145
expand_icon = self.page.locator(self.RESPONSE_REFERENCE_EXPAND_ICON)
4246
expand_icon.nth(expand_icon.count() - 1).click()
43-
self.page.wait_for_load_state('networkidle')
47+
self.page.wait_for_load_state("networkidle")
4448
self.page.wait_for_timeout(2000)
45-
49+
4650
def close_citation(self):
4751
self.page.wait_for_timeout(3000)
4852
self.page.locator(self.CLOSE_BUTTON).click()
49-
self.page.wait_for_timeout(2000)
53+
self.page.wait_for_timeout(2000)
Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from base.base import BasePage
21
from pytest_check import check
32

3+
from base.base import BasePage
4+
45

56
class DraftPage(BasePage):
67
# Principal_Amount_and_Date = "div:nth-child(3) div:nth-child(2) span:nth-child(1) textarea:nth-child(1)"
@@ -10,8 +11,7 @@ class DraftPage(BasePage):
1011
Draft_headings = "//span[@class='fui-Text ___nl2uoq0 fk6fouc f4ybsrx f1i3iumi f16wzh4i fpgzoln f1w7gpdv f6juhto f1gl81tg f2jf649 fepr9ql febqm8h']"
1112
invalid_response = "The requested information is not available in the retrieved data. Please try another query or topic."
1213
invalid_response1 = "There was an issue fetching your data. Please try again."
13-
invalid_response2 = " "
14-
14+
invalid_response2 = " "
1515

1616
def __init__(self, page):
1717
self.page = page
@@ -21,6 +21,17 @@ def check_draft_Sections(self):
2121
for i in range(self.page.locator(self.Draft_Sections).count()):
2222
draft_sections_response = self.page.locator(self.Draft_Sections).nth(i)
2323
draft_heading = self.page.locator(self.Draft_headings).nth(i).text_content()
24-
check.not_equal(self.invalid_response, draft_sections_response.text_content(),f'Invalid response for {draft_heading} section')
25-
check.not_equal(self.invalid_response1, draft_sections_response.text_content(), f'Invalid response for {draft_heading} section' )
26-
check.is_not_none(draft_sections_response.text_content(), f'Invalid response for {draft_heading} section')
24+
check.not_equal(
25+
self.invalid_response,
26+
draft_sections_response.text_content(),
27+
f"Invalid response for {draft_heading} section",
28+
)
29+
check.not_equal(
30+
self.invalid_response1,
31+
draft_sections_response.text_content(),
32+
f"Invalid response for {draft_heading} section",
33+
)
34+
check.is_not_none(
35+
draft_sections_response.text_content(),
36+
f"Invalid response for {draft_heading} section",
37+
)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from base.base import BasePage
22

3+
34
class GeneratePage(BasePage):
4-
GENERATE_DRAFT="//button[@title='Generate Draft']"
5+
GENERATE_DRAFT = "//button[@title='Generate Draft']"
56
TYPE_QUESTION = "//textarea[@placeholder='Type a new question...']"
67
SEND_BUTTON = "//div[@aria-label='Ask question button']"
78

8-
99
def __init__(self, page):
1010
self.page = page
1111

@@ -14,12 +14,12 @@ def enter_a_question(self, text):
1414
self.page.locator(self.TYPE_QUESTION).fill(text)
1515
self.page.wait_for_timeout(2000)
1616

17-
def click_send_button(self ):
17+
def click_send_button(self):
1818
# Type a question in the text area
1919
self.page.locator(self.SEND_BUTTON).click()
2020
self.page.wait_for_timeout(20000)
2121

22-
def click_generate_draft_button(self ):
22+
def click_generate_draft_button(self):
2323
# Type a question in the text area
2424
self.page.locator(self.GENERATE_DRAFT).click()
25-
self.page.wait_for_timeout(15000)
25+
self.page.wait_for_timeout(15000)

playwright-tests/pages/homePage.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from base.base import BasePage
22

3+
34
class HomePage(BasePage):
45
BROWSE_BUTTON = "//p[contains(text(),'Let AI search through your files and provide answe')]"
56

6-
7-
87
def __init__(self, page):
98
self.page = page
109

1110
def click_browse_button(self):
12-
# click on BROWSE
13-
self.page.wait_for_timeout(3000)
11+
# click on BROWSE
12+
self.page.wait_for_timeout(3000)
1413
self.page.locator(self.BROWSE_BUTTON).click()
15-
self.page.wait_for_timeout(5000)
14+
self.page.wait_for_timeout(5000)

playwright-tests/tests/conftest.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from pathlib import Path
2+
23
import pytest
34
from playwright.sync_api import sync_playwright
4-
from config.constants import *
55
from slugify import slugify
6-
from dotenv import load_dotenv
7-
import os
6+
7+
from config.constants import URL
88

99

1010
@pytest.fixture(scope="session")
@@ -18,7 +18,7 @@ def login_logout():
1818
# Navigate to the login URL
1919
page.goto(URL)
2020
# Wait for the login form to appear
21-
#page.wait_for_load_state('networkidle')
21+
# page.wait_for_load_state('networkidle')
2222
yield page
2323

2424
# perform close the browser
@@ -34,7 +34,7 @@ def pytest_html_report_title(report):
3434
def pytest_runtest_makereport(item, call):
3535
pytest_html = item.config.pluginmanager.getplugin("html")
3636
outcome = yield
37-
screen_file = ''
37+
screen_file = ""
3838
report = outcome.get_result()
3939
extra = getattr(report, "extra", [])
4040
if report.when == "call":

playwright-tests/tests/test_poc_docgen.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
from pages.draftPage import DraftPage
1+
from config.constants import browse_question1, browse_question2, generate_question1
22
from pages.browsePage import BrowsePage
3+
from pages.draftPage import DraftPage
34
from pages.generatePage import GeneratePage
45
from pages.homePage import HomePage
5-
from config.constants import *
6+
67

78
def test_DKM_GOLDENPATH(login_logout):
89
page = login_logout
@@ -12,7 +13,7 @@ def test_DKM_GOLDENPATH(login_logout):
1213
browse_page = BrowsePage(page)
1314
browse_page.enter_a_question(browse_question1)
1415
browse_page.click_send_button()
15-
# validate response
16+
# validate response
1617
browse_page.validate_response_status(question_api=browse_question1)
1718
browse_page.click_expand_reference_in_response()
1819
browse_page.click_reference_link_in_response()
@@ -33,4 +34,3 @@ def test_DKM_GOLDENPATH(login_logout):
3334
generate_page.click_generate_draft_button()
3435
draft_page = DraftPage(page)
3536
draft_page.check_draft_Sections()
36-

0 commit comments

Comments
 (0)