cgoldberg / xvfbwrapper

Manage headless displays with Xvfb (X virtual framebuffer)
Other
295 stars 52 forks source link

prepare Popen for OSError exception #6

Closed danclaudiupop closed 8 years ago

danclaudiupop commented 10 years ago

Hi,

If xvfb is not installed, and running the tests, the following output is generated:

======================================================================
ERROR: testGoogleHomepage (__main__.TestPages)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "xx.py", line 12, in setUp
    self.xvfb.start()
  File "/home/danclaudiupop/envs/account/local/lib/python2.7/site-packages/xvfbwrapper.py", line 55, in start
    stderr=open(os.devnull),
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception
OSError: [Errno 2] No such file or directory

I prepared the app for OSError exception and provided a more friendly error message. Also, this makes it so we can run the tests even if we didn't start the tests from an X session.

testGoogleHomepage (__main__.TestPages) ... Failed to run Xvfb :1095 -screen 0 1280x720x24
ok
fgimian commented 10 years ago

It should really be up to the calling code to handle this exception. This pull request removes control from the caller and ultimately would make this library unusable for me personally (often teardowns of other sorts are required after xvfb is not found).

I suggest you handle the OSError in a manner similar to the following in your code:

from xvfbwrapper import Xvfb

def main():
    # TODO create your Selenium object and initialise the browser
    xvfb = Xvfb()
    try:
        xvfb.start()
        # TODO run some selenium tests here
        xvfb.stop()
    except OSError:
        print(
            'Error: xvfb cannot be found on your system, please install '
            'it and try again')
        exit(1)
    finally:
        # TODO clean up Selenium browser

if __name__ == '__main__':
    main()

Cheers Fotis

Rohith043 commented 10 years ago

I installed xvfb using the command (It went fine):

sudo pip install xvfbwrapper

When i try to use xvfb (ubuntu 12.04 , python)

from xvfbwrapper import Xvfb

vdisplay = Xvfb() vdisplay.start()

It throws traceback:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/xvfbwrapper.py", line 53, in start stderr=open(os.devnull), File "/usr/lib/python2.7/subprocess.py", line 679, in init errread, errwrite) File "/usr/lib/python2.7/subprocess.py", line 1249, in _execute_child raise child_exception OSError: [Errno 2] No such file or directory

Can any one help me with this?

danclaudiupop commented 10 years ago

I think you missed to install XVFB:

sudo apt-get install xvfb

Rohith043 commented 10 years ago

Thanks danclaudiupop. I missed it. Working fine now