|
2 | 2 | BasePage Module |
3 | 3 | Contains base page object class with common methods |
4 | 4 | """ |
| 5 | +from config.constants import * |
5 | 6 | import json |
6 | | -import logging |
| 7 | +from dotenv import load_dotenv |
7 | 8 | import os |
8 | | -import time |
9 | 9 | import uuid |
10 | | -from dotenv import load_dotenv |
11 | | -from config.constants import API_URL |
12 | | - |
13 | | -logger = logging.getLogger(__name__) |
14 | | - |
| 10 | +import time |
15 | 11 |
|
16 | 12 | class BasePage: |
17 | | - """Base class for all page objects""" |
18 | | - |
19 | 13 | def __init__(self, page): |
20 | | - """Initialize BasePage with page instance""" |
21 | 14 | self.page = page |
22 | 15 |
|
23 | | - def scroll_into_view(self, locator): |
24 | | - """Scroll element into view""" |
| 16 | + def scroll_into_view(self,locator): |
25 | 17 | reference_list = locator |
26 | 18 | locator.nth(reference_list.count()-1).scroll_into_view_if_needed() |
27 | 19 |
|
28 | | - def is_visible(self, locator): |
29 | | - """Check if element is visible""" |
30 | | - return locator.is_visible() |
| 20 | + def is_visible(self,locator): |
| 21 | + locator.is_visible() |
31 | 22 |
|
32 | | - def validate_response_status(self, question): # pylint: disable=too-many-locals,too-many-statements |
33 | | - """ |
34 | | - Validate that the API responds with status 200 for the given question. |
35 | | - Uses Playwright's request context which maintains authentication from the browser session. |
36 | | - """ |
| 23 | + def validate_response_status(self,questions): |
37 | 24 | load_dotenv() |
38 | | - |
39 | | - url = f"{API_URL}/history/update" |
| 25 | + WEB_URL = os.getenv("web_url") |
| 26 | + |
| 27 | + url = f"{API_URL}/api/chat" |
| 28 | + |
40 | 29 |
|
41 | 30 | user_message_id = str(uuid.uuid4()) |
| 31 | + assistant_message_id = str(uuid.uuid4()) |
42 | 32 | conversation_id = str(uuid.uuid4()) |
43 | 33 |
|
44 | 34 | payload = { |
45 | | - "messages": [{"role": "assistant", "content": question, "id": user_message_id}], |
| 35 | + "messages": [{"role": "user", "content": questions, |
| 36 | + "id": user_message_id}], |
46 | 37 | "conversation_id": conversation_id, |
47 | 38 | } |
48 | | - |
| 39 | + # Serialize the payload to JSON |
| 40 | + payload_json = json.dumps(payload) |
49 | 41 | headers = { |
50 | | - "Content-Type": "application/json", |
| 42 | + "Content-Type": "application/json-lines", |
51 | 43 | "Accept": "*/*" |
52 | 44 | } |
53 | | - |
54 | | - # Log request details for debugging |
55 | | - logger.info("=" * 80) |
56 | | - logger.info("🔍 API REQUEST DEBUG INFO") |
57 | | - logger.info("=" * 80) |
58 | | - logger.info("URL: %s", url) |
59 | | - logger.info("Method: POST") |
60 | | - logger.info("Headers: %s", json.dumps(headers, indent=2)) |
61 | | - logger.info("Payload: %s", json.dumps(payload, indent=2)) |
62 | | - logger.info("Question: %s", question) |
63 | | - |
| 45 | + # response = self.page.request.post(url, headers=headers, data=payload_json, timeout=60000) |
64 | 46 | start = time.time() |
| 47 | + response = self.page.request.post(url, headers=headers, data=payload_json, timeout=90000) |
| 48 | + duration = time.time() - start |
65 | 49 |
|
66 | | - try: |
67 | | - # Using Playwright's request context to leverage browser's authentication |
68 | | - response = self.page.request.post( |
69 | | - url, |
70 | | - headers=headers, |
71 | | - data=json.dumps(payload), |
72 | | - timeout=90000 |
73 | | - ) |
74 | | - |
75 | | - duration = time.time() - start |
76 | | - |
77 | | - # Log response details for debugging |
78 | | - logger.info("-" * 80) |
79 | | - logger.info("📥 API RESPONSE DEBUG INFO") |
80 | | - logger.info("-" * 80) |
81 | | - logger.info("Status Code: %s", response.status) |
82 | | - logger.info("Response Time: %.2fs", duration) |
83 | | - |
84 | | - # Log response headers |
85 | | - try: |
86 | | - response_headers = response.headers |
87 | | - logger.info("Response Headers: %s", json.dumps(dict(response_headers), indent=2)) |
88 | | - except Exception as exc: # pylint: disable=broad-exception-caught |
89 | | - logger.warning("Could not get response headers: %s", str(exc)) |
90 | | - |
91 | | - # Get response body for debugging |
92 | | - try: |
93 | | - response_body = response.json() |
94 | | - logger.info("Response Body (JSON): %s", json.dumps(response_body, indent=2)) |
95 | | - |
96 | | - # If there's an error in the response, log it prominently |
97 | | - if "error" in response_body: |
98 | | - logger.error("🚨 API ERROR MESSAGE: %s", response_body.get("error")) |
99 | | - if "detail" in response_body: |
100 | | - logger.error("🚨 API ERROR DETAIL: %s", response_body.get("detail")) |
101 | | - |
102 | | - except Exception as exc: # pylint: disable=broad-exception-caught |
103 | | - logger.warning("Could not parse response body as JSON: %s", str(exc)) |
104 | | - try: |
105 | | - response_text = response.text() |
106 | | - # First 500 chars |
107 | | - logger.info("Response Body (Text): %s", response_text[:500]) |
108 | | - except Exception as text_error: # pylint: disable=broad-exception-caught |
109 | | - logger.error("Could not get response text: %s", str(text_error)) |
110 | | - |
111 | | - # Assert successful response |
112 | | - if response.status != 200: |
113 | | - error_msg = f"API returned status {response.status} instead of 200" |
114 | | - logger.error("❌ %s", error_msg) |
115 | | - logger.error("💡 POSSIBLE REASONS FOR 500 ERROR:") |
116 | | - logger.error( |
117 | | - " 1. Missing 'conversation_id' in payload (endpoint expects existing conversation)" |
118 | | - ) |
119 | | - logger.error(" 2. Authentication/authorization issue") |
120 | | - logger.error(" 3. Invalid payload structure") |
121 | | - logger.error(" 4. Backend service error") |
122 | | - logger.error(" 5. Database connection issue") |
123 | | - logger.warning( |
124 | | - "⚠️ Warning: %s - Continuing with test (UI validation is primary)", |
125 | | - error_msg |
126 | | - ) |
127 | | - else: |
128 | | - logger.info("✅ API succeeded in %.2fs", duration) |
| 50 | + print(f"✅succeeded in {duration:.2f}s") |
| 51 | + # Check the response status code |
| 52 | + assert response.status == 200, "response code is " + str(response.status) |
129 | 53 |
|
130 | | - except Exception as exc: # pylint: disable=broad-exception-caught |
131 | | - duration = time.time() - start |
132 | | - logger.error("❌ API request failed after %.2fs", duration) |
133 | | - logger.error("Exception Type: %s", type(exc).__name__) |
134 | | - logger.error("Exception Message: %s", str(exc)) |
135 | | - import traceback # pylint: disable=import-outside-toplevel |
136 | | - logger.error("Stack Trace:\n%s", traceback.format_exc()) |
137 | | - logger.warning("⚠️ Warning: API validation failed - Continuing with test") |
| 54 | + self.page.wait_for_timeout(4000) |
138 | 55 |
|
139 | | - logger.info("=" * 80) |
140 | | - # Wait for UI to settle |
141 | | - self.page.wait_for_timeout(6000) |
0 commit comments