mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.03k stars 1.51k forks source link

Geckodriver fails to find non-snap installed firefox when launched from a snap application #2062

Open brownan opened 1 year ago

brownan commented 1 year ago

System

In my case, I'm developing a Django project which uses selenium and invokes the geckodriver. When I run from the command line, it works fine. When I run it from PyCharm (installed via snap), the geckodriver returns this error:

selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher: no such file or directory

I believe this is due to the recent bug https://bugzilla.mozilla.org/show_bug.cgi?id=1769991 and its fix https://hg.mozilla.org/mozilla-central/rev/93e827afaac1

If I'm reading the code right, it checks for the SNAP_INSTANCE_NAME environment variable, but doesn't check its contents. When running from Pycharm, the geckodriver process inherits the value SNAP_INSTANCE_NAME=pycharm-professional and then tries to find firefox at /snap/firefox/current/firefox.launcher instead of its actual location at /usr/bin/firefox

I can verify this by executing my test suite like this:

SNAP_INSTANCE_NAME=foo ./manage.py test
Traceback (most recent call last):
...
selenium.common.exceptions.SessionNotCreatedException: Message: Failed to start browser /snap/firefox/current/firefox.launcher: no such file or directory

whereas without that variable set, the tests run fine.

mathes2 commented 1 year ago

i had the same problem, i solved it on my linux-ubuntu 20.04 by a symlink firefox.launcher in new directory /snap/firefox/current/ to /usr/bin/firefox. It's not elegant, but it works. sudo mkdir /snap/firefox/current sudo ln -s /usr/bin/firefox /snap/firefox/current/ sudo mv firefox firefox.launcher

virgostyx commented 1 year ago

Thanks to mathes2. It is the best I could find.