Debian Codegraph @

dirsrvtests/tests/suites/webui/login/login_test.py

raw
1 # --- BEGIN COPYRIGHT BLOCK ---
2 # Copyright (C) 2023 Red Hat, Inc.
3 # All rights reserved.
4 #
5 # License: GPL (version 3 or any later version).
6 # See LICENSE for details.
7 # --- END COPYRIGHT BLOCK ---
8 #
9 import time
10 import subprocess
11 import pytest
12 import distro
13
14 from lib389.cli_idm.account import *
15 from lib389.tasks import *
16 from lib389.utils import *
17 from test389.topologies import topology_st
18 from .. import setup_page, remove_instance_through_lib, check_cockpit_version_is_higher, check_frame_assignment, \
19 setup_login, check_cockpit_version_is_lower
20
21 pytestmark = pytest.mark.skipif(os.getenv('WEBUI') is None, reason="These tests are only for WebUI environment")
22 pytest.importorskip('playwright')
23
24 RHEL = 'Red Hat Enterprise Linux'
25
26
27 def test_login_no_instance(topology_st, page, browser_name):
28 """ Test login to WebUI is successful
29
30 :id: 0a85c1ec-20f3-41ae-8203-3951e74f34e7
31 :setup: Standalone instance
32 :steps:
33 1. Go to cockpit login page
34 2. Fill user and password
35 3. Click on login button
36 4. Go to Red Hat Directory server side tab page
37 5. Check there is Create New Instance button when no instance exists
38 :expectedresults:
39 1. Page redirection to login page successful
40 2. Success
41 3. Login successful
42 4. Page redirection successful
43 5. Button is visible
44 """
45
46 remove_instance_through_lib(topology_st)
47 password = ensure_str(os.getenv('PASSWD'))
48
49 # if we use setup_page from __init__.py we would be logged in already
50 page.set_viewport_size({"width": 1920, "height": 1080})
51
52 # increase default timeout to wait enough time on a slow machine for selector availability
53 # (it will wait just enough time for the selector to be available,
54 # it won't stop for 60 000 miliseconds each time it is called)
55 page.set_default_timeout(60000)
56
57 page.goto("http://localhost:9090/")
58 assert page.url == 'http://localhost:9090/'
59 page.wait_for_selector('#login-user-input')
60
61 # We are at login page
62 log.info('Let us log in')
63 page.fill('#login-user-input', 'root')
64 page.fill('#login-password-input', password)
65 page.click('#login-button')
66 time.sleep(2)
67
68 if RHEL in distro.name():
69 page.wait_for_selector('text=Red Hat Directory Server')
70 assert page.is_visible('text=Red Hat Directory Server')
71 log.info('Let us go to RHDS side tab page')
72 page.click('text=Red Hat Directory Server')
73 else:
74 page.wait_for_selector('text=389 Directory Server')
75 assert page.is_visible('text=389 Directory Server')
76 log.info('Let us go to RHDS side tab page')
77 page.click('text=389 Directory Server')
78
79 log.info('Login successful')
80 assert page.url == 'http://localhost:9090/389-console'
81
82 log.info('Check there is Create New Instance button')
83 frame = check_frame_assignment(page, browser_name)
84 frame.wait_for_selector('#no-inst-create-btn')
85 assert frame.is_visible("#no-inst-create-btn")
86
87
88 def test_logout(topology_st, page):
89 """ Test logout from WebUI is successful
90
91 :id: a7e71179-3ef0-4e4e-baca-a36beeef71b6
92 :setup: Standalone instance
93 :steps:
94 1. Go to cockpit login page
95 2. Fill user and password
96 3. Click on login button
97 4. Click on root user and choose Log Out option
98 5. Check we have been redirected to the login page
99 :expectedresults:
100 1. Page redirection to login page successful
101 2. Success
102 3. Login successful
103 4. Page redirection successful
104 5. We are at login page
105 """
106
107 setup_login(page)
108 assert page.url == "http://localhost:9090/389-console"
109
110 # checking cockpit versions because selector ids got renamed in between
111 log.info('Let us log out')
112 if check_cockpit_version_is_higher('258'):
113 page.click('#toggle-menu')
114 page.click('#logout')
115 elif check_cockpit_version_is_higher('250') and check_cockpit_version_is_lower('257'):
116 page.click('#navbar-dropdown')
117 page.click('#go-logout')
118 else:
119 page.click('#content-user-name')
120 page.click('#go-logout')
121
122 page.wait_for_selector('#login-user-input')
123 assert page.is_visible('#login-user-input')
124 log.info('Log out successful')
125
126
127 if __name__ == '__main__':
128 # Run isolated
129 # -s for DEBUG mode
130 CURRENT_FILE = os.path.realpath(__file__)
131 pytest.main("-s %s" % CURRENT_FILE)
132