From a2e4f903df25dcad0e6bfdd97cc6a17164616da1 Mon Sep 17 00:00:00 2001 From: Marcin Sobczyk Date: Wed, 28 Sep 2022 16:34:31 +0200 Subject: [PATCH] ui: Separate user portal and grafana tests from other UI tests Due to the problem with keycloak logout we're using a separate Selenium session to test user portal and grafana. Signed-off-by: Marcin Sobczyk --- .../test_100_basic_ui_sanity.py | 81 +---------------- .../test_101_ui_user_portal_and_grafana.py | 88 +++++++++++++++++++ ost_utils/pytest/fixtures/selenium.py | 22 +++-- ost_utils/pytest/fixtures/ui.py | 10 +-- 4 files changed, 107 insertions(+), 94 deletions(-) create mode 100644 basic-suite-master/test-scenarios/test_101_ui_user_portal_and_grafana.py diff --git a/basic-suite-master/test-scenarios/test_100_basic_ui_sanity.py b/basic-suite-master/test-scenarios/test_100_basic_ui_sanity.py index b6dad747..469859da 100644 --- a/basic-suite-master/test-scenarios/test_100_basic_ui_sanity.py +++ b/basic-suite-master/test-scenarios/test_100_basic_ui_sanity.py @@ -25,10 +25,6 @@ from ost_utils.selenium.page_objects.WebAdminLeftMenu import WebAdminLeftMenu from ost_utils.selenium.page_objects.WebAdminTopMenu import WebAdminTopMenu from ost_utils.selenium.page_objects.VmListView import VmListView -from ost_utils.selenium.page_objects.GrafanaLoginScreen import ( - GrafanaLoginScreen, -) -from ost_utils.selenium.page_objects.Grafana import Grafana from ost_utils.shell import ShellError from ost_utils.shell import shell @@ -534,7 +530,7 @@ def test_dashboard(ovirt_driver): assert dashboard.events_count() > 0 -def test_logout(ovirt_driver, engine_webadmin_url, keycloak_enabled): +def test_logout(ovirt_driver, engine_webadmin_url): webadmin_menu = WebAdminTopMenu(ovirt_driver) webadmin_menu.wait_for_displayed() webadmin_menu.logout() @@ -546,78 +542,3 @@ def test_logout(ovirt_driver, engine_webadmin_url, keycloak_enabled): welcome_screen.wait_for_displayed() welcome_screen.wait_for_user_logged_out() assert welcome_screen.is_user_logged_out() - - if keycloak_enabled: - # delete all cookies to workaround not logging out from the Keycloak properly - ovirt_driver.delete_all_cookies() - - -def test_userportal( - ovirt_driver, - nonadmin_username, - nonadmin_password, - user_login, - engine_webadmin_url, - save_screenshot, -): - welcome_screen = WelcomeScreen(ovirt_driver) - welcome_screen.wait_for_displayed() - welcome_screen.open_user_portal() - - user_login(nonadmin_username, nonadmin_password) - - vm_portal = VmPortal(ovirt_driver) - vm_portal.wait_for_displayed() - - # using vm0 requires logic from 002 _bootstrap::test_add_vm_permissions_to_user - assert assert_utils.equals_within_short(vm_portal.get_vm_count, 1) - vm0_status = vm_portal.get_vm_status('vm0') - assert vm0_status == 'Powering up' or vm0_status == 'Running' - save_screenshot('userportal') - - vm_portal.logout() - save_screenshot('userportal-logout') - - welcome_screen = WelcomeScreen(ovirt_driver) - welcome_screen.wait_for_displayed() - assert welcome_screen.is_user_logged_out() - - -def test_grafana( - ovirt_driver, - save_screenshot, - engine_username, - engine_password, - engine_webadmin_url, - user_login, - engine_fqdn, -): - - ovirt_driver.get(engine_webadmin_url) - - welcome_screen = WelcomeScreen(ovirt_driver) - welcome_screen.wait_for_displayed() - welcome_screen.open_monitoring_portal() - - grafana_login = GrafanaLoginScreen(ovirt_driver) - grafana_login.wait_for_displayed() - save_screenshot('grafana-login') - grafana_login.use_ovirt_engine_auth() - user_login(engine_username, engine_password) - - grafana = Grafana(ovirt_driver) - grafana.wait_for_displayed() - save_screenshot('grafana') - - # navigate directly to Grafana Configuration/Data Sources page - ovirt_driver.get(f'https://{engine_fqdn}/ovirt-engine-grafana/datasources') - assert grafana.db_connection() - save_screenshot('grafana-datasource-connection') - - grafana.open_dashboard('oVirt Executive Dashboards', '02 Data Center Dashboard') - assert not grafana.is_error_visible() - save_screenshot('grafana-dashboard-1') - - grafana.open_dashboard('oVirt Inventory Dashboards', '02 Hosts Inventory Dashboard') - assert not grafana.is_error_visible() - save_screenshot('grafana-dashboard-2') diff --git a/basic-suite-master/test-scenarios/test_101_ui_user_portal_and_grafana.py b/basic-suite-master/test-scenarios/test_101_ui_user_portal_and_grafana.py new file mode 100644 index 00000000..879580b6 --- /dev/null +++ b/basic-suite-master/test-scenarios/test_101_ui_user_portal_and_grafana.py @@ -0,0 +1,88 @@ +# +# Copyright oVirt Authors +# SPDX-License-Identifier: GPL-2.0-or-later +# +# + +from ost_utils import assert_utils +from ost_utils import constants +from ost_utils.constants import * +from ost_utils.pytest.fixtures.selenium import * +from ost_utils.pytest.fixtures.ui import * +from ost_utils.selenium.page_objects.WelcomeScreen import WelcomeScreen +from ost_utils.selenium.page_objects.VmPortal import VmPortal +from ost_utils.selenium.page_objects.GrafanaLoginScreen import ( + GrafanaLoginScreen, +) +from ost_utils.selenium.page_objects.Grafana import Grafana + + +def test_userportal( + ovirt_driver, + nonadmin_username, + nonadmin_password, + user_login, + engine_webadmin_url, + save_screenshot, +): + welcome_screen = WelcomeScreen(ovirt_driver) + welcome_screen.wait_for_displayed() + welcome_screen.open_user_portal() + + user_login(nonadmin_username, nonadmin_password) + + vm_portal = VmPortal(ovirt_driver) + vm_portal.wait_for_displayed() + + # using vm0 requires logic from 002 _bootstrap::test_add_vm_permissions_to_user + assert assert_utils.equals_within_short(vm_portal.get_vm_count, 1) + vm0_status = vm_portal.get_vm_status('vm0') + assert vm0_status == 'Powering up' or vm0_status == 'Running' + save_screenshot('userportal') + + vm_portal.logout() + save_screenshot('userportal-logout') + + welcome_screen = WelcomeScreen(ovirt_driver) + welcome_screen.wait_for_displayed() + assert welcome_screen.is_user_logged_out() + + +def test_grafana( + ovirt_driver, + save_screenshot, + engine_username, + engine_password, + engine_webadmin_url, + user_login, + engine_fqdn, +): + + ovirt_driver.get(engine_webadmin_url) + + welcome_screen = WelcomeScreen(ovirt_driver) + welcome_screen.wait_for_displayed() + welcome_screen.open_monitoring_portal() + + grafana_login = GrafanaLoginScreen(ovirt_driver) + grafana_login.wait_for_displayed() + save_screenshot('grafana-login') + grafana_login.use_ovirt_engine_auth() + user_login(engine_username, engine_password) + + grafana = Grafana(ovirt_driver) + grafana.wait_for_displayed() + save_screenshot('grafana') + + # navigate directly to Grafana Configuration/Data Sources page + ovirt_driver.get(f'https://{engine_fqdn}/ovirt-engine-grafana/datasources') + assert grafana.db_connection() + save_screenshot('grafana-datasource-connection') + + grafana.open_dashboard('oVirt Executive Dashboards', '02 Data Center Dashboard') + assert not grafana.is_error_visible() + save_screenshot('grafana-dashboard-1') + + grafana.open_dashboard('oVirt Inventory Dashboards', '02 Hosts Inventory Dashboard') + assert not grafana.is_error_visible() + save_screenshot('grafana-dashboard-2') diff --git a/ost_utils/pytest/fixtures/selenium.py b/ost_utils/pytest/fixtures/selenium.py index cf536780..f94e4912 100644 --- a/ost_utils/pytest/fixtures/selenium.py +++ b/ost_utils/pytest/fixtures/selenium.py @@ -27,6 +27,10 @@ class SeleniumGridError(Exception): pass +def _timestamp(): + return datetime.now().strftime("%Y%m%d_%H%M%S_%f") + + def _node_ready(status_dict, browser_name): nodes = status_dict["value"]["nodes"] for node in nodes: @@ -101,7 +105,7 @@ def selenium_url(storage_management_ips, selenium_port): yield url -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def selenium_browser( ansible_storage, selenium_artifacts_dir, @@ -129,13 +133,13 @@ def selenium_browser( _grid_health_check(selenium_url, selenium_browser_name) yield container_id ansible_storage.shell(f"podman stop {container_id}") - log_name = f"podman-{selenium_browser_name}.log" + log_name = f"podman-{selenium_browser_name}-{_timestamp()}.log" remote_log_path = f"{selenium_remote_artifacts_dir}/{log_name}" ansible_storage.shell(f"podman logs {container_id} > {remote_log_path}") ansible_storage.fetch(src=remote_log_path, dest=f"{selenium_artifacts_dir}/{log_name}", flat=True) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def selenium_video_recorder( ansible_storage, selenium_browser_name, @@ -145,11 +149,12 @@ def selenium_video_recorder( selenium_screen_width, selenium_screen_height, ): + video_file_name = f"video-{selenium_browser_name}-{_timestamp()}.mp4" container_id = ansible_storage.shell( "podman run -d" f" -v {selenium_remote_artifacts_dir}/:/videos:z" f" -e DISPLAY_CONTAINER_NAME={selenium_browser[:12]}" - f" -e FILE_NAME=video-{selenium_browser_name}.mp4" + f" -e FILE_NAME={video_file_name}" f" -e SE_SCREEN_WIDTH={selenium_screen_width}" f" -e SE_SCREEN_HEIGHT={selenium_screen_height}" f" --network=container:{selenium_browser}" @@ -158,17 +163,17 @@ def selenium_video_recorder( yield ansible_storage.shell(f"podman stop {container_id}") ansible_storage.fetch( - src=f"{selenium_remote_artifacts_dir}/video-{selenium_browser_name}.mp4", + src=f"{selenium_remote_artifacts_dir}/{video_file_name}", dest=selenium_artifacts_dir, flat=True, ) res = ansible_storage.shell(f"podman logs {container_id}") - with open(f"{selenium_artifacts_dir}/podman-video-{selenium_browser}.log", "w") as log_file: + with open(f"{selenium_artifacts_dir}/podman-video-{selenium_browser}-{_timestamp()}.log", "w") as log_file: log_file.write(res["stdout"]) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def selenium_grid_url(selenium_url, selenium_browser, selenium_video_recorder): yield selenium_url @@ -210,8 +215,7 @@ def selenium_artifacts_dir(artifacts_dir): @pytest.fixture(scope="session") def selenium_artifact_filename(selenium_browser_name): def _selenium_artifact_filename(description, extension): - date = datetime.now().strftime("%Y%m%d_%H%M%S_%f") - return "{}_{}_{}.{}".format(date, selenium_browser_name, description, extension) + return f"{_timestamp()}_{selenium_browser_name}_{description}.{extension}" return _selenium_artifact_filename diff --git a/ost_utils/pytest/fixtures/ui.py b/ost_utils/pytest/fixtures/ui.py index 8fa8cf39..4d036c62 100644 --- a/ost_utils/pytest/fixtures/ui.py +++ b/ost_utils/pytest/fixtures/ui.py @@ -17,7 +17,7 @@ LOGGER = logging.getLogger(__name__) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def ovirt_driver( engine_webadmin_url, selenium_browser_options, selenium_grid_url, selenium_screen_width, selenium_screen_height ): @@ -44,7 +44,7 @@ def ovirt_driver( ovirt_driver.quit() -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def save_screenshot(ovirt_driver, selenium_artifact_full_path): def save(description): ovirt_driver.save_screenshot(selenium_artifact_full_path(description, 'png')) @@ -52,7 +52,7 @@ def save(description): return save -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def save_page_source(ovirt_driver, selenium_artifact_full_path): def save(description): ovirt_driver.save_page_source(selenium_artifact_full_path(description, 'html')) @@ -60,7 +60,7 @@ def save(description): return save -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def save_logs_from_browser(ovirt_driver, selenium_artifact_full_path): def save(description): if ovirt_driver.get_capability('browserName') == 'chrome': @@ -81,7 +81,7 @@ def after_test(request, save_screenshot, save_page_source, save_logs_from_browse save_page_source(file_name) -@pytest.fixture(scope="session") +@pytest.fixture(scope="module") def user_login(ovirt_driver, keycloak_enabled): def login(username, password): login_screen = LoginScreen(ovirt_driver, keycloak_enabled)