Playwright E2E: better logout selector chain + JS fallback

Test now tries (in order):
1. .sb-foot .lo (topbar logout in sidebar foot)
2. .lo (any logout class)
3. #pgz-menu-logout (sidebar.js menu link)
4. a/button :has-text('Odjava')
5. JS fallback: window.logout() or PGZSidebar.logout()

Also: dialog handler accepts confirm() automatically.
This commit is contained in:
2026-05-05 09:23:13 +02:00
parent dd2f7daaf8
commit a0fb328029
12 changed files with 139 additions and 34 deletions
+24 -10
View File
@@ -121,18 +121,32 @@ def test_desktop(pw):
# 5. Logout
try:
# Click the logout button (⎋ icon)
# Find a visible logout element; topbar .lo first
# Find a visible logout element across all known selectors
logout_btn = None
for sel in ['.lo[onclick*="logout"]', '.lo', 'button[onclick*="logout"]', '[onclick*="logout()"]']:
elems = page.locator(sel)
for i in range(elems.count()):
try:
if elems.nth(i).is_visible():
logout_btn = elems.nth(i); break
except: continue
if logout_btn: break
candidates = ['.sb-foot .lo', '.lo', '#pgz-menu-logout', 'a:has-text("Odjava")', 'button:has-text("Odjava")']
for sel in candidates:
try:
el = page.locator(sel).first
if el.count() > 0 and el.is_visible(timeout=1000):
logout_btn = el; print(f' [debug] found visible logout via: {sel}'); break
except: continue
# Fallback: try clicking via JS
if logout_btn is None:
res = page.evaluate("""() => {
if (typeof window.logout === 'function') { window.logout(); return 'js:logout()'; }
if (window.PGZSidebar && typeof window.PGZSidebar.logout === 'function') { window.PGZSidebar.logout(); return 'js:PGZSidebar.logout()'; }
return null;
}""")
if res:
print(f' [debug] logout invoked via JS: {res}')
time.sleep(2)
logout_btn = 'js' # sentinel
if logout_btn is not None:
logout_btn.click(force=True)
if hasattr(logout_btn, 'click'):
# Suppress confirm() dialog
page.on('dialog', lambda d: d.accept())
try: logout_btn.click(force=True, timeout=5000)
except: pass
time.sleep(2)
tok_after = page.evaluate("() => localStorage.getItem('pgz_access') || sessionStorage.getItem('pgz_access')")
shoot(page, "05_post_logout")