How do I run Selenium in Xvfb?

前端 未结 5 1755
面向向阳花
面向向阳花 2020-11-22 08:21

I\'m on EC2 instance. So there is no GUI.

$pip install selenium
$sudo apt-get install firefox xvfb

Then I do this:

$Xvfb :1         


        
5条回答
  •  有刺的猬
    2020-11-22 09:01

    This is the setup I use:

    Before running the tests, execute:

    export DISPLAY=:99
    /etc/init.d/xvfb start
    

    And after the tests:

    /etc/init.d/xvfb stop

    The init.d file I use looks like this:

    #!/bin/bash
    
    XVFB=/usr/bin/Xvfb
    XVFBARGS="$DISPLAY -ac -screen 0 1024x768x16"
    PIDFILE=${HOME}/xvfb_${DISPLAY:1}.pid
    case "$1" in
      start)
        echo -n "Starting virtual X frame buffer: Xvfb"
        /sbin/start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS
        echo "."
        ;;
      stop)
        echo -n "Stopping virtual X frame buffer: Xvfb"
        /sbin/start-stop-daemon --stop --quiet --pidfile $PIDFILE
        echo "."
        ;;
      restart)
        $0 stop
        $0 start
        ;;
      *)
      echo "Usage: /etc/init.d/xvfb {start|stop|restart}"
      exit 1
    esac
    exit 0

提交回复
热议问题