无法测试我的第一个Django代码

时间:2016-11-12 17:59:57

标签: python django git selenium

我刚刚开始使用win10学习Django和git。

我使用以下代码创建了一个名为functional_tests.py的python文件:

from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title

当然,当我尝试单独运行这个pyhton文件时,我弹出一个错误消息的firefox窗口

然后,在git bash我做:

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

在另一个命令shell中,我这样做: $python functional_tests.py

我应该在Firefox窗口中弹出一条祝贺我的信息。

相反,没有弹出firefox窗口,我有这个错误:

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__
    self.stop()
  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'

我已经在PATH中添加了Firefox和geckodriver

1 个答案:

答案 0 :(得分:0)

从错误中看,在尝试为gecko创建日志文件时,selenium失败了:

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

可能正在尝试在与geckodriver所在的目录相同的目录中创建日志文件。相反,在驱动程序设置中明确设置日志路径:

browser = webdriver.Firefox(log_path=<some writable file here>)
相关问题