Can't use Selenium with Tox

Issue #268 on hold
v created an issue

Steps to reproduce:

  1. Install selenium in a new virtual environment.
  2. Create the file test_selenium.py with the contents:

    import unittest
    
    from selenium import webdriver
    
    class TestBroken(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
    
        def tearDown(self):
            self.driver.quit()
    
        def test_broken(self):
            pass
    
  3. Execute $ python -m unittest:

    .
    ----------------------------------------------------------------------
    Ran 1 test in 1.103s
    
    OK
    
  4. Install tox.

  5. Create the file tox.ini with the contents:

    [tox]
    skipsdist=True
    
    [testenv]
    deps=selenium
    commands=python -m unittest
    
  6. Execute $ tox:

    python installed: selenium==2.47.1,wheel==0.24.0
    python runtests: PYTHONHASHSEED='275551244'
    python runtests: commands[0] | python -m unittest
    E/usr/lib64/python3.4/unittest/case.py:605: ResourceWarning: unclosed file <_io.BufferedWriter name='/dev/null'>
      outcome.errors.clear()
    
    ======================================================================
    ERROR: test_selenium (test_selenium.TestSelenium)
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "/.../test_selenium.py", line 8, in setUp
        self.driver = webdriver.Firefox()
      File "/.../.tox/python/lib/python3.4/site-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
        self.binary, timeout),
      File "/.../.tox/python/lib/python3.4/site-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
        self.binary.launch_browser(self.profile)
      File "/.../.tox/python/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
        self._wait_until_connectable()
      File "/.../.tox/python/lib/python3.4/site-packages/selenium/webdriver/firefox/firefox_binary.py", line 98, in _wait_until_connectable
        raise WebDriverException("The browser appears to have exited "
    selenium.common.exceptions.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.
    
    ----------------------------------------------------------------------
    Ran 1 test in 1.060s
    
    FAILED (errors=1)
    ERROR: InvocationError: '/.../.tox/python/bin/python -m unittest'
    _________________________________________________________________ summary __________________________________________________________________
    ERROR:   python: commands failed
    

Comments (11)

  1. Florian Bruhin

    I'm guessing this is caused by tox's isolating of environment variables, i.e. more or less working as intended.

    Can you try if it works with passenv = *? If so, I'd recommend finding out what variable caused it and only adding that to passenv.

  2. v reporter

    Ah, passenv = * did the trick, thanks. I'll try to see which environment variable is responsible.

  3. v reporter

    The problem was that the DISPLAY environment variable wasn't passed, which is the intended behavior of tox.

  4. davide moro

    Hi,

    probably I have a similar problem but passenv didn't solve. If I run the tests with py.test using Firefox all goes fine, instead if I invoke the same command using tox the Firefox process hangs:

    davide    8222  0.6  0.9  49912 18752 pts/1    S+   15:47   0:00 /home/davide/workspaces/tierra_qa/python/bin/python2 /home/davide/workspaces/tierra_qa/python/bin/tox -e firefox
    davide    8246  2.0  3.0 107040 61360 pts/1    S+   15:47   0:00 /home/davide/workspaces/tierra_qa/.tox/firefox/bin/python2 .tox/firefox/bin/py.test --credentials=Administrator;admin;admin --splinter-webdriver=firefox
    davide    8251  0.1  0.4  15392  8780 pts/1    Sl+  15:47   0:00 geckodriver -b /usr/bin/firefox --port 51607
    davide    8257  0.0  0.0      0     0 pts/1    Z+   15:47   0:00 [firefox] <defunct>
    davide    8267  0.0  0.0  14252   936 pts/2    S+   15:47   0:00 grep --color=auto firefox
    

    Versions: Firefox version: 48.0 OS: linux (Kubuntu) * kernel 4.4.0-36-generic

    Requirements.txt:

    enum34==1.1.6
    glob2==0.4.1
    Mako==1.0.4
    MarkupSafe==0.23
    parse==1.6.6
    parse-type==0.3.4
    pluggy==0.3.1
    py==1.4.31
    pytest==3.0.1
    pytest-base-url==1.1.0
    pytest-bdd==2.17.1
    pytest-splinter==1.7.6
    pytest-travis-fold==1.2.0
    requests==2.11.1
    selenium==3.0.0b2
    six==1.10.0
    splinter==0.7.4
    tox==2.3.1
    virtualenv==15.0.3
    

    Any suggestion please?

    Thank you in advance.

    PS: same wrong behaviour happens using Google chrome

  5. davide moro

    Here it is my tox.ini file:

    [tox]
    envlist = py27,py35
    skip_missing_interpreters = true
    #passenv = *
    passenv = DISPLAY
    
    [testenv]
    deps=
        pip
        wheel
        setuptools
        -rrequirements.txt
        -e.
    commands=py.test --runslow --credentials="Administrator;admin;admin"
    
    [testenv:phantomjs]
    commands={[testenv]commands} --splinter-webdriver=phantomjs
    
    [testenv:firefox]
    commands={[testenv]commands} --splinter-webdriver=firefox
    
    [testenv:chrome]
    commands={[testenv]commands} --splinter-webdriver=chrome
    
  6. Log in to comment