WebDriver: Getting it to play nicely with Xvfb

來源:互聯網
上載者:User

標籤:

http://www.markhneedham.com/blog/2011/12/15/webdriver-getting-it-to-play-nicely-with-xvfb/

 


Thoughts on Software Development

 

with 2 comments

Another thing we’ve been doing with WebDriver is having it run with the FirefoxDriver while redirecting the display output into the Xvfb framebuffer so that we can run it on our continuous integration agents which don’t have a display attached.

The first thing we needed to do was set the environment property ‘webdriver.firefox.bin’ to our own script which would point the display to Xvfb before starting Firefox:

import java.lang.System._lazy val firefoxDriver: FirefoxDriver = {  setProperty("webdriver.firefox.bin", "/our/awesome/starting-firefox.sh")  new FirefoxDriver()}

Our first version of the script looked like this:

/our/awesome/starting-firefox.sh

#!/bin/bash rm -f ~/.mozilla/firefox/*/.parentlockrm -rf /var/go/.mozilla  XVFB=`which xVfb`if [ "$?" -eq 1 ];then    echo "Xvfb not found."    exit 1fi $XVFB :99 -ac &  BROWSER=`which firefox`if [ "$?" -eq 1 ];then    echo "Firefox not found."    exit 1fi export DISPLAY=:99$BROWSER &

The mistake we made here was that we started Xvfb in the background which meant that sometimes it hadn’t actually started by the time Firefox tried to connect to the display and we ended up with this error message:

No Protocol specifiedError cannot open display :99

We really wanted to keep Xvfb running regardless of whether the Firefox instances being used by WebDriver were alive or not so we moved the starting of Xvfb out into a separate script which we run as one of the earlier steps in the build.

We also struggled to get the FirefoxDriver to kill itself after each test as calling ‘close’ or ‘quit’ on the driver didn’t seem to kill off the process.

We eventually resorted to putting a ‘pkill firefox’ statement at the start of our firefox starting script:

/our/awesome/starting-firefox.sh

#!/bin/bash rm -f ~/.mozilla/firefox/*/.parentlockrm -rf /var/go/.mozilla pkill firefox BROWSER=`which firefox`if [ "$?" -eq 1 ];then    echo "Firefox not found."    exit 1fi export DISPLAY=:99$BROWSER &

It’s a bit hacky but it does the job more deterministically than anything else we’ve tried previously.

Be Sociable, Share!

WebDriver: Getting it to play nicely with Xvfb

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.