firefox geckodriver in snap does not work

Bug #2025268 reported by Maksim Beliaev
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
firefox (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

once trying to connect to geckodriver from selenium get:
```
Traceback (most recent call last):
  File "/home/maksim/git/kubeflow/bundle-kubeflow/tests-bundle/1.7/conftest.py", line 38, in driver
    driver = webdriver.Firefox(options=options, service=service)
  File "/home/maksim/git/kubeflow/bundle-kubeflow/venv/lib/python3.10/site-packages/selenium/webdriver/firefox/webdriver.py", line 196, in __init__
    self.service.start()
  File "/home/maksim/git/kubeflow/bundle-kubeflow/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 100, in start
    self.assert_process_still_running()
  File "/home/maksim/git/kubeflow/bundle-kubeflow/venv/lib/python3.10/site-packages/selenium/webdriver/common/service.py", line 113, in assert_process_still_running
    raise WebDriverException(f"Service {self._path} unexpectedly exited. Status code was: {return_code}")
selenium.common.exceptions.WebDriverException: Message: Service /snap/bin/firefox.geckodriver unexpectedly exited. Status code was: -6

```

here is a code to reproduce (see lines to toggle with comment `# toggle lines to reproduce`). Create conftest.py with content

```
import os
import time
from datetime import datetime
from pathlib import Path

import pytest
from selenium import webdriver

from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager

DEBUG = os.environ.get("DEBUG_KF", False)

@pytest.fixture(scope='session')
def driver(request):
    """Set up webdriver fixture."""
    options = Options()
    if not DEBUG:
        print("Running in headless mode")
        options.add_argument('--headless')
        options.add_argument('--disable-gpu')
    else:
        options.log.level = "trace"

    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.binary_location = "/snap/bin/firefox"

    # must create path,
    # see https://github.com/mozilla/geckodriver/releases/tag/v0.31.0
    tmp_user = Path("~/tmp").expanduser()
    os.environ["TMPDIR"] = str(tmp_user)
    tmp_user.mkdir(parents=True, exist_ok=True)

    # toggle lines to reproduce
    service = Service(GeckoDriverManager().install())
    service = Service(executable_path="firefox.geckodriver")
    driver = webdriver.Firefox(options=options, service=service)
    driver.set_window_size(1920, 1080)
    driver.maximize_window()
    driver.implicitly_wait(10)

    yield driver
    driver.quit()

```

and test_driver.py with

```
def test_1(driver):
    driver.get("https://google.de")
    a = 1
```

firefox --version
Mozilla Firefox 113.0.2

pip freeze:

absl-py==1.4.0
anyio==3.6.2
asttokens==2.2.1
async-generator==1.10
attrs==22.2.0
backcall==0.2.0
bcrypt==4.0.1
cachetools==5.3.0
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.1.0
click==7.1.2
cloudpickle==2.2.1
cryptography==40.0.1
decorator==5.1.1
Deprecated==1.2.13
docstring-parser==0.15
exceptiongroup==1.1.1
executing==1.2.0
fire==0.5.0
google-api-core==2.11.0
google-api-python-client==1.12.11
google-auth==2.17.2
google-auth-httplib2==0.1.0
google-cloud-core==2.3.2
google-cloud-storage==2.8.0
google-crc32c==1.5.0
google-resumable-media==2.4.1
googleapis-common-protos==1.59.0
h11==0.14.0
httpcore==0.16.3
httplib2==0.22.0
httpx==0.23.3
hvac==1.1.0
idna==3.4
iniconfig==2.0.0
ipdb==0.13.13
ipython==8.12.0
jedi==0.18.2
Jinja2==3.1.2
jsonschema==4.17.3
juju==2.9.42.1
jujubundlelib==0.5.7
kfp==1.8.19
kfp-pipeline-spec==0.1.16
kfp-server-api==1.8.5
kubernetes==19.15.0
lightkube==0.12.0
lightkube-models==1.26.0.4
macaroonbakery==1.3.1
MarkupSafe==2.1.2
matplotlib-inline==0.1.6
mypy-extensions==1.0.0
oauthlib==3.2.2
outcome==1.2.0
packaging==23.0
paramiko==2.12.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
pluggy==1.0.0
prompt-toolkit==3.0.38
protobuf==3.20.3
psutil==5.9.5
ptyprocess==0.7.0
pure-eval==0.2.2
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pydantic==1.10.7
Pygments==2.14.0
pyhcl==0.4.4
pymacaroons==0.13.0
PyNaCl==1.5.0
pyparsing==3.0.9
pyRFC3339==1.1
pyrsistent==0.19.3
PySocks==1.7.1
pytest==7.2.2
pytest-asyncio==0.21.0
pytest-dependency==0.5.1
pytest-operator==0.26.0
python-dateutil==2.8.2
python-dotenv==1.0.0
pytz==2023.3
PyYAML==5.4.1
requests==2.28.2
requests-oauthlib==1.3.1
requests-toolbelt==0.10.1
rfc3986==1.5.0
rsa==4.9
selenium==4.9.0
six==1.16.0
sniffio==1.3.0
sortedcontainers==2.4.0
stack-data==0.6.2
strip-hints==0.1.10
tabulate==0.9.0
termcolor==2.2.0
theblues==0.5.2
tomli==2.0.1
toposort==1.10
tqdm==4.65.0
traitlets==5.9.0
trio==0.22.0
trio-websocket==0.10.2
typer==0.7.0
typing-extensions==4.5.0
typing-inspect==0.8.0
uritemplate==3.0.1
urllib3==1.26.15
wcwidth==0.2.6
webdriver-manager==3.8.5
websocket-client==1.5.1
websockets==11.0.1
wrapt==1.15.0
wsproto==1.2.0

description: updated
description: updated
Revision history for this message
Amin Bandali (bandali) wrote (last edit ):

On Ubuntu 23.04 with Firefox snap 114.0.1 and its geckodriver 0.33, I put the above two files in a new directory, then ran

python3 -m venv venv
. venv/bin/activate
pip3 install selenium webdriver-manager pytest
pytest test_driver.py

The run failed with the following error:

ERROR test_driver.py::test_1 - selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable

Per https://github.com/mozilla/geckodriver/issues/2010#issuecomment-1116203839, setting options.binary_location = "/snap/firefox/current/firefox.launcher" fixed it and the test passed. I believe this is the default in recent versions, so just not setting options.binary_location worked as well.

I then tried commenting out the ~/tmp directory creation bit, as well as toggling between the two 'service' assignments, and in every case the test continued to pass.

Are you using a recent Firefox snap (and its geckodriver) version?

Revision history for this message
Maksim Beliaev (beliaev-maksim) wrote (last edit ):

refreshed snap and update version of selenium to 4.10 (initially was 4.9), looks to work now

even no need to TMP anymore, just works as it should be

see example https://github.com/beliaev-maksim/firefox-selenium

Revision history for this message
Sebastien Bacher (seb128) wrote :

Great, should the bug marked as fixed then?

Revision history for this message
Maksim Beliaev (beliaev-maksim) wrote :

yes, please feel free to close

Changed in firefox (Ubuntu):
status: New → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.