Skip to content

Commit 10a0c5c

Browse files
committed
Reverted code to previously working code
Added a helper method for switching user to avoid duplicate code Updated safe_accept_dialog to log dialog text for easier debugging
1 parent b980556 commit 10a0c5c

File tree

2 files changed

+461
-467
lines changed

2 files changed

+461
-467
lines changed

pages/base_page.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,22 @@ def _accept_dialog(self, dialog: Dialog) -> None:
237237

238238
def safe_accept_dialog(self, locator: Locator) -> None:
239239
"""
240-
Safely accepts a dialog triggered by a click, avoiding the error:
241-
playwright._impl._errors.Error: Dialog.accept: Cannot accept dialog which is already handled!
240+
Safely accepts a dialog triggered by a click, logging its contents.
241+
Avoids the error: Dialog.accept: Cannot accept dialog which is already handled!
242242
If no dialog appears, continues without error.
243243
Args:
244244
locator (Locator): The locator that triggers the dialog when clicked.
245-
example: If clicking a save button opens a dialog, pass that save button's locator.
246245
"""
247-
self.page.once("dialog", self._accept_dialog)
246+
247+
def handle_dialog(dialog: Dialog):
248+
try:
249+
logging.info(f"[DIALOG APPEARED WITH MESSAGE]: {dialog.message}")
250+
dialog.accept()
251+
except Exception:
252+
logging.warning("Dialog already accepted or handled")
253+
254+
self.page.once("dialog", handle_dialog)
255+
248256
try:
249257
self.click(locator)
250258
except Exception as e:

0 commit comments

Comments
 (0)