Skip to content

Instantly share code, notes, and snippets.

@kosyfrances
Last active September 6, 2020 22:31
Show Gist options
  • Save kosyfrances/212ecdb71914d6a266c8 to your computer and use it in GitHub Desktop.
Save kosyfrances/212ecdb71914d6a266c8 to your computer and use it in GitHub Desktop.
Unable to call firefox from selenium in python on AWS machine while running functional tests

While trying to run functional tests in python on an Ubuntu EC2 instance using
python manage.py test functional_tests --liveserver=superlist-staging.tk

I got this error
RuntimeError: Could not find firefox in your system PATH. Please specify the firefox binary location or install firefox So I did sudo apt-get install firefox to install firefox.

Afterwards I tried running the tests again and got another error:
WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.

The issue is Selenium needs a display and as Linux does not have one , you need to download a virtual display (xvnc/xvfb). So I installed xfvb with sudo apt-get install xvfb

Then I ran the tests with xvfb like this - xvfb-run python manage.py test functional_tests --liveserver=superlist-staging.tk

I got another error:
WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

Turns out the reason is a version problem between the selenium server and python library. I updated selenium with pip install -U selenium and that resolved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment