Skip to content

Commit

Permalink
Merge pull request #51 from rvykydal/webui-tests-more-robust-going-ba…
Browse files Browse the repository at this point in the history
…ck-and-variant-agnostic

Webui tests more robust going back and variant agnostic
  • Loading branch information
KKoukiou authored Nov 20, 2023
2 parents d60bea4 + 35d79c7 commit fae9411
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 51 deletions.
13 changes: 7 additions & 6 deletions test/check-basic
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
]

for step in steps:
i.click_step_on_sidebar(step)
if step not in i.hidden_steps:
i.click_step_on_sidebar(step)

i.reach(i.steps.REVIEW)

Expand All @@ -88,16 +89,16 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
i = Installer(b, m)
r = Review(b)

pretend_live_iso(self)
pretend_live_iso(self, i)

# For live media the first screen is the installation-method
i.open(step="installation-method")
i.open()
i.reach(i.steps.INSTALLATION_METHOD)

# Back button should be disabled on the first screen
b.wait_visible("#installation-back-btn[aria-disabled=true]")

# For live media in the review screen language details should still be displayed
i.reach(i.steps.REVIEW, hidden_steps=[i.steps.ACCOUNTS])
i.reach(i.steps.REVIEW)
r.check_language("English (United States)")

def testAboutModal(self):
Expand Down Expand Up @@ -205,7 +206,7 @@ class TestBasic(anacondalib.VirtInstallMachineCase):
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

# FIXME: Remove PF5 specific selector: https://github.com/patternfly/patternfly-react/issues/9512
b.wait_not_present("#critical-error-bz-report-modal.pf-v5-c-modal-box")
Expand Down
48 changes: 21 additions & 27 deletions test/check-storage
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
s = Storage(b, self.machine)

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

# Check the auto-selected disk's details
s.check_single_disk_destination("vda", "16.1 GB")
Expand Down Expand Up @@ -86,10 +86,10 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):

self.addCleanup(m.execute, "killall blivet-gui")

pretend_live_iso(self)
pretend_live_iso(self, i)

# For live media the first screen is the installation-method
i.open(step="installation-method")
i.open()
i.reach(i.steps.INSTALLATION_METHOD)

disk="vda"

Expand Down Expand Up @@ -221,7 +221,6 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
p = Password(b, s.encryption_id_prefix)

i.open()
# Language selection

i.reach(i.steps.INSTALLATION_METHOD)

Expand Down Expand Up @@ -301,8 +300,7 @@ class TestStorage(anacondalib.VirtInstallMachineCase, StorageHelpers):
# Go back to the Disk Configuration page and re-enter the review screen.
# This should create again a new partitioning object and apply it
# no matter how many partitioning objects were created before
i.back()
i.back()
i.reach_on_sidebar(i.steps.DISK_ENCRYPTION)
i.reach(i.steps.REVIEW)
new_applied_partitioning = s.dbus_get_applied_partitioning()
new_created_partitioning = s.dbus_get_created_partitioning()
Expand Down Expand Up @@ -335,7 +333,7 @@ class TestStorageExtraDisks(anacondalib.VirtInstallMachineCase, StorageHelpers):
dev = dev.split("/")[-1]

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

s.wait_no_disks_detected_not_present()

Expand Down Expand Up @@ -376,6 +374,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s = Storage(b, m)
r = Review(b)


disk = "/dev/vda"
dev = "vda"
btrfsname = "btrfstest"
Expand All @@ -384,7 +383,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -428,9 +427,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
applied_partitioning = s.dbus_get_applied_partitioning()

# When adding a new partition a new partitioning should be created
i.back()
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
i.back()
i.reach_on_sidebar(i.steps.INSTALLATION_METHOD)

m.execute(f"sgdisk --new=0:0:0 {disk}")
s.rescan_disks()
Expand Down Expand Up @@ -472,7 +469,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -512,7 +509,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)

# Select first only vdb disk and verify that the partitioning request is correct
i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)

s.rescan_disks()

Expand Down Expand Up @@ -591,7 +588,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev1, True)])
Expand Down Expand Up @@ -656,7 +653,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

# select only vda and check that we don't try to unlock the LUKS partition on vdb
Expand Down Expand Up @@ -705,7 +702,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

# select only vda and check that we don't try to unlock the LUKS partition on vdb
Expand Down Expand Up @@ -761,7 +758,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -800,9 +797,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
r.check_disk_row(dev, 3, "home, 15.0 GB: mount, /home")
r.check_disk_row_not_present(dev, f"unused")

i.back()
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
i.back()
i.reach_on_sidebar(i.steps.INSTALLATION_METHOD)

# Checks for nested btrfs subvolume
tmp_mount = "/tmp/btrfs-mount-test"
Expand Down Expand Up @@ -891,7 +886,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()
s.wait_scenario_available("mount-point-mapping", False)

Expand Down Expand Up @@ -923,7 +918,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down Expand Up @@ -964,8 +959,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
r.check_disk_row(disk, 3, f"{vgname}-home, 8.12 GB: mount, /home")
r.check_disk_row(disk, 4, f"{vgname}-swap, 902 MB: mount, swap")

i.back()
i.back(previous_page=i.steps.CUSTOM_MOUNT_POINT)
i.reach_on_sidebar(i.steps.CUSTOM_MOUNT_POINT)

# remove the /home row and check that row 3 is now swap
s.remove_mountpoint_row(3)
Expand Down Expand Up @@ -996,7 +990,7 @@ class TestStorageMountPoints(anacondalib.VirtInstallMachineCase, StorageHelpers)
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand All @@ -1023,7 +1017,7 @@ class TestStorageMountPointsEFI(anacondalib.VirtInstallMachineCase):
s.udevadm_settle()

i.open()
i.next()
i.reach(i.steps.INSTALLATION_METHOD)
s.rescan_disks()

s.select_mountpoint([(dev, True)])
Expand Down
52 changes: 35 additions & 17 deletions test/helpers/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,27 @@ class InstallerSteps(UserDict):
PROGRESS = "installation-progress"

_steps_jump = {}
_steps_jump[WELCOME] = INSTALLATION_METHOD
_steps_jump[WELCOME] = [INSTALLATION_METHOD]
_steps_jump[INSTALLATION_METHOD] = [DISK_ENCRYPTION, CUSTOM_MOUNT_POINT]
_steps_jump[DISK_ENCRYPTION] = ACCOUNTS
_steps_jump[CUSTOM_MOUNT_POINT] = ACCOUNTS
_steps_jump[ACCOUNTS] = REVIEW
_steps_jump[REVIEW] = PROGRESS
_steps_jump[DISK_ENCRYPTION] = [ACCOUNTS]
_steps_jump[CUSTOM_MOUNT_POINT] = [ACCOUNTS]
_steps_jump[ACCOUNTS] = [REVIEW]
_steps_jump[REVIEW] = [PROGRESS]
_steps_jump[PROGRESS] = []

_parent_steps = {}
_parent_steps[DISK_ENCRYPTION] = DISK_CONFIGURATION
_parent_steps[CUSTOM_MOUNT_POINT] = DISK_CONFIGURATION

_steps_callbacks = {}
_steps_callbacks[ACCOUNTS] = create_user

class Installer():
def __init__(self, browser, machine):
def __init__(self, browser, machine, hidden_steps=None):
self.browser = browser
self.machine = machine
self.steps = InstallerSteps()
self.hidden_steps = hidden_steps or []

@log_step(snapshot_before=True)
def begin_installation(self, should_fail=False, confirm_erase=True):
Expand All @@ -63,22 +68,24 @@ def begin_installation(self, should_fail=False, confirm_erase=True):
if should_fail:
self.wait_current_page(current_page)
else:
self.wait_current_page(self.steps._steps_jump[current_page])
self.wait_current_page(self.steps._steps_jump[current_page][0])

def _previous_pages(self, page):
return [k for k, v in self.steps._steps_jump.items() if page in v]

def reach(self, target_page, hidden_steps=None):
hidden_steps = hidden_steps or []
def reach(self, target_page):
path = []
prev_pages = [target_page]
current_page = self.get_current_page()

while current_page not in prev_pages:
page = prev_pages[0]
path.append(page)
prev_pages = [k for k, v in self.steps._steps_jump.items() if page in v]
prev_pages = self._previous_pages(page)

while self.get_current_page() != target_page:
next_page = path.pop()
if next_page not in hidden_steps:
if next_page not in self.hidden_steps:
self.next(next_page=next_page)
if next_page in self.steps._steps_callbacks:
self.steps._steps_callbacks[next_page](self.browser, self.machine)
Expand All @@ -88,10 +95,9 @@ def next(self, should_fail=False, next_page=""):
current_page = self.get_current_page()
# If not explicitly specified, get the first item for next page from the steps dict
if not next_page:
if isinstance(self.steps._steps_jump[current_page], list):
next_page = self.steps._steps_jump[current_page][0]
else:
next_page = self.steps._steps_jump[current_page]
next_page = self.steps._steps_jump[current_page][0]
while next_page in self.hidden_steps:
next_page = self.steps._steps_jump[next_page][0]

# Wait for a disk to be pre-selected before clicking 'Next'.
# FIXME: Find a better way.
Expand Down Expand Up @@ -123,12 +129,17 @@ def back(self, should_fail=False, previous_page=""):
self.wait_current_page(current_page)
else:
if not previous_page:
previous_page = [k for k, v in self.steps._steps_jump.items() if current_page in v][0]
previous_page = self._previous_pages(current_page)[0]
while previous_page in self.hidden_steps:
previous_page = self._previous_pages(previous_page)[0]

self.wait_current_page(previous_page)

@log_step()
def open(self, step="installation-language"):
def open(self, step=None):
step = step or self.steps.WELCOME
while step in self.hidden_steps:
step = self.steps._steps_jump[step][0]
self.browser.open(f"/cockpit/@localhost/anaconda-webui/index.html#/{step}")
self.wait_current_page(step)
# Ensure that the logo is visible before proceeding as pixel tests get racy otherwise
Expand All @@ -138,6 +149,13 @@ def click_step_on_sidebar(self, step=None):
step = step or self.get_current_page()
self.browser.click(f"#{step}")

@log_step()
def reach_on_sidebar(self, target_page):
if target_page in self.steps._parent_steps:
self.click_step_on_sidebar(self.steps._parent_steps[target_page])
self.click_step_on_sidebar(target_page)
self.wait_current_page(target_page)

def get_current_page(self):
return self.browser.eval_js('window.location.hash;').replace('#/', '') or self.steps[0]

Expand Down
3 changes: 2 additions & 1 deletion test/helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def add_public_key(machine):
machine.execute(f"chmod 700 {sysroot_ssh}")
machine.write(authorized_keys, public_key, perm="0600")

def pretend_live_iso(test):
def pretend_live_iso(test, installer):
installer.hidden_steps.extend([installer.steps.ACCOUNTS, installer.steps.WELCOME])
test.restore_file('/run/anaconda/anaconda.conf')
test.machine.execute("sed -i 's/type = BOOT_ISO/type = LIVE_OS/g' /run/anaconda/anaconda.conf")

Expand Down

0 comments on commit fae9411

Please sign in to comment.