Source code for univention.testing.browser.sidemenu
#!/usr/bin/python3
# SPDX-FileCopyrightText: 2023-2025 Univention GmbH
# SPDX-License-Identifier: AGPL-3.0-only
import time
from pathlib import Path
from playwright.sync_api import Locator, Page, TimeoutError as PlaywrightTimeoutError, expect
from univention.lib.i18n import Translation
from univention.testing.browser.lib import UCSLanguage, UMCBrowserTest
_ = Translation('ucs-test-framework').translate
[docs]
class SideMenuUser:
def __init__(self, tester: UMCBrowserTest):
self.tester: UMCBrowserTest = tester
self.page: Page = self.tester.page
[docs]
def change_password(self, old_password: str, new_password: str):
self.page.locator('#umcMenuChangePassword').click()
self.page.get_by_role('dialog').get_by_label('Old Password').press_sequentially(old_password)
time.sleep(0.5)
self.page.get_by_role('dialog').get_by_label('New password', exact=True).press_sequentially(new_password)
time.sleep(0.5)
self.page.get_by_role('dialog').get_by_label('New password (retype)').press_sequentially(new_password)
time.sleep(0.5)
self.page.get_by_role('button', name=_('Change password')).click()
[docs]
class SideMenuServer:
def __init__(self, tester: UMCBrowserTest):
self.tester: UMCBrowserTest = tester
self.page: Page = self.tester.page
[docs]
def reboot_server(self, do_reboot: bool = False):
self.page.get_by_text('Reboot Server').click()
reboot_button = self.page.get_by_role('button', name='Reboot')
expect(reboot_button).to_be_visible()
if do_reboot:
reboot_button.click()
[docs]
class SideMenuLicense:
def __init__(self, tester: UMCBrowserTest):
self.tester: UMCBrowserTest = tester
self.page: Page = tester.page
[docs]
def import_license(self, license_file_path: Path, as_text: bool):
self.page.get_by_text(_('Import new license')).click()
if as_text:
with open(license_file_path) as license_file:
license_text = license_file.read()
self.page.get_by_role('dialog').get_by_role('textbox').last.fill(license_text)
self.page.get_by_role('button', name=_('Import from text field')).click()
else:
with self.page.expect_file_chooser() as fc_info:
self.page.get_by_role('button', name=_('Import from file...')).click(force=True)
file_chooser = fc_info.value
file_chooser.set_files(license_file_path)
success_text = self.page.get_by_text(_('The license has been imported successfully.'))
expect(success_text).to_be_visible()
self.page.get_by_role('dialog').get_by_role('button', name='Ok').click()
[docs]
class SideMenu:
side_menu_button: Locator
def __init__(self, tester: UMCBrowserTest) -> None:
self.tester: UMCBrowserTest = tester
self.page: Page = tester.page
self.is_portal: bool = False
[docs]
def switch_to_language(self, target_language: UCSLanguage):
"""
Switches the language to the language given by target_language.
This method changes the language using the SideMnu "Switch Language" button.
It also updates the tester this Class was initialized with to the new language.
:param target_language: the language to switch to
"""
self.page.locator('#umcMenuLanguage').click()
lang_button = self.page.get_by_text(target_language.get_name())
lang_button.click()
self.page.get_by_role('button', name='Switch language').click()
# not sure if this is the right place to do this
self.tester.set_language(target_language)
[docs]
def logout(self):
"""Logout using the Side Menu"""
self.page.get_by_role('button', name=_('Logout')).click()
# logout configrmation popup only in the UMC
if not self.is_portal:
self.page.get_by_role('dialog', name=_('Confirmation')).get_by_role('button', name=_('Logout')).click()
[docs]
def logout_with_fallback(self):
try:
self.logout()
except PlaywrightTimeoutError:
self.page.goto(f'{self.tester.base_url}/univention/logout')
[docs]
def back(self):
# TODO: find a better locator for this
self.page.locator('.menuSlideHeader').locator('visible=true').click()