Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Sikuli working in headless mode

If we have a headless test server running sikuli (both ubuntu and windows configurations needed), how to get it work without a physical monitor and preferably for as many screen resolutions as possible.

like image 794
Amr Lotfy Avatar asked Sep 25 '14 07:09

Amr Lotfy


People also ask

Does Sikuli work on headless mode?

I got SikuliX working in a true headless mode in GCE with a Windows 2016 client system. It takes some duct tape and other Rube Goldberg contraptions to work, but it can be done.

Can Sikuli work in background?

In the normal situation, Sikuli scripts use the machine's screen, mouse and keyboard, so while a script is running, the machine may not be used. In this other Sikuli question about headless mode, a virtual screen is added to a second (headless) machine so that Sikuli scripts can operate there.

Can Sikuli be used with Python?

SikuliX supports the following as scripting languages: Python language level 2.7. Ruby language level 1.9 and 2.0. JavaScript.


2 Answers

I successfully got sikuli running in headless mode (no physical monitor connected)

Ubuntu: check Xvfb.

Windows: install display driver on the machine (to be headless) from virtualbox guest additions display drivers and use TightVNC to remotely set resolution from another machine.

Detailed steps for windows 7

Assume that:

  1. Machine A: to be headless machine, windows 7, with vnc server ready (e.g. TightVNC server installed and waiting for connections).
  2. Machine B: will be used to remotely setup the virtual display driver on machine A.

steps:

  1. Download virtualbox guest additions iso file on Machine A from here (for latest version check latest version here and download VBoxGuestAdditions_x.y.z.iso) enter image description here
  2. Extract iso file (possibly with winrar) into a directory (let us call it folder D) enter image description here
  3. using command prompt cd to D folder
  4. Driver extraction

    -To extract the 32-bit drivers to "C:\Drivers", do the following:

    • VBoxWindowsAdditions-x86 /extract /D=C:\Drivers

    -For the 64-bit drivers:

    • VBoxWindowsAdditions-amd64 /extract /D=C:\Drivers

    drivers extracted

  5. Goto device manager my computer/manage

  6. add hardwareenter image description here

  7. List item

  8. List item

  9. List item

  10. List item

  11. List item

  12. List item

  13. List item

  14. List item

  15. List item

  16. Restart and connect with VNC viewer, now you should be able to change screen resolution enter image description here

other valuable info on launchpad.

like image 197
Amr Lotfy Avatar answered Oct 11 '22 14:10

Amr Lotfy


I got SikuliX working in a true headless mode in GCE with a Windows 2016 client system. It takes some duct tape and other Rube Goldberg contraptions to work, but it can be done.

The issue is that, for GCE (and probably AWS and other cloud environment Windows clients), you don't have a virtual video adapter and display, so, unless there's an open RDP connection to the client, it doesn't have a screen, and SikuliX/OpenCV will get a 1024x768 black desktop, and fail.

So, the question is, how to create an RDP connection without having an actual screen anywhere. I did this using Xvfb (X Windows virtual frame buffer). This does require a second VM, though. Xvfb runs on Linux. The other piece of the puzzle is xfreerdp 2.0. The 2.x version is required for compatibility with recent versions of Windows. 1.x is included with some Linux distros; 2.x may need to be built from sources, depending on what flavor Linux you're using. I'm using CentOS, which did require me to build my own.

The commands to establish the headless RDP session, once the pieces are in place, look something like this:

/usr/bin/Xvfb :0 -screen 0 1920x1080x24 &
export DISPLAY=:0.0
/usr/local/bin/xfreerdp /size:1920x1080 /u:[WindowsUser] /p:"[WindowsPassword]" /v:[WindowsTarget]

In our environment we automated this as part of the build job kicked off by Jenkins. For this to work under the Jenkins slave, it was also necessary to run the Jenkins slave as a user process, rather than a service... this can be accomplished by enabling auto admin login and setting the slave launch script as a run (on logon) command.

like image 36
Paul Chambre Avatar answered Oct 11 '22 14:10

Paul Chambre