【发布时间】:2018-06-06 08:16:13
【问题描述】:
我在 Django 应用程序聊天中有以下代码
tests.py
from channels.testing import ChannelsLiveServerTestCase
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.wait import WebDriverWait
class ChatTests(ChannelsLiveServerTestCase):
serve_static = True # emulate StaticLiveServerTestCase
@classmethod
def setUpClass(cls):
super().setUpClass()
try:
# NOTE: Requires "chromedriver" binary to be installed in $PATH /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/
cls.driver = webdriver.Chrome(executable_path="/home/muiruri_samuel/webapp/chatsys/chat/chromedriver")
except:
super().tearDownClass()
raise
...
它应该检查!如果通道工作正常,但在此之前无法连接到 ChromeDriver 并出现此错误
(chatenv) muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests
Creating test database for alias 'default'...
System check identified no issues (0 silenced).
E
======================================================================
ERROR: setUpClass (chat.tests.ChatTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", l
ine 76, in start
stdin=PIPE)
File "/usr/lib/python3.6/subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "/usr/lib/python3.6/subprocess.py", line 1344, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/muiruri_samuel/webapp/chatsys/chat/chromedriver':
'/home/muiruri_samuel/webapp/chatsys/chat/chromedriver'
line 68, in __init__
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/muiruri_samuel/webapp/chatsys/chat/tests.py", line 14, in setUpClass
cls.driver = webdriver.Chrome(executable_path="/home/muiruri_samuel/webapp/chatsys/chat/chromedriver")
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
self.service.start()
File "/home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
----------------------------------------------------------------------
Ran 0 tests in 0.006s
FAILED (errors=1)
Destroying test database for alias 'default'...
它“没有”在 PATH /home/muiruri_samuel/webapp/chatsys/chat/chromedriver 上找到驱动程序,我也尝试将其复制到站点包 /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/
【问题讨论】:
-
例如复制到
/usr/bin