0

I have the following code in a Django app chat's

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

    ...

it's supposed to check! if channels works ok, but before that fails to connect to the ChromeDriver with this error

(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'...

It "doesn't" find the driver on the PATH /home/muiruri_samuel/webapp/chatsys/chat/chromedriver and I've also tried copying it to the sites-packages /home/muiruri_samuel/webapp/chatenv/lib/python3.6/site-packages/

Community
  • 1
  • 1
Sam B.
  • 2,703
  • 8
  • 40
  • 78

1 Answers1

0

According to muiruri_samuel@train:~/webapp/chatsys$ python manage.py test chat.tests command, you're running the code from folder webapp/chatsys. So it will be a working directory. Thus it won't find chromedriver in subdirectories, including ./chat. Try moving chromedriver to /usr/bin for example. And make sure it's in PATH variable: echo $PATH

Andrew_Lvov
  • 4,621
  • 2
  • 25
  • 31
  • copied it using sudo, restarted gunicorn and tried again but still getting the same error. I've also checked if the path is in path `(chatenv) muiruri_samuel@train:/usr/bin$ echo $PATH /home/muiruri_samuel/webapp/chatenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games:/snap/bin` – Sam B. Jun 06 '18 at 08:58
  • `/usr/bin` is in the path folder – Sam B. Jun 06 '18 at 08:58
  • What do you get if you add ```import os; print(os.environ['PATH'])``` in `chat/tests.py` ? – Andrew_Lvov Jun 06 '18 at 09:02
  • /home/muiruri_samuel/webapp/chatenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games: /usr/local/games:/snap/bin – Sam B. Jun 06 '18 at 09:16
  • it prints the lines above. – Sam B. Jun 06 '18 at 09:33
  • After moving to `/usr/bin/` have you tried to remove param `executable_path="/home/....` as well ? – Andrew_Lvov Jun 06 '18 at 09:43
  • yes removed it but the error remains, trying now with firefox – Sam B. Jun 06 '18 at 09:51
  • But the error was still the same? And it had `execute` and `read` permissions ? – Andrew_Lvov Jun 06 '18 at 10:03
  • I used `sudo cp -i ` and at least for firefox seemed to find and use the driver but throws a configuration error https://stackoverflow.com/questions/50717900/selenium-django-python-errorunable-to-find-a-matching-set-of-capabilities – Sam B. Jun 06 '18 at 10:17
  • seems atleast a step closed to solving the problem – Sam B. Jun 06 '18 at 10:18