1+ import time
2+ import os
13from base .base import BasePage
24from pytest_check import check
3- from config .constants import *
45import logging
56logger = logging .getLogger (__name__ )
6- import time
77
88
99class DraftPage (BasePage ):
1010 Draft_Sections = "//textarea"
1111 Draft_headings = "//span[@class='fui-Text ___nl2uoq0 fk6fouc f4ybsrx f1i3iumi f16wzh4i fpgzoln f1w7gpdv f6juhto f1gl81tg f2jf649 fepr9ql febqm8h']"
1212 invalid_response = "The requested information is not available in the retrieved data. Please try another query or topic."
1313 invalid_response1 = "There was an issue fetching your data. Please try again."
14-
1514
1615 def __init__ (self , page ):
1716 self .page = page
@@ -74,8 +73,8 @@ def validate_draft_sections_loaded(self):
7473 logger .info (f"✅ Section '{ title_text } ' loaded after Generate + Confirm." )
7574 content_loaded = True
7675 break
77- except :
78- pass
76+ except Exception as e :
77+ logger . info ( f"⏳ Waiting for section ' { title_text } ' to load... { e } " )
7978 time .sleep (1 )
8079
8180 if not content_loaded :
@@ -90,8 +89,8 @@ def validate_draft_sections_loaded(self):
9089 logger .info (f"✅ Section '{ title_text } ' loaded successfully." )
9190 content_loaded = True
9291 break
93- except :
94- pass
92+ except Exception as e :
93+ logger . info ( f"⏳ Waiting for section ' { title_text } ' to load... { e } " )
9594 time .sleep (poll_interval )
9695
9796 # Step 2: If still not loaded, click Generate and retry
@@ -114,8 +113,8 @@ def validate_draft_sections_loaded(self):
114113 logger .info (f"✅ Section '{ title_text } ' loaded after clicking Generate." )
115114 content_loaded = True
116115 break
117- except :
118- pass
116+ except Exception as e :
117+ logger . info ( f"⏳ Waiting for section ' { title_text } ' to load after Generate... { e } " )
119118 time .sleep (poll_interval )
120119
121120 if not content_loaded :
@@ -133,42 +132,41 @@ def validate_draft_sections_loaded(self):
133132 continue
134133
135134 try :
136- content = content_locator .text_content (timeout = 2000 ).strip ()
137- with check :
138- if content == self .invalid_response or content == self .invalid_response1 :
139- logger .warning (f"❌ Invalid response found in '{ title_text } '. Retrying Generate + Confirm..." )
140-
135+ content = content_locator .text_content (timeout = 2000 ).strip ()
136+ with check :
137+ if content == self .invalid_response or content == self .invalid_response1 :
138+ logger .warning (f"❌ Invalid response found in '{ title_text } '. Retrying Generate + Confirm..." )
139+
140+ try :
141+ generate_btn .click ()
142+ self .page .wait_for_timeout (3000 )
143+
144+ confirm_btn = self .page .locator ("//button[@class='fui-Button r1alrhcs ___zqkcn80 fd1o0ie fjxutwb fwiml72 fj8njcf fzcpov4 f1d2rq10 f1mk8lai ff3glw6']" )
145+ if confirm_btn .is_visible (timeout = 3000 ):
146+ confirm_btn .click ()
147+ logger .info (f"🟢 Retried Confirm for section '{ title_text } '" )
148+ else :
149+ logger .warning (f"⚠️ Confirm button not visible during retry for '{ title_text } '" )
150+ except Exception as e :
151+ logger .error (f"❌ Retry Generate/Confirm failed: { e } " )
152+
153+ retry_start = time .time ()
154+ while time .time () - retry_start < short_wait :
141155 try :
142- generate_btn .click ()
143- self .page .wait_for_timeout (3000 )
144-
145- confirm_btn = self .page .locator ("//button[@class='fui-Button r1alrhcs ___zqkcn80 fd1o0ie fjxutwb fwiml72 fj8njcf fzcpov4 f1d2rq10 f1mk8lai ff3glw6']" )
146- if confirm_btn .is_visible (timeout = 3000 ):
147- confirm_btn .click ()
148- logger .info (f"🟢 Retried Confirm for section '{ title_text } '" )
149- else :
150- logger .warning (f"⚠️ Confirm button not visible during retry for '{ title_text } '" )
156+ content = content_locator .text_content (timeout = 2000 ).strip ()
157+ if content and content not in [self .invalid_response , self .invalid_response1 ]:
158+ logger .info (f"✅ Section '{ title_text } ' fixed after retry." )
159+ break
151160 except Exception as e :
152- logger .error (f"❌ Retry Generate/Confirm failed: { e } " )
153-
154- retry_start = time .time ()
155- while time .time () - retry_start < short_wait :
156- try :
157- content = content_locator .text_content (timeout = 2000 ).strip ()
158- if content and content not in [self .invalid_response , self .invalid_response1 ]:
159- logger .info (f"✅ Section '{ title_text } ' fixed after retry." )
160- break
161- except :
162- pass
163- time .sleep (1 )
164-
165- with check :
166- check .not_equal (content , self .invalid_response , f"❌ '{ title_text } ' still has invalid response after retry" )
167- check .not_equal (content , self .invalid_response1 , f"❌ '{ title_text } ' still has invalid response after retry" )
168-
169- else :
170- logger .info (f"🎯 Section '{ title_text } ' has valid content." )
171- except Exception as e :
172- logger .error (f"❌ Could not validate content for '{ title_text } ': { e } " )
161+ logger .info (f"⏳ Retrying section '{ title_text } '... { e } " )
162+ time .sleep (1 )
163+
164+ with check :
165+ check .not_equal (content , self .invalid_response , f"❌ '{ title_text } ' still has invalid response after retry" )
166+ check .not_equal (content , self .invalid_response1 , f"❌ '{ title_text } ' still has invalid response after retry" )
173167
174- logger .info (f"✔️ Completed section: '{ title_text } '\n " )
168+ else :
169+ logger .info (f"🎯 Section '{ title_text } ' has valid content." )
170+ except Exception as e :
171+ logger .error (f"❌ Could not validate content for '{ title_text } ': { e } " )
172+ logger .info (f"✔️ Completed section: '{ title_text } '\n " )
0 commit comments