ChromeDriver occasionally hangs on init

selenium
chrome
python

#1

I’m using Python and Selenium’s Chromedriver. In my 200 tests there’s always a random one that hangs entire execution. I narrowed the problem down to my setUp method:

def setUp(self):
    print('[SETUP] OPENING BROWSER...')

    self.browser = webdriver.Chrome(settings.CHROMEDRIVER_PATH)

    print('[SETUP] FINISHED!')

Output:

> [SETUP] OPENING BROWSER...
> command python manage.py test took more than 10 minutes since last output

It happens for different test each time, while most of them passes without problems.

It does not happen when I run tests locally on my computer.

Please, advise what should I do.


#2

Can you add the following environment variable to your project:

DBUS_SESSION_BUS_ADDRESS = /dev/null

You can do this via the CircleCI UI: Project settings > Environment Variables

Or in circle.yml:

machine:
  environment:
    DBUS_SESSION_BUS_ADDRESS: /dev/null

Do let us know if that helps or not. Our testing suggests that this resolves issues related to x11-dbus and Xvfb in containerized environments with flaky browser testing using Selenium, Chrome / Firefox.


#3

This works for me. Wish I had found this thread sooner. I ended up on this post that ultimately provided the solution shared by Tom.


#4

Glad to hear it helped. This setting is now included in out 14.04 image: Ubuntu 14.04 Build Image Update 201701-01


#5