Skip to content

Commit

Permalink
ui: Separate user portal and grafana tests from other UI tests
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
tinez committed Sep 28, 2022
1 parent bc4503c commit a2e4f90
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 94 deletions.
81 changes: 1 addition & 80 deletions basic-suite-master/test-scenarios/test_100_basic_ui_sanity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand All @@ -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')
Original file line number Diff line number Diff line change
@@ -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')
22 changes: 13 additions & 9 deletions ost_utils/pytest/fixtures/selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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}"
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions ost_utils/pytest/fixtures/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
):
Expand All @@ -44,23 +44,23 @@ 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'))

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'))

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':
Expand All @@ -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)
Expand Down

0 comments on commit a2e4f90

Please sign in to comment.