Ubuntu无桌面进行Web浏览器测试

来源:互联网 发布:笛子入门 知乎 编辑:程序博客网 时间:2024/05/22 14:18

主要原理是利用xvfb提供的显卡帧缓冲区,让浏览器以为有桌面

Install xvfb in ubuntu:

sudo apt install xvfb

cat > /etc/init.d/xvfb <<"EOF"

XVFB=/usr/bin/Xvfb

XVFBARGS=":99 -screen 0 1024x768x24 -fbdir /var/run -ac"

PIDFILE=/var/run/xvfb.pid

case "$1" in

 start)

   echo -n "Starting virtual X frame buffer: Xvfb"

   start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS

   echo "."

   ;;

 stop)

   echo -n "Stopping virtual X frame buffer: Xvfb"

   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

EOF


chmod +x /etc/init.d/xvfb

export DISPLAY=:99.0

/etc/init.d/xvfb start


1.2. Install chrome in ubuntu:

sudo apt-get install libxss1 libappindicator1 libindicator7

sudo apt-get install -f

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

sudo dpkg -i google-chrome*.deb

sudo ln -s /usr/bin/google-chrome /usr/bin/chrome



1.3. Install chromedriver in ubuntu:

wget http://chromedriver.storage.googleapis.com/2.25/chromedriver_linux64.zip

unzip chromedriver_linux64.zip

sudo mv chromedriver /usr/bin/



1.4. Install firefox in ubuntu:

sudo apt install firefox


1.5. Install geckodriver for firefox in ubuntu:

wget https://github.com/mozilla/geckodriver/releases/download/v0.11.1/geckodriver-v0.11.1-linux64.tar.gz

tar zxf geckodriver-v0.11.1-linux64.tar.gz

sudo mv geckodriver /usr/bin/


原创粉丝点击