kotarop kotarop - 1 year ago 280
Python Question

Unable to test my first Django code

I've just started to learn Django and git using win10.

I created a python file called functional_tests.py with the following code :

from selenium import webdriver
browser = webdriver.Firefox()
assert 'Django' in browser.title

Of course, I got a firefox window popping up with an error message when I try to run this pyhton file alone

Then, in git bash I do :

$django-admin.py startproject superlists
$cd superlists
$python manage.py runserver

In another command shell, I do :
$python functional_tests.py

I'm supposed to have a Firefox window popping up with a message congratulating me.

Instead, no firefox window pop up and I have this error :

Traceback (most recent call last):
File "functional_tests.py", line 3, in <module>
browser = webdriver.Firefox()
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 134, in __init__
self.service = Service(executable_path, log_path=log_path)
File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\service.py", li ne 45, in __init__
log_file = open(log_path, "a+")
PermissionError: [Errno 13] Permission denied: 'geckodriver.log'
Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.firef ox.service.Service object at 0x03347D10>>
Traceback (most recent call last):
File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", lin e 163, in __del__
File "C:\Python34\lib\site-packages\selenium\webdriver\common\service.py", lin e 129, in stop
if self.log_file != PIPE:
AttributeError: 'Service' object has no attribute 'log_file'

I have already added Firefox and geckodriver in PATH

Answer Source

from the error, looks like selenium is failing while trying to create the logfile for gecko:

PermissionError: [Errno 13] Permission denied: 'geckodriver.log'

which might be trying to create the logfile in the same directory as where the geckodriver lives. instead, set the log path explicitly in your driver setup:

browser = webdriver.Firefox(log_path=<some writable file here>)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download