Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

selenium - How to make Xvfb display visible?

I am running selenium through Xvfb on display number :99 like this:

/usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99" && java -jar /usr/lib/selenium/selenium-server-standalone-2.24.1.jar -port 4444

However display with number other than :0 is not visible by default. How do I make it visible to actually see what selenium is doing in the browser?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use X11vnc

All you need is to install x11vnc via:

sudo apt-get install x11vnc xvfb fluxbox

Optionally install fluxbox to have simple window manager.

Run x11vnc in shell

Then to setup access to Xvfb for remote control, you can use X11 over SSH or VNC over SSH, e.g.

export DISPLAY=:1
Xvfb $DISPLAY -screen 0 1024x768x16 &
fluxbox &
x11vnc -display $DISPLAY -bg -forever -nopw -quiet -listen localhost -xkb

Run x11vnc using script

Here is script friendly version to run Xvfb, x11vnc and fluxbox:

export DISPLAY=${DISPLAY:-:0} # Select screen 0 by default.
xdpyinfo
if which x11vnc &>/dev/null; then
  ! pgrep -a x11vnc && x11vnc -bg -forever -nopw -quiet -display WAIT$DISPLAY &
fi
! pgrep -a Xvfb && Xvfb $DISPLAY -screen 0 1024x768x16 &
sleep 1
if which fluxbox &>/dev/null; then
  ! pgrep -a fluxbox && fluxbox 2>/dev/null &
fi
echo "IP: $(hostname -I) ($(hostname))"

Note: I'm using it in the following Docker project (check .funcs.cmds.inc.sh).

Run x11vnc using one-liner

Or you can use the following one-liner:

$ x11vnc -create -env FD_PROG=/usr/bin/fluxbox 
    -env X11VNC_FINDDISPLAY_ALWAYS_FAILS=1 
        -env X11VNC_CREATE_GEOM=${1:-1024x768x16} 
        -gone 'killall Xvfb' 
        -bg -nopw

  • -create makes it start Xvfb
  • X11VNC_FINDDISPLAY_ALWAYS_FAILS=1 makes it goto the created Xvfb session (Display :1 rather than :0 which will be normal desktop)
  • FD_PROG=/usr/bin/fluxbox makes it fire up Fluxbox (Ubuntu's one, should have background Ubuntu logo)
  • X11VNC_CREATE_GEOM=${1:-1024x768x16} sets screen to 16bit colour 1024x768
  • -gone cleans up when it exits as otherwise Xvfb is left behind (killing xvfb also kills fluxbox)

Connect to VNC

If your Xvfb listen on localhost only, you can setup tunneling to localhost, so a vncviewer can then connect to localhost to get remote control over the server. E.g.

ssh -N -T -L 5900:localhost:5900 user@remotehost &
vncviewer -encodings 'copyrect tight zrle hextile' localhost:5900

Or to listen on all addresses with password, use:

x11vnc -display :0.0 -usepw

To setup password, run: x11vnc -storepasswd.

See: Remote control over SSH at Xvfb Wikipedia page


Check also:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...