Skip to content

Commit 9851ca7

Browse files
Refactor code for improved readability and maintainability: clean up imports, adjust formatting, and enhance comments across multiple files
1 parent 20d4594 commit 9851ca7

File tree

8 files changed

+84
-89
lines changed

8 files changed

+84
-89
lines changed

tests/e2e-test/base/__init__.py

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

tests/e2e-test/base/base.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
1-
from config.constants import *
2-
import requests
3-
import json
1+
from config.constants import API_URL
42
from dotenv import load_dotenv
5-
import os
3+
64

75
class BasePage:
86
def __init__(self, page):
97
self.page = page
108

11-
def scroll_into_view(self,locator):
9+
def scroll_into_view(self, locator):
1210
reference_list = locator
13-
locator.nth(reference_list.count()-1).scroll_into_view_if_needed()
11+
locator.nth(reference_list.count() - 1).scroll_into_view_if_needed()
1412

15-
def is_visible(self,locator):
13+
def is_visible(self, locator):
1614
locator.is_visible()
1715

1816
def validate_response_status(self):
19-
17+
2018
load_dotenv()
21-
19+
2220
# The URL of the API endpoint you want to access
2321
api_url = f"{API_URL}/api/plans"
2422

2523
headers = {
2624
"Accept": "*/*",
2725
}
2826

29-
3027
# Make the GET request
3128
response = self.page.request.get(api_url, headers=headers, timeout=120000)
3229

3330
# Check the response status code with custom error message
3431
try:
3532
assert response.status == 200
3633
except AssertionError:
37-
raise AssertionError(f"Expected response code 200, but got {response.status}. Response body: {response.text()}")
34+
raise AssertionError(
35+
f"Expected response code 200, but got {response.status}. Response body: {response.text()}"
36+
)

tests/e2e-test/config/constants.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
from dotenv import load_dotenv
21
import os
3-
import re
42
from datetime import datetime, timedelta
53

4+
from dotenv import load_dotenv
65

76
load_dotenv()
8-
URL = os.getenv('url')
9-
if URL.endswith('/'):
7+
URL = os.getenv("url")
8+
if URL.endswith("/"):
109
URL = URL[:-1]
1110

1211
load_dotenv()
13-
API_URL = os.getenv('api_url')
14-
if API_URL.endswith('/'):
12+
API_URL = os.getenv("api_url")
13+
if API_URL.endswith("/"):
1514
API_URL = API_URL[:-1]
1615

1716
# Calculate today's date + 10 days
@@ -24,4 +23,3 @@
2423
employee_details = f"Employee name - jessica, laptop model - Dell xps 15, email [email protected], Orientation date - {new_orientation_date}"
2524
product_details = "product name- Apple TV"
2625
prompt_question3 = "Manage a customer retention program"
27-

tests/e2e-test/pages/BIAB.py

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,90 +3,93 @@
33

44

55
class BIABPage(BasePage):
6-
WELCOME_PAGE_TITLE = "//span[normalize-space()='Multi-Agent-Custom-Automation-Engine']"
7-
NEW_TASK_PROMPT="//textarea[@id='newTaskPrompt']"
8-
SEND_BUTTON= "//button[@class='send-button']"
9-
TASK_LIST= "//span[contains(text(),'1.')]"
10-
NEW_TASK="//button[@id='newTaskButton']"
11-
MOBILE_PLAN="//div[@class='columns']//div[1]//div[1]//div[1]"
12-
MOBILE_TASK1="//span[contains(text(),'1.')]"
13-
MOBILE_TASK2="//span[contains(text(),'2.')]"
14-
MOBILE_APPROVE_TASK1="i[title='Approve']"
15-
ADDITIONAL_INFO="//textarea[@id='taskMessageTextarea']"
16-
ADDITIONAL_INFO_SEND_BUTTON="//button[@id='taskMessageAddButton']"
17-
STAGES= "//i[@title='Approve']"
6+
WELCOME_PAGE_TITLE = (
7+
"//span[normalize-space()='Multi-Agent-Custom-Automation-Engine']"
8+
)
9+
NEW_TASK_PROMPT = "//textarea[@id='newTaskPrompt']"
10+
SEND_BUTTON = "//button[@class='send-button']"
11+
TASK_LIST = "//span[contains(text(),'1.')]"
12+
NEW_TASK = "//button[@id='newTaskButton']"
13+
MOBILE_PLAN = "//div[@class='columns']//div[1]//div[1]//div[1]"
14+
MOBILE_TASK1 = "//span[contains(text(),'1.')]"
15+
MOBILE_TASK2 = "//span[contains(text(),'2.')]"
16+
MOBILE_APPROVE_TASK1 = "i[title='Approve']"
17+
ADDITIONAL_INFO = "//textarea[@id='taskMessageTextarea']"
18+
ADDITIONAL_INFO_SEND_BUTTON = "//button[@id='taskMessageAddButton']"
19+
STAGES = "//i[@title='Approve']"
1820

19-
20-
2121
def __init__(self, page):
2222
super().__init__(page)
2323
self.page = page
2424

2525
def click_my_task(self):
2626
# self.page.locator(self.TASK_LIST).click()
2727
# self.page.wait_for_timeout(2000)
28-
self.page.locator(self.TASK_LIST).click()
28+
self.page.locator(self.TASK_LIST).click()
2929
self.page.wait_for_timeout(10000)
3030

31-
def enter_aditional_info(self,text):
32-
additional_info = self.page.frame('viewIframe').locator(self.ADDITIONAL_INFO)
31+
def enter_aditional_info(self, text):
32+
additional_info = self.page.frame("viewIframe").locator(self.ADDITIONAL_INFO)
3333

34-
if(additional_info).is_enabled():
34+
if (additional_info).is_enabled():
3535
additional_info.fill(text)
3636
self.page.wait_for_timeout(5000)
3737
# Click on send button in question area
38-
self.page.frame('viewIframe').locator(self.ADDITIONAL_INFO_SEND_BUTTON).click()
38+
self.page.frame("viewIframe").locator(
39+
self.ADDITIONAL_INFO_SEND_BUTTON
40+
).click()
3941
self.page.wait_for_timeout(5000)
4042

4143
def click_send_button(self):
4244
# Click on send button in question area
43-
self.page.frame('viewIframe').locator(self.SEND_BUTTON).click()
45+
self.page.frame("viewIframe").locator(self.SEND_BUTTON).click()
4446
self.page.wait_for_timeout(25000)
45-
#self.page.wait_for_load_state('networkidle')
47+
# self.page.wait_for_load_state('networkidle')
4648

4749
def validate_rai_validation_message(self):
4850
# Click on send button in question area
49-
self.page.frame('viewIframe').locator(self.SEND_BUTTON).click()
51+
self.page.frame("viewIframe").locator(self.SEND_BUTTON).click()
5052
self.page.wait_for_timeout(1000)
51-
expect(self.page.frame('viewIframe').locator("//div[@class='notyf-announcer']")).to_have_text("Unable to create plan for this task.")
53+
expect(
54+
self.page.frame("viewIframe").locator("//div[@class='notyf-announcer']")
55+
).to_have_text("Unable to create plan for this task.")
5256
self.page.wait_for_timeout(3000)
5357

5458
def click_aditional_send_button(self):
5559
# Click on send button in question area
56-
self.page.frame('viewIframe').locator(self.ADDITIONAL_INFO_SEND_BUTTON).click()
60+
self.page.frame("viewIframe").locator(self.ADDITIONAL_INFO_SEND_BUTTON).click()
5761
self.page.wait_for_timeout(5000)
5862

5963
def click_new_task(self):
6064
self.page.locator(self.NEW_TASK).click()
6165
self.page.wait_for_timeout(5000)
6266

6367
def click_mobile_plan(self):
64-
self.page.frame('viewIframe').locator(self.MOBILE_PLAN).click()
68+
self.page.frame("viewIframe").locator(self.MOBILE_PLAN).click()
6569
self.page.wait_for_timeout(3000)
6670

6771
def validate_home_page(self):
6872
expect(self.page.locator(self.WELCOME_PAGE_TITLE)).to_be_visible()
6973

70-
71-
def enter_a_question(self,text):
74+
def enter_a_question(self, text):
7275
# Type a question in the text area
73-
#self.page.pause()
74-
self.page.frame('viewIframe').locator(self.NEW_TASK_PROMPT).fill(text)
76+
# self.page.pause()
77+
self.page.frame("viewIframe").locator(self.NEW_TASK_PROMPT).fill(text)
7578
self.page.wait_for_timeout(5000)
7679

77-
7880
def processing_different_stage(self):
79-
if self.page.frame('viewIframe').locator(self.STAGES).count() >= 1:
80-
for i in range(self.page.frame('viewIframe').locator(self.STAGES).count()):
81-
approve_stages = self.page.frame('viewIframe').locator(self.STAGES).nth(0)
81+
if self.page.frame("viewIframe").locator(self.STAGES).count() >= 1:
82+
for i in range(self.page.frame("viewIframe").locator(self.STAGES).count()):
83+
approve_stages = (
84+
self.page.frame("viewIframe").locator(self.STAGES).nth(0)
85+
)
8286
approve_stages.click()
83-
self.page.wait_for_timeout(10000)
87+
self.page.wait_for_timeout(10000)
8488
BasePage.validate_response_status(self)
85-
self.page.wait_for_timeout(10000)
86-
expect(self.page.frame('viewIframe').locator("//tag[@id='taskStatusTag']")).to_have_text("Completed")
87-
expect(self.page.frame('viewIframe').locator("//div[@id='taskProgressPercentage']")).to_have_text("100%")
88-
89-
90-
91-
92-
89+
self.page.wait_for_timeout(10000)
90+
expect(
91+
self.page.frame("viewIframe").locator("//tag[@id='taskStatusTag']")
92+
).to_have_text("Completed")
93+
expect(
94+
self.page.frame("viewIframe").locator("//div[@id='taskProgressPercentage']")
95+
).to_have_text("100%")

tests/e2e-test/pages/__init__.py

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

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")

tests/e2e-test/tests/conftest.py

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
1-
from pathlib import Path
1+
import os
2+
23
import pytest
4+
from config.constants import URL
35
from playwright.sync_api import sync_playwright
4-
from config.constants import *
5-
from slugify import slugify
6-
from pages.loginPage import LoginPage
7-
from dotenv import load_dotenv
8-
import os
9-
from py.xml import html # type: ignore
6+
from py.xml import html # type: ignore
107

118

129
@pytest.fixture(scope="session")
@@ -20,8 +17,8 @@ def login_logout():
2017
# Navigate to the login URL
2118
page.goto(URL)
2219
# Wait for the login form to appear
23-
page.wait_for_load_state('networkidle')
24-
20+
page.wait_for_load_state("networkidle")
21+
2522
yield page
2623

2724
# perform close the browser
@@ -33,13 +30,16 @@ def pytest_html_report_title(report):
3330
report.title = "Automation_MACAE"
3431

3532

36-
3733
# Add a column for descriptions
3834
def pytest_html_results_table_header(cells):
3935
cells.insert(1, html.th("Description"))
4036

37+
4138
def pytest_html_results_table_row(report, cells):
42-
cells.insert(1, html.td(report.description if hasattr(report, "description") else ""))
39+
cells.insert(
40+
1, html.td(report.description if hasattr(report, "description") else "")
41+
)
42+
4343

4444
# Add logs and docstring to report
4545
@pytest.hookimpl(hookwrapper=True)
@@ -48,6 +48,5 @@ def pytest_runtest_makereport(item, call):
4848
report = outcome.get_result()
4949
report.description = str(item.function.__doc__)
5050
os.makedirs("logs", exist_ok=True)
51-
extra = getattr(report, 'extra', [])
51+
extra = getattr(report, "extra", [])
5252
report.extra = extra
53-
Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
from pages.BIAB import BIABPage
2-
from config.constants import *
3-
41
import logging
52

3+
from config.constants import prompt_question1, prompt_question2, rai_prompt, employee_details, product_details
4+
from pages.BIAB import BIABPage
5+
66
logger = logging.getLogger(__name__)
77

88

99
def test_biab_PAGE_AUTOMATION(login_logout):
10-
"""Validate Golden path test case for Multi-Agent-Custom-Automation-Engine """
10+
"""Validate Golden path test case for Multi-Agent-Custom-Automation-Engine"""
1111
page = login_logout
1212
biab_page = BIABPage(page)
1313
logger.info("Step 1: Validate home page is loaded.")
@@ -17,15 +17,15 @@ def test_biab_PAGE_AUTOMATION(login_logout):
1717
biab_page.click_send_button()
1818
biab_page.click_my_task()
1919
biab_page.enter_aditional_info(employee_details)
20-
#biab_page.click_aditional_send_button()
20+
# biab_page.click_aditional_send_button()
2121
biab_page.processing_different_stage()
2222
biab_page.click_new_task()
2323
logger.info("Step 3: Validate Run Sample prompt2 & run plans")
2424
biab_page.enter_a_question(prompt_question2)
2525
biab_page.click_send_button()
2626
biab_page.click_my_task()
2727
biab_page.enter_aditional_info(product_details)
28-
#biab_page.click_aditional_send_button()
28+
# biab_page.click_aditional_send_button()
2929
biab_page.processing_different_stage()
3030
biab_page.click_new_task()
3131
logger.info("Step 4: Validate Run Sample prompt3 from Quick Tasks & run plans")
@@ -34,10 +34,8 @@ def test_biab_PAGE_AUTOMATION(login_logout):
3434
biab_page.click_my_task()
3535
biab_page.processing_different_stage()
3636
biab_page.click_new_task()
37-
logger.info("Step 5: Validate Run known RAI test prompts to ensure that you get the toast saying that a plan cannot be generated")
37+
logger.info(
38+
"Step 5: Validate Run known RAI test prompts to ensure that you get the toast saying that a plan cannot be generated"
39+
)
3840
biab_page.enter_a_question(rai_prompt)
3941
biab_page.validate_rai_validation_message()
40-
41-
42-
43-

0 commit comments

Comments
 (0)