diff --git a/lib/utils.pm b/lib/utils.pm index cd7cae9e..3d866f5b 100644 --- a/lib/utils.pm +++ b/lib/utils.pm @@ -8,7 +8,7 @@ use Exporter; use feature "switch"; use lockapi; use testapi; -our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type repo_setup cleanup_workaround_repo console_initial_setup handle_welcome_screen gnome_initial_setup anaconda_create_user check_desktop download_modularity_tests quit_firefox advisory_get_installed_packages advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut lo_dismiss_tip disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile get_release_number get_version_major get_code_name check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log click_unwanted_notifications repos_mirrorlist register_application get_registered_applications solidify_wallpaper/; +our @EXPORT = qw/run_with_error_check type_safely type_very_safely desktop_vt boot_to_login_screen console_login console_switch_layout desktop_switch_layout console_loadkeys_us do_bootloader boot_decrypt check_release menu_launch_type repo_setup cleanup_workaround_repo console_initial_setup handle_welcome_screen gnome_initial_setup anaconda_create_user check_desktop download_modularity_tests quit_firefox advisory_get_installed_packages advisory_check_nonmatching_packages start_with_launcher quit_with_shortcut lo_dismiss_tip disable_firefox_studies select_rescue_mode copy_devcdrom_as_isofile get_release_number get_version_major get_code_name check_left_bar check_top_bar check_prerelease check_version spell_version_number _assert_and_click is_branched rec_log click_unwanted_notifications repos_mirrorlist register_application get_registered_applications solidify_wallpaper check_and_install_git download_testdata make_serial_writable set_update_notification_timestamp kde_doublek_workaround dm_perform_login/; # We introduce this global variable to hold the list of applications that have # registered during the apps_startstop_test when they have sucessfully run. @@ -1381,4 +1381,159 @@ sub solidify_wallpaper { } } +# This routine is used in Desktop test suites, such as Evince or Gedit. +# It checks if git is installed and installs it, if necessary. +sub check_and_install_git { + unless (get_var("CANNED")) { + if (script_run("rpm -q git")) { + assert_script_run("dnf install -y git"); + } + } +} + +# This routine is used in Desktop test suites. It downloads the test data from +# the repository and populates the directory structure. +# The data repository is located at https://pagure.io/fedora-qa/openqa_testdata. + +sub download_testdata { + # We can select which Data to copy over. + my $data = shift; + $data = 'structure' unless ($data); + # Navigate to the user's home directory + my $user = get_var("USER_LOGIN") // "test"; + assert_script_run("cd /home/$user/"); + # Create a temporary directory to unpack the zipped file. + assert_script_run("mkdir temp"); + assert_script_run("cd temp"); + # Download the compressed file with the repository content. + assert_script_run("curl --retry-delay 10 --max-time 120 --retry 5 -o repository.tar.gz https://pagure.io/fedora-qa/openqa_testdata/blob/thetree/f/repository.tar.gz", timeout => 600); + # Untar it. + assert_script_run("tar -zxvf repository.tar.gz"); + # Copy out the files into the VMs directory structure. + if ($data eq "structure") { + assert_script_run("cp music/* /home/$user/Music"); + assert_script_run("cp documents/* /home/$user/Documents"); + assert_script_run("cp pictures/* /home/$user/Pictures"); + assert_script_run("cp video/* /home/$user/Videos"); + assert_script_run("cp reference/* /home/$user/"); + } + else { + assert_script_run("mkdir /home/$user/$data"); + assert_script_run("cp $data/* /home/$user/$data/"); + } + # Delete the temporary directory and the downloaded file. + assert_script_run("cd"); + assert_script_run("rm -rf /home/$user/temp"); + # Change ownership + assert_script_run("chown -R test:test /home/$user/"); +} + +# On Fedora, the serial console is not writable for regular users which lames +# some of the openQA commands that send messages to the serial console to check +# that a command has finished, for example assert_script_run, etc. +# This routine changes the rights on the serial console file and makes it +# writable for everyone, so that those commands work. This is actually very useful +# for testing commands from users' perspective. The routine also handles becoming the root. +# We agree that this is not the "correct" way, to enable users to type onto serial console +# and that it correctly should be done via groups (dialout) but that would require rebooting +# the virtual machine. Therefore we do it this way, which has immediate effect. +sub make_serial_writable { + become_root(); + sleep 2; + # Make serial console writable for everyone. + enter_cmd("chmod 666 /dev/${serialdev}"); + sleep 2; + # Exit the root account + enter_cmd("exit"); + sleep 2; +} + +# Sometimes, especially in between freezes, there are Software Updates available +# that trigger a notification pop-up which covers some part of the screen +# and possibly steals focus from the applications, thus making tests to fail. +# This will set the update notification timestamp to the current time (-30 seconds), +# forcing the notification mechanism to think it already had notified. +# Note, that this has to be run under the user under which the tests run, +# not root. +sub set_update_notification_timestamp { + # Get the current time + my $ep_time = time(); + # Subtract 30 seconds from the number. + $ep_time -= 30; + # Run a command using the command dialogue + send_key('alt-f2'); + wait_still_screen(2); + # Set the new timestamp using the gsettings command. + type_very_safely("gsettings set org.gnome.software update-notification-timestamp $ep_time\n"); +} + +# This routine takes a list of applications. It will then use the terminal +# to start all these applications in the background and then it will exit the +# terminal. This is useful when we want to start multiple applications quickly. +sub start_applications { + my @applications = @_; + # Open the terminal + desktop_launch_terminal(); + assert_screen("apps_run_terminal"); + wait_still_screen(2); + # Iterate over the application list + # and start each application from it. + foreach (@applications) { + assert_script_run("$_ &"); + # Take some time for things to settle. + wait_still_screen(1); + } + # Exit the terminal. + enter_cmd("exit"); +} + +# this is a workaround for an annoying KDE bug where the first character +# typed into the launcher is often repeated. I think it's due to KDE +# working hard to cache all the launchers, or something, so we try to +# work around it by doing a 'throwaway' open, type a 'k', wait a bit, +# close operation before we do anything 'real'. this is repeated in +# several tests so we share it here +sub kde_doublek_workaround { + my %args = @_; + $args{key} //= 'k'; + wait_screen_change { send_key 'super'; }; + wait_still_screen 3; + send_key $args{key}; + wait_still_screen 5; + send_key 'esc'; + wait_still_screen 3; +} + +# handle login at a graphical DM once we have reached the initial +# DM screen. Factored out of _graphical_wait_login for reuse by +# tests that reboot and need to login afterwards +sub dm_perform_login { + my ($desktop, $password) = @_; + # GDM 3.24.1 dumps a cursor in the middle of the screen here... + mouse_hide; + if ($desktop eq 'gnome') { + # we have to hit enter to get the password dialog, and it + # doesn't always work for some reason so just try it three + # times + send_key_until_needlematch("graphical_login_input", "ret", 3, 5); + } + assert_screen "graphical_login_input"; + # seems like we often double-type on aarch64 if we start right + # away + wait_still_screen(stilltime => 5, similarity_level => 38); + if (get_var("SWITCHED_LAYOUT")) { + # see _do_install_and_reboot; when layout is switched + # user password is doubled to contain both US and native + # chars + desktop_switch_layout 'ascii'; + type_very_safely $password; + desktop_switch_layout 'native'; + type_very_safely $password; + } + else { + type_very_safely $password; + } + send_key "ret"; +} + 1; diff --git a/tests/applications/clocks/aaa_setup.pm b/tests/applications/clocks/aaa_setup.pm new file mode 100644 index 00000000..6ea1d232 --- /dev/null +++ b/tests/applications/clocks/aaa_setup.pm @@ -0,0 +1,47 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# This script will start the Gnome Clocks application and save the status +# for any subsequent tests. + +sub run { + my $self = shift; + + # At first, we need to set time and time zones manually. + $self->root_console(tty => 3); + # Switch off automatic time. + assert_script_run("timedatectl set-ntp 0"); + # Set the time zone + assert_script_run("timedatectl set-timezone Europe/Prague"); + # Set the time and date + assert_script_run("timedatectl set-time '2022-09-09 09:00:00'"); + # Return back + desktop_vt(); + + # Set the update notification timestamp + set_update_notification_timestamp(); + + # Start the Application + menu_launch_type("clocks"); + assert_screen ["apps_run_clocks", "grant_access"]; + # give access rights if asked + if (match_has_tag 'grant_access') { + click_lastmatch; + assert_screen 'apps_run_clocks'; + } + + # Make it fill the entire window. + send_key("super-up"); + wait_still_screen(2); +} + +sub test_flags { + # If this test fails, there is no need to continue. + return {fatal => 1, milestone => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/about.pm b/tests/applications/clocks/about.pm new file mode 100644 index 00000000..4bda6811 --- /dev/null +++ b/tests/applications/clocks/about.pm @@ -0,0 +1,29 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able use the menu to enter further functions. + +sub run { + my $self = shift; + + # Click on the burger menu. + assert_and_click("gnome_burger_menu"); + + # Click on About Clocks to see the About info. + assert_and_click("clocks_menu_about"); + assert_screen("clocks_about_displayed"); + assert_and_click("gnome_button_credits"); + assert_screen("clocks_credits_shown"); + +} + +sub test_flags { + # Rollback after test is over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/alarm.pm b/tests/applications/clocks/alarm.pm new file mode 100644 index 00000000..8d2ef5b5 --- /dev/null +++ b/tests/applications/clocks/alarm.pm @@ -0,0 +1,68 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able to add, edit and remove alarms. + +sub run { + my $self = shift; + + # Click on the Alarm button. + assert_and_click("clocks_button_alarm"); + + # Add a new alarm using the Add Alarm button + assert_and_click("clocks_button_add_alarm"); + assert_and_click("clocks_alarm_hour"); + wait_still_screen 2; + send_key("ctrl-a"); + wait_still_screen(2); + type_very_safely("09"); + send_key("tab"); + type_very_safely("04"); + assert_and_click("clocks_set_snooze"); + assert_and_click("clocks_set_snooze_time"); + assert_and_click("gnome_add_button"); + assert_screen("clocks_alarm_active"); + + # Wait until the alarm goes on, two buttons will be shown. This should not take + # more than three minutes. + # A snooze button should become visible, click it. + assert_and_click("clocks_button_alarm_snooze", timeout => 240); + assert_screen("clocks_alarm_snooze_confirmed"); + # After another minute or so, the alarm should ring again. + # This time we will use the stop button to stop it. + assert_and_click("clocks_button_alarm_stop", timeout => 120); + # Up to 46.0, the alarm would stay active after being stopped; from + # 46.0 onwards it goes inactive. FIXME this can be simplified to + # assume it starts at 'inactive' once we are no longer testing + # < 46.0 anywhere + assert_screen(["clocks_alarm_active", "clocks_alarm_inactive"]); + my $wasactive = match_has_tag("clocks_alarm_active"); + # Now toggle the switch to change its state + assert_and_click("gnome_button_toggle"); + # whichever state it was in, check it's now in the other + if ($wasactive) { + assert_screen("clocks_alarm_inactive"); + } + else { + assert_screen("clocks_alarm_active"); + } + # Delete alarm using the delete button. + assert_and_click("gnome_button_cross_remove"); + sleep 2; + if (check_screen(["clocks_alarm_active", "clocks_alarm_inactive"])) { + die("The alarm should have been deleted but it is still visible in the GUI"); + } + + +} + +sub test_flags { + # Rollback after test is over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/help.pm b/tests/applications/clocks/help.pm new file mode 100644 index 00000000..8f29e35a --- /dev/null +++ b/tests/applications/clocks/help.pm @@ -0,0 +1,24 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able use the menu to enter further functions. + +sub run { + my $self = shift; + + # Click on the burger menu and display Help. + assert_and_click("gnome_burger_menu"); + assert_and_click("clocks_menu_help"); + assert_screen("clocks_help_shown"); +} + +sub test_flags { + # Rollback after test is over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/shortcuts.pm b/tests/applications/clocks/shortcuts.pm new file mode 100644 index 00000000..29124cf5 --- /dev/null +++ b/tests/applications/clocks/shortcuts.pm @@ -0,0 +1,24 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able use the menu to enter further functions. + +sub run { + my $self = shift; + + # Use the menu to see the shortcuts + assert_and_click("gnome_burger_menu"); + assert_and_click("clocks_menu_shortcuts"); + assert_screen("clocks_shortcuts_shown"); +} + +sub test_flags { + # Rollback after test is over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/stopwatch.pm b/tests/applications/clocks/stopwatch.pm new file mode 100644 index 00000000..289ac161 --- /dev/null +++ b/tests/applications/clocks/stopwatch.pm @@ -0,0 +1,52 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able to measure time using stopwatch. + +sub run { + my $self = shift; + + # Click on the Stopwatch button. + assert_and_click("clocks_button_stopwatch"); + + # Start the stopwatch, pause it, resume, and clear. + assert_and_click("clocks_stopwatch_button_start"); + # Wait some time and pause the stopwatch, read the + # time. + sleep(20); + assert_and_click("clocks_stopwatch_button_pause", timeout => 2); + assert_screen("clocks_stopwatch_time_reached"); + # Resume the measurement. + assert_and_click("clocks_stopwatch_button_resume"); + sleep(10); + # Press pause and read the time. + assert_and_click("clocks_stopwatch_button_pause", timeout => 2); + assert_screen("clocks_stopwatch_secondtime_reached"); + # Clear the stopwatch and check you can start it again. + assert_and_click("clocks_stopwatch_button_clear"); + assert_screen("clocks_stopwatch_button_start"); + + # Start the stopwatch, count several laps and assert. + assert_and_click("clocks_stopwatch_button_start"); + sleep(10); + assert_and_click("clocks_stopwatch_button_lap"); + sleep(10); + assert_and_click("clocks_stopwatch_button_lap"); + sleep(10); + assert_and_click("clocks_stopwatch_button_lap"); + assert_and_click("clocks_stopwatch_button_pause"); + assert_screen("clocks_stopwatch_laps_count"); + assert_screen("clocks_stopwatch_laps_times"); + assert_screen("clocks_stopwatch_laps_deltas"); +} + +sub test_flags { + # Rollback when tests are over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/timer.pm b/tests/applications/clocks/timer.pm new file mode 100644 index 00000000..867441f9 --- /dev/null +++ b/tests/applications/clocks/timer.pm @@ -0,0 +1,41 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able to add, edit and remove timers. + +sub run { + my $self = shift; + + # Click on the Timer button. + assert_and_click("clocks_button_timer"); + + # Add a new alarm using the one minute button + assert_screen("clocks_timer_page"); + assert_and_click("clocks_button_timer_minute"); + # since GNOME 46, that was a 'quickstart', on older GNOME we + # have to hit start; remove this when no more F39 testing + if (check_screen("clocks_button_timer_start", 5)) { + wait_still_screen(2); + click_lastmatch; + } + sleep(10); + assert_and_click("clocks_button_timer_pause"); + assert_screen("clocks_timer_paused"); + assert_and_click("clocks_button_timer_start"); + # Wait a minute if the timer goes off. + assert_screen("clocks_timer_finished", timeout => 60); + # Delete the timeout + assert_and_click("gnome_button_delete"); + assert_screen("clocks_timer_page"); +} + +sub test_flags { + # Rollback after test is over. + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/clocks/world.pm b/tests/applications/clocks/world.pm new file mode 100644 index 00000000..3e229fb0 --- /dev/null +++ b/tests/applications/clocks/world.pm @@ -0,0 +1,60 @@ +use base "installedtest"; +use strict; +use testapi; +use utils; + +# I as a user want to be able to add a new city in the World clock. + +sub run { + my $self = shift; + + # Click on the World button. + assert_and_click("clocks_button_world"); + + # Add a new location using the addition icon + assert_and_click("gnome_add_button_plus"); + wait_still_screen(2); + type_very_safely("Bratislava"); + assert_and_click("gnome_city_button_bratislava"); + assert_and_click("gnome_add_button"); + wait_still_screen(2); + diag("CLOCKS: Added the new city."); + # View city details + assert_and_click("clocks_city_added_bratislava"); + assert_screen("clocks_city_details"); + diag("CLOCKS: Details shown."); + + # Return back to overview + assert_and_click("clocks_button_back"); + assert_screen("clocks_city_added_bratislava"); + + # Add a new location using the keyboard shortcut + send_key("ctrl-n"); + wait_still_screen(2); + type_very_safely("Reykjav"); + assert_and_click("gnome_city_button_reykjavik"); + assert_and_click("gnome_add_button_blue"); + assert_screen("clocks_city_added_reykjavik"); + + # Click onto the Delete button to remove the listed cities. + # While there are cities to be removed, remove them. + while (check_screen("gnome_button_cross_remove", 3)) { + click_lastmatch(); + mouse_hide; + } + # If the cities are still visible, then die. + if (check_screen("clocks_city_added_bratislava")) { + die("The city Bratislava should have been removed, but it is still visible on the screen."); + } + if (check_screen("clocks_city_added_reykjavik")) { + die("The city Reykjavik should have been removed, but it is still visible on the screen."); + } +} + +sub test_flags { + return {always_rollback => 1}; +} + +1; + +# vim: set sw=4 et: diff --git a/tests/applications/evince/aaa_setup.pm b/tests/applications/evince/aaa_setup.pm index a0055366..703b8023 100644 --- a/tests/applications/evince/aaa_setup.pm +++ b/tests/applications/evince/aaa_setup.pm @@ -25,7 +25,7 @@ sub download_testdata { # Change ownership and attributes assert_script_run("chown -R test:test openqa_testdata"); # Move the test file into a correct location. - assert_script_run("cp openqa_testdata/evince/evince.pdf Documents"); + assert_script_run("cp openqa_testdata/documents/evince.pdf Documents"); } sub run {