#137 Create an automated test to test printing on Desktop
Merged 4 years ago by adamwill. Opened 4 years ago by lruzicka.

@@ -0,0 +1,15 @@ 

+ {

+   "area": [

+     {

+       "xpos": 363,

+       "ypos": 143,

+       "width": 187,

+       "height": 17,

+       "type": "match"

+     }

+   ],

+   "properties": [],

+   "tags": [

+     "printing_check_sentence"

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_print"

+   ],

+   "area": [

+     {

+       "xpos": 790,

+       "ypos": 134,

+       "width": 40,

+       "height": 19,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_print_completed"

+   ],

+   "area": [

+     {

+       "xpos": 356,

+       "ypos": 49,

+       "width": 76,

+       "height": 16,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_select_pdfprinter"

+   ],

+   "area": [

+     {

+       "xpos": 185,

+       "ypos": 270,

+       "width": 99,

+       "height": 19,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_check_sentence"

+   ],

+   "area": [

+     {

+       "xpos": 252,

+       "ypos": 134,

+       "width": 300,

+       "height": 24,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_check_sentence"

+   ],

+   "area": [

+     {

+       "xpos": 247,

+       "ypos": 136,

+       "width": 305,

+       "height": 20,

+       "type": "match"

+     }

+   ]

+ }

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "area": [

+     {

+       "type": "match",

+       "xpos": 246,

+       "height": 20,

+       "width": 305,

+       "ypos": 136

+     }

+   ],

+   "properties": [],

+   "tags": [

+     "printing_check_sentence"

+   ]

+ } 

\ No newline at end of file

@@ -0,0 +1,22 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_pdfprinter_ready"

+   ],

+   "area": [

+     {

+       "xpos": 377,

+       "ypos": 98,

+       "width": 69,

+       "height": 18,

+       "type": "match"

+     },

+     {

+       "xpos": 377,

+       "ypos": 97,

+       "width": 69,

+       "height": 20,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
@@ -0,0 +1,15 @@ 

+ {

+   "properties": [],

+   "tags": [

+     "printing_print"

+   ],

+   "area": [

+     {

+       "xpos": 561,

+       "ypos": 229,

+       "width": 57,

+       "height": 19,

+       "type": "match"

+     }

+   ]

+ } 

\ No newline at end of file

empty or binary file added
file modified
+43
@@ -460,6 +460,28 @@ 

                      },

                      {

                        machine    => { name => "64bit" },

+                       prio       => 20,

+                       product    => {

+                                       arch    => "x86_64",

+                                       distri  => "fedora",

+                                       flavor  => "Workstation-live-iso",

+                                       version => "*",

+                                     },

+                       test_suite => { name => "desktop_printing" },

+                     },

+                     {

+                       machine    => { name => "64bit" },

+                       prio       => 20,

+                       product    => {

+                                       arch    => "x86_64",

+                                       distri  => "fedora",

+                                       flavor  => "KDE-live-iso",

+                                       version => "*",

+                                     },

+                       test_suite => { name => "desktop_printing" },

+                     },

+                     {

+                       machine    => { name => "64bit" },

                        prio       => 22,

                        product    => {

                                        arch    => "x86_64",
@@ -1940,6 +1962,18 @@ 

                                        flavor  => "Workstation-live-iso",

                                        version => "*",

                                      },

+                       test_suite => { name => "desktop_printing" },

+                     },

+                     {

+                       group_name => "Fedora PowerPC",

+                       machine    => { name => "ppc64le" },

+                       prio       => 20,

+                       product    => {

+                                       arch    => "ppc64le",

+                                       distri  => "fedora",

+                                       flavor  => "Workstation-live-iso",

+                                       version => "*",

+                                     },

                        test_suite => { name => "desktop_browser" },

                      },

                      {
@@ -5392,6 +5426,15 @@ 

                        ],

                      },

                      {

+                       name => "desktop_printing",

+                       settings => [

+                         { key => "POSTINSTALL", value => "desktop_printing" },

+                         { key => "START_AFTER_TEST", value => "install_default_upload" },

+                         { key => "BOOTFROM", value => "c" },

+                         { key => "HDD_1", value => "disk_%FLAVOR%_%MACHINE%.qcow2" },

+                       ],

+                     },

+                     {

                        name => "desktop_terminal",

                        settings => [

                          { key => "POSTINSTALL", value => "desktop_terminal" },

@@ -0,0 +1,80 @@ 

+ use base "installedtest";

+ use strict;

+ use testapi;

+ use utils;

+ 

+ sub run {

+     my $self = shift;

+     # Prepare the environment:

+     #

+     # Become root

+     $self->root_console(tty=>3);

+ 

+     # Create a text file with content to print

+     script_run  "cd /home/test/";

+     assert_script_run  "echo 'A quick brown fox jumps over a lazy dog.' > testfile.txt";

+     script_run "chmod 666 testfile.txt";

+     # Install the Cups-PDF package to use the Cups-PDF printer

+     assert_script_run "dnf -y install cups-pdf", 180;

+     # Leave the root terminal and switch back to desktop.

+     desktop_vt();

+     my $desktop = get_var("DESKTOP");

+     # some simple variances between desktops. defaults are for GNOME

+     my $editor = "gedit";

+     my $viewer = "evince";

+     my $maximize = "super-up";

+     if ($desktop eq "kde") {

+         $editor = "kwrite";

+         $viewer = "okular";

+         $maximize = "super-pgup";

+     }

+ 

+     # Open the text editor and print the file.

+     send_key "alt-f2";

+     wait_still_screen(stilltime=>5, similarity_level=>45);

+     type_safely "$editor /home/test/testfile.txt\n";

+     wait_still_screen(stilltime=>5, similarity_level=>44);

+     # Print the file using the Cups-PDF printer

+     send_key "ctrl-p";

+     wait_still_screen(stilltime=>5, similarity_level=>45);

+     if ($desktop eq 'gnome') {

+         assert_and_click "printing_select_pdfprinter";

+     }

+     else {

+         # It seems that on newly installed KDE systems with no

+         # printer,  the Cups-PDF printer is already pre-selected.

+         # We only check that it is correct.

+         assert_screen "printing_pdfprinter_ready";

+     }

+     wait_still_screen(stilltime=>2, similarity_level=>45);

+     assert_and_click "printing_print";

+     # Exit the application

+     send_key "alt-f4";

+     # Wait out confirmation on GNOME

+     if (check_screen "printing_print_completed", 1) {

+         sleep 30;

+     }

+ 

+     # Open the pdf file and check the print

+     send_key "alt-f2";

+     wait_still_screen(stilltime=>5, similarity_level=>45);

+     type_safely "$viewer /home/test/Desktop/testfile.pdf\n";

+     wait_still_screen(stilltime=>5, similarity_level=>45);

+     # Resize the window, so that the size of the document fits the bigger space

+     # and gets more readable.

+     send_key $maximize;

+     wait_still_screen(stilltime=>2, similarity_level=>45);

+     # make sure we're at the start of the document

+     send_key "ctrl-home" if ($desktop eq "kde");

+     # Check the printed pdf.

+     assert_screen "printing_check_sentence";

+ }

+ 

+ 

+ sub test_flags {

+     return { fatal => 1 };

+ }

+ 

+ 1;

+ 

+ # vim: set sw=4 et:

  • Gnome printing test on x86_64 and ppc641e
  • KDE printing test on x86_64

Metadata Update from @lruzicka:
- Request assigned

4 years ago

rebased onto 11fece7cb73606f892840359579f9217ccb7b3d0

4 years ago

This includes a bunch of Xfce needles but no Xfce tests, it seems. Also the printing_change_zoom needle doesn't appear to be used anywhere, and why do we need _kde versions of a lot of the needle tags? Why not just use the same tags for KDE and GNOME? Also, why have two completely different test flows for KDE and GNOME? I feel you could reconcile them quite easily and save quite some space, it just requires a few conditionals.

This includes a bunch of Xfce needles but no Xfce tests, it seems.

Arghh, yes. Originally, I created the Xfce version, too, but then I realized that we do not run any Xfce related tests, even on arm. So I deleted it again. Forgot about the needles.

Also the printing_change_zoom needle doesn't appear to be used anywhere, and w>hy do we need _kde versions of a lot of the needle tags? Why not just use the same tags for KDE and GNOME?

I can do that, but we still need two needles for one tag, so I thought that it would not mind, if the tag is specified.

Also, why have two completely different test flows for KDE and GNOME? I feel you could reconcile them quite easily and save quite some space, it just requires a few conditionals.

Because, this was much easier to write, than to create conditionals for every difference between Gnome and KDE. It is not just that it uses different applications, but the applications also behave differently, so I thought that copying the skeleton of the code and replacing the differences is much more straightforward and more readable than to create a conditional for
every difference, which was my original intention.

However, if you insist, I can rewrite it, I just don't believe it serves a better purpose.

1 new commit added

  • Delete needles for xfce
4 years ago

What I could do, is to avoid using applications altogether and I could only print a Test page instead, that would simplify the process a lot. However, can it happen that a test page is printed, but applications cannot print? I don't know.

1 new commit added

  • Delete kde specs from the tags.
4 years ago

1 new commit added

  • Delete unused needles to handle document zoom.
4 years ago

rebased onto aab56ffc53ea9c0eed13b64d5c6e61c759303c47

4 years ago

rebased onto fd407a590834542e63c02dea40ebd5e09648e383

4 years ago

So, a few more notes:

  • There are still a ton of unused needles here, presumably ones you used in earlier versions of the test and forgot to remove when you took them out. Please check all needle tags against what's actually in the commit and remove the unused ones. Please do this in general for future PRs - when you change the test logic, remember to check for no-longer-needed needles and remove them
  • The needle name okular_menu_beginning_document_grey reads like it's a variant on the okular_menu_beginning_document needle, but it literally has the tag okular_menu_beginning_document_grey which is not used in the test at all. Is it meant to have the tag okular_menu_beginning_document or is it a useless needle?
  • What's the point of going into Settings at all? All we do is check the printer is there and then leave. If it's not there we'll just find out later on anyway, so why bother doing this?
  • I still think we can combine the KDE and GNOME flows quite nicely

I have created a branch, printing-adamw, with a single commit. I took your current state, dropped all the Settings bits, merged the GNOME and KDE workflows, dropped all the unused needles, fixed the tag on printing_check_sentence_kde_alt.json, simplified the 'go to start of document' bit in Okular (there's a keyboard shortcut), added another variant on the 'check sentence' needle that seems to be needed for some reason, and squashed all the commits down into one. Can you take a look at that and see what you think? Thanks.

The check_sentence thing on KDE is a bit funky, honestly - I don't know why the kerning gets messed up like that. I poked around quite a lot with zoom options in Okular but couldn't really get anything more reliable in the end so I just added another needle to cover me getting slightly different funky kerning when running the test on today's Rawhide vs. whatever you ran it on to get the funky kerning in the _alt needle.

Oh, another thought, we could probably run this test on updates too.

So, a few more notes:

There are still a ton of unused needles here, presumably ones you used in earlier versions of the test and forgot to remove when you took them out. Please check all needle tags against what's actually in the commit and remove the unused ones. Please do this in general for future PRs - when you change the test logic, remember to check for no-longer-needed needles and remove them

I will probably have to think about a different needle workflow, something like put all the needles into one directory and when the test finally works, redistribute them. Otherwise, I get too much excited about the passing status and forget about it. I will try harder in the future, but there might be slips.

The needle name okular_menu_beginning_document_grey reads like it's a variant on the okular_menu_beginning_document needle, but it literally has the tag okular_menu_beginning_document_grey which is not used in the test at all. Is it meant to have the tag okular_menu_beginning_document or is it a useless needle?

For developing the test, I was using a virtual machine created by createhdds.py and I also opened it in virt-manager to try some tricks and the last status of okular was remembered, so it started to appear as full screen and the test logic could not handle it, so I thought that I might be able to distinguish checking the needles. In the end, I went to that VM again and reset the status, so it did not start as full screen any longer. So that may be well an unused needle. I will have to check.

What's the point of going into Settings at all? All we do is check the printer is there and then leave. If it's not there we'll just find out later on anyway, so why bother doing this?

True. However, I thought that if the printer appears in system is a good thing to check. It somehow completes the "printer addition" process in my belief.

I still think we can combine the KDE and GNOME flows quite nicely

You did that well.

I have created a branch, printing-adamw, with a single commit. I took your current state, dropped all the Settings bits, merged the GNOME and KDE workflows, dropped all the unused needles, fixed the tag on printing_check_sentence_kde_alt.json, simplified the 'go to start of document' bit in Okular (there's a keyboard shortcut), added another variant on the 'check sentence' needle that seems to be needed for some reason, and squashed all the commits down into one. Can you take a look at that and see what you think? Thanks.

I think it is brilliant. I was thinking about variables used like that, but I was not sure I could also make a variable with super-pgup in it. Also ctrl-home did not work for me somehow. The code really looks well and there were not as many conditions needed as I thought. So, yeah, I must admit you were right about it.

What am I to do now? I do not think there's much to do. When you have done the polishing work, we can just merge your stuff, can't we? Or do you want me to practise?

The check_sentence thing on KDE is a bit funky, honestly - I don't know why the kerning gets messed up like that. I poked around quite a lot with zoom options in Okular but couldn't really get anything more reliable in the end so I just added another needle to cover me getting slightly different funky kerning when running the test on today's Rawhide vs. whatever you ran it on to get the funky kerning in the _alt needle.

I was developing on Fedora 31, and I could not find a way to handle the rendering of the test sentence, so I needed the _alt needle to cover the weird appearance in KDE. Originally, I thought to use the zoom settings, but I still cannot figure out the pull-down menus. Sometimes, it works, the menu opens and lets me click on items, sometimes it does not. I do not know if I need to wait between the steps, or when OpenQA moves the mouse, it disappears. A human being would keep the mouse on it, while clicking, but the machine must move it in order to be able to assert properly, so that can be the case. I try to avoid them as much as possible.

What do these do? The stilltime parameter is clear, but what is similarity_level?

wait_still_screen(stilltime=>2, similarity_level=>45);

it's how similar the screenshot needs to be to the previous screenshot to be considered 'still'. The max value I believe is 50, the default threshold is 47. The problem with 47 is that when there's a flashing cursor on the screen, the similarity value between screenshots usually goes under 47, so you just wind up waiting through the entire 30 second timeout. Dropping the threshold to 45 usually solves that (in one case here I had to drop it to 44).

So on making a variable with super-pgup in it - there's nothing magic about the values passed to send_key, really, they're just strings. So of course you can use string variables. There's code in the back end that parses the string and translates it to keycodes for the actual pressing. It has logic to split key combinations when it sees a -, and there's a lookup table for keys like super and pgup and space and so on; the keys that are ASCII characters are converted using an ASCII code lookup IIRC. If you manage to send the function a string it can't parse into identifiable key presses the test will blow up on you.

For the KDE rendering thing - there are keyboard shortcuts for zooming too (ctrl-+ zooms in, ctrl-- zooms out, ctrl-0 zooms to 100%) but I couldn't actually find a way to use them that would reliably make Okular render the text in the PDF at 'native' size, so I gave up on it in the end. If you want to use a menu where you have to hold down the mouse button to keep the menu visible, I think it's a bit tricky; there isn't actually a testapi function for 'press but don't release mouse button' AFAICS. There's hold_key and release_key but not hold_button and release_button. You'd have to use query_isotovideo directly to do it yourself, I think.

Since you like my branch I'll go ahead and merge it. You don't need to do anything more, I just wanted to give you a chance to look over it and see the changes before merging it :)

rebased onto 345a9683ce2fcb840d50672b3880e2c6faaba0aa

4 years ago

rebased onto cbe3d976696271447296a0d313ee5495d78c74ec

4 years ago

rebased onto 77ae127

4 years ago

Haha, just caught another bug before I merged - it's ppc64le, not ppc641e! The character before 'e' is the letter 'l', not the number '1'. :)

Pull-Request has been merged by adamwill

4 years ago