#182 Add support for mouse dragging.
Closed 3 years ago by adamwill. Opened 3 years ago by lruzicka.

file modified
+88 -3
@@ -7,7 +7,9 @@ 

  

  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 @@ 

  }

  

  # 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 @@ 

      }

  }

  

+ # 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;

Mouse drag is not implemented the testapi and to use its workaround is not very convenient. The feature has been requested a long time ago at OpenSuse but its priority has been lowered to Low a couple of months back, so we might assume that this functionality will not be implemented
any time soon. Therefore, I have created our own mouse_drag subroutine that uses the workaround, but added the needle support, so the starting point of the mouse drag can be specified using a needle. The release point is given in absolute numbers (however, maybe we could also use a needle for it in the future)

The function takes the following arguments:

  • the needle tag (for the click and hold point)
  • the button to tell which button to use
  • the xend and yend coordinates to specify the release point
  • the timeout to pass to the assert_needle used to confirm the click point needle exists.

Syntax: mouse_drag("needle", button => 'left', xend => '300', yend => '200', timeout => 30);

I have tested it in my home instance and it works there.

Metadata Update from @lruzicka:
- Pull-request tagged with: improvetest
- Request assigned

3 years ago

1 new commit added

  • Clean whitespaces.
3 years ago

Build succeeded.

Why not just submit this to os-autoinst upstream? Priority low means no-one at SUSE is going to be prioritizing it, but as it's a valid feature request I'm sure they'd consider a PR from us to add it.

Gladly, but where to put such a subroutine? testapi ?

that's where I'd propose it, yeah. if they don't take it, no harm done, we can come back to this PR instead :)

btw, one suggestion: you might want to make it more flexible - allow start and end to both be either a co-ordinate or a needle.

that's where I'd propose it, yeah. if they don't take it, no harm done, we can come back to this PR instead :)

btw, one suggestion: you might want to make it more flexible - allow start and end to both be either a co-ordinate or a needle.

Ok, I can redo it. Thanks for a good idea. :D

1 new commit added

  • Make the mouse_drag function more universal
3 years ago

Build failed.

1 new commit added

  • Fix typos
3 years ago

Build failed.

1 new commit added

  • Move variable definition out of if statement.
3 years ago

Build failed.

The tox failure here looks like something changed in softwarefactory, I think...don't think it's your fault...

Yes, I did not change anything about python or something. I will need to test the subroutine in the real environment now, but at least the code is now written correctly. :)

running 'tox' locally should work.

Build succeeded.

1 new commit added

  • Make the subroutine work.
3 years ago

Build succeeded.

1 new commit added

  • Finalize and error proof the function.
3 years ago

Build failed.

1 new commit added

  • Fix variable assignment.
3 years ago

1 new commit added

  • Assign in the main body.
3 years ago

Build succeeded.

1 new commit added

  • Delete useless my statements.
3 years ago

1 new commit added

  • Delete redundant values.
3 years ago

Build succeeded.

rebased onto b7689cd

3 years ago

Build succeeded.

The fork looks fine. You will want to have a more detailed commit message, and I'd also probably suggest that instead of effectively copying 80% of click_lastmatch twice, it would be a better idea to add a new non-exported sub that does most of click_lastmatch's work and make both click_lastmatch and mouse_drag use that. Or you could extend click_lastmatch's behaviour to be more flexible in terms of what button click and mouse move actions it does, I guess, and just have mouse_drag call it. Either way...

I see your point. Here is another attempt: https://github.com/os-autoinst/os-autoinst/compare/master...lruzicka:master

I think this is the maximum I dare to go. I also do not know how to test it locally, because we do not have any testapi.pm in our version of os-autoinst. In the documentation, SuSE only describes how to do it on SUSE. Is there a Fedora way?

I see your point. Here is another attempt: https://github.com/os-autoinst/os-autoinst/compare/master...lruzicka:master

I think this is the maximum I dare to go. I also do not know how to test it locally, because we do not have any testapi.pm in our version of os-autoinst. In the documentation, SuSE only describes how to do it on SUSE. Is there a Fedora way?

Eh? Sure we do:

[adamwill@openqa-x86-worker04 ~][PROD-IAD2]$ rpm -ql os-autoinst | grep testapi
/usr/libexec/os-autoinst/testapi.pm
/usr/share/doc/os-autoinst/testapi.html

that first one is the relevant file. I would either just overwrite your local copy of the file on a test box, or (cleaner but more work) rebuild the os-autoinst RPM with your change applied as a patch.

Ha, thanks, I was trying something similar to our os-autoinst-fedora because the names looked similar to me. I located the file and i am just trying that out.

So, the enhancement seems to be working normally in my test machine, so I am going to rewrite the commit message and open the PR at SuSE's.

This got merged upstream, so closing this downstream version. I've backported it to the Fedora packages already.

Pull-Request has been closed by adamwill

3 years ago