diff --git a/lib/utils.pm b/lib/utils.pm index ea12c705..b807b27e 100644 --- a/lib/utils.pm +++ b/lib/utils.pm @@ -7,7 +7,9 @@ use Exporter; 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 setup_workaround_repo cleanup_workaround_repo 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 bypass_1691487 get_release_number workaround_ble26 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/; +use autotest "query_isotovideo"; + +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 setup_workaround_repo cleanup_workaround_repo 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 bypass_1691487 get_release_number workaround_ble26 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 mouse_drag/; # We introduce this global variable to hold the list of applications that have # registered during the apps_startstop_test when they have sucessfully run. @@ -1276,8 +1278,8 @@ sub register_application { } # The KDE desktop tests are very difficult to maintain, because the transparency -# of the menu requires a lot of different needles to cover the elements. -# Therefore it is useful to change the background to a solid colour. +# of the menu requires a lot of different needles to cover the elements. +# Therefore it is useful to change the background to a solid colour. # Since many needles have been already created with a black background # we will keep it that way. The following code has been taken from the # KDE startstop tests but it is good to have it here, because it will be @@ -1326,4 +1328,87 @@ sub solidify_wallpaper { } } +# Mouse drags are not implemented yet in testapi and the importance of such proposal has been +# recently lowered to "Low" so we might assume that this functionality will not be implemented +# any time soon. Therefore, let's to do it by ourselves. +# +# The function can either use the cartesian coordinates or a needle that provides them. If both +# are given, the function prefers the coordinates to the needles. Combinations are allowed, i.e. +# one point can be given using coordinates, while the other can be given as a needle. +# If neither are correctly provided, the functions terminates with an error message. +# +# The $button variable specifies which button should be used to drag. The $timeout tells the engine +# how long to wait for the needle to appear. +# +# Syntax +# using needles: +# mouse_drag(startpoint => "needle1", endpoint => "needle2", button => 'left', timeout => 30); +# using coordinates: +# mouse_drag(startx => "300", starty => "200", endx => "390", endy => "250", button => 'left', timeout => 30); +# using a combination: +# mouse_drag(startpoint => "needle1", endx => "390", endy => "250", button => 'left', timeout => 30); +sub mouse_drag { + my %args = @_; + my $startx = + my $starty = + my $endx = + my $endy = 0; + # If full coordinates are provided, work with them as a priority, + if (defined $args{startx} and defined $args{starty}) { + $startx = $args{startx}; + $starty = $args{starty}; + } + # If the coordinates were not complete, use the needle as a fallback solution. + elsif (defined $args{startpoint}) { + my $startmatch = $args{startpoint}; + # Check that the needle exists. + my $start_matched_needle = assert_screen($startmatch, $args{timeout}); + # Calculate the click point from the area defined by the needle (take the center of it) + my $start_area = $start_matched_needle->{area}->[-1]; + my $start_click_point = { + xpos => $start_area->{w} / 2, + ypos => $start_area->{h} / 2, + }; + $startx = int($start_area->{x} + $start_click_point->{xpos}); + $starty = int($start_area->{y} + $start_click_point->{ypos}); + } + # If neither coordinates nor a needle is provided, report an error and quit. + else { + die "The starting point of the drag was not correctly provided. Either provide the 'startx' and 'starty' coordinates, or a needle marking the starting point."; + } + + # Repeat the same for endpoint coordinates or needles. + if (defined $args{endx} and defined $args{endy}) { + $endx = $args{endx}; + $endy = $args{endy}; + } + elsif (defined $args{endpoint}) { + my $endmatch = $args{endpoint}; + my $end_matched_needle = assert_screen($endmatch, $args{timeout}); + my $end_area = $end_matched_needle->{area}->[-1]; + my $end_click_point = { + xpos => $end_area->{w} / 2, + ypos => $end_area->{h} / 2, + }; + $endx = int($end_area->{x} + $end_click_point->{xpos}); + $endy = int($end_area->{y} + $end_click_point->{ypos}); + } + else { + die "The ending point of the drag was not correctly provided. Either provide the 'endx' and 'endy' coordinates, or a needle marking the starting point."; + } + # Get the button variable. If no button has been provided, assume the "left" button. + my $button = $args{button} //= "left"; + + # Now, perform the actual mouse drag. Navigate to the startpoint location, + # press and hold the mouse button, then navigate to the endpoint location + # and release the mouse button. + mouse_set($startx, $starty); + query_isotovideo('backend_mouse_button', {button => $button, bstate => 1}); + mouse_set($endx, $endy); + query_isotovideo('backend_mouse_button', {button => $button, bstate => 0}); + + # Sleep for a while to leave a trace on the SUT video. + sleep("5"); +} + 1;