richelbilderbeek / testing_cpp_gui_applications_tutorial

Tutorial about testing C++ GUI applications
GNU General Public License v3.0
3 stars 0 forks source link

Replace wmctrl by superior alternative #5

Open richelbilderbeek opened 7 years ago

richelbilderbeek commented 7 years ago

I am happy to see Travis telling me:

ERROR: wmctrl not installed, type 'sudo apt-get install wmctrl' to install it

It appears @jorn600 did not need it. I will replace its use in my scripts.

richelbilderbeek commented 7 years ago

These are the scripts that use wmctrl:

richel@lubuntu:~/GitHubs/testing_cpp_gui_applications_tutorial/scripts$ egrep -iR "wmctrl"
is_wmctrl_present_test.sh:. is_wmctrl_present.sh
is_wmctrl_present_test.sh:is_present=`is_wmctrl_present`
is_wmctrl_present_test.sh:  echo "wmctrl is present"
is_wmctrl_present_test.sh:  echo "wmctrl is absent, type 'sudo apt-get install wmctrl' to install it"
is_dialog_present.sh:  id=`wmctrl -l | egrep "$@" | head -n 1 | cut -f 1 -d ' '`
is_wmctrl_present.sh:function is_wmctrl_present
is_wmctrl_present.sh:  command -v wmctrl >/dev/null 2>&1 || { echo 0; exit 0; }
get_dialog_id.sh:  echo `wmctrl -l | egrep "$*" | head -n 1 | cut -f 1 -d ' '`

The scripts that need to be improved:

richelbilderbeek commented 7 years ago

Travis does a great job to detect this need now:

1.01s$ ./get_dialog_id_test
get_dialog_id: line 8: wmctrl: command not found
Xlib:  extension "RANDR" missing on display ":99.0".
get_dialog_id: line 8: wmctrl: command not found
Error: should detect empty leafpad window
The command "./get_dialog_id_test" exited with 1.
richelbilderbeek commented 7 years ago

Works locally:

xlsclients -l | egrep --before-context=2 "Name:  Leafpad" | egrep "Window" | cut -f 1 -d ":" | cut -f 2 -d " "
0x2c00001
richelbilderbeek commented 7 years ago

get_dialog_id works fine on single instances of a window.

With multiple instances the error is:

./get_dialog_id_test: line 15: [: too many arguments
richelbilderbeek commented 7 years ago

Only select the first, before:

echo `xlsclients -l | egrep --before-context=2 "Name:.*$*" | egrep "Window" | cut -f 1 -d ":" | cut -f 2 -d " "`

now adding head -n 1

echo `xlsclients -l | egrep --before-context=2 "Name:.*$*" | egrep "Window" | cut -f 1 -d ":" | cut -f 2 -d " " | head -n 1`
richelbilderbeek commented 7 years ago

Currently, I grep for the Name.

xlsclients -l

gives

Applications after:
Window 0x2000002:
  Machine:  testing-gce-96e4d8ed-ad63-4987-bf0e-e151deedfa0f
  Name:  Dialog
  Command:  ./minimal_project
  Instance/Class:  minimal_project/Minimal_project

For minimal_project this would be Dialog (hey, that is the title of the window!).

Perhaps I should change to grep on the Command or Instance/Class?

richelbilderbeek commented 7 years ago

This is what select_class gives:

Window 0xa00002:
  Machine:  testing-gce-a7d3bf48-2384-4ab5-80da-c31003907c32
  Name:  Select a class
  Command:  ./select_class
  Instance/Class:  select_class/Select_class

And here we have leafpad and mousepad:

Window 0xa00001:
  Machine:  testing-gce-a7d3bf48-2384-4ab5-80da-c31003907c32
  Name:  mousepad
  Icon Name:  mousepad
  Command:  mousepad
  Instance/Class:  mousepad/Mousepad
Window 0xc00001:
  Machine:  testing-gce-a7d3bf48-2384-4ab5-80da-c31003907c32
  Name:  leafpad
  Icon Name:  leafpad
  Command:  leafpad
  Instance/Class:  leafpad/Leafpad