WebDriver: Getting it to play nicely with Xv

系统 1823 0

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/*/.parentlock

rm -rf /var/go/.mozilla

 

 

XVFB=`which xVfb`

if [ "$?" -eq 1 ];

then

    echo "Xvfb not found."

    exit 1

fi

 

$XVFB :99 -ac &

 

 

BROWSER=`which firefox`

if [ "$?" -eq 1 ];

then

    echo "Firefox not found."

    exit 1

fi

 

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 specified

Error 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/*/.parentlock

rm -rf /var/go/.mozilla

 

pkill firefox

 

BROWSER=`which firefox`

if [ "$?" -eq 1 ];

then

    echo "Firefox not found."

    exit 1

fi

 

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


更多文章、技术交流、商务合作、联系博主

微信扫码或搜索:z360901061

微信扫一扫加我为好友

QQ号联系: 360901061

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描下面二维码支持博主2元、5元、10元、20元等您想捐的金额吧,狠狠点击下面给点支持吧,站长非常感激您!手机微信长按不能支付解决办法:请将微信支付二维码保存到相册,切换到微信,然后点击微信右上角扫一扫功能,选择支付二维码完成支付。

【本文对您有帮助就好】

您的支持是博主写作最大的动力,如果您喜欢我的文章,感觉我的文章对您有帮助,请用微信扫描上面二维码支持博主2元、5元、10元、自定义金额等您想捐的金额吧,站长会非常 感谢您的哦!!!

发表我的评论
最新评论 总共0条评论