I use selenium to run django tests and I've never encountered this error before. Out of nowhere, hundreds of my tests began failing (though strangely enough not all of them, and not consistently - if I run tests one at a time, they run fine.) I have no idea why this started happening as there have been no changes to my environment.
From the traceback below, it looks like the error is being thrown while setting up the webdriver. Has anybody ever encountered this selenium error before and does anyone know how to fix it?
I'm using selenium==3.141.0 and python 3.6.3
Here's the test Class that seems to be the source of the error when running the tests:
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
from selenium import webdriver
from django.test import Client
from rest_framework.test import APIClient
class ViewTestCase(StaticLiveServerTestCase):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.test_client = Client()
self.api_client = APIClient()
def setUp(self):
super().setUp()
self.selenium = webdriver.Chrome()
self.selenium.set_window_size(1200, 678)
self.selenium.implicitly_wait(5)
self.open_page()
def tearDown(self):
self.selenium.quit()
super().tearDown()
def open_page(self):
self.selenium.get('{}/{}'.format(self.live_server_url, self.page_url))
Error tracelogs:
Traceback (most recent call last):
File "/Users/daniellong/Documents/Coding/GrubBase/GrubBase/tests/__init__.py", line 174, in setUp
self.selenium = webdriver.Chrome()
File "/Users/daniellong/Documents/Coding/GrubBase/venv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
self.service.start()
File "/Users/daniellong/Documents/Coding/GrubBase/venv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 9] Bad file descriptor