无法测试第一个Django代码



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

我用下面的代码创建了一个名为functional_tests.py的python文件:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://localhost:8000')
assert 'Django' in browser.title

当然,当我试图单独运行这个python文件时,我得到一个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:Python34libsite-packagesseleniumwebdriverfirefoxwebdriver.py",     line 134, in __init__
    self.service = Service(executable_path, log_path=log_path)
  File "C:Python34libsite-packagesseleniumwebdriverfirefoxservice.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:Python34libsite-packagesseleniumwebdrivercommonservice.py", lin    e 163, in __del__
    self.stop()
  File "C:Python34libsite-packagesseleniumwebdrivercommonservice.py", lin    e 129, in stop
    if self.log_file != PIPE:
AttributeError: 'Service' object has no attribute 'log_file'

我已经在PATH

中添加了Firefox和geckodriver

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

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

,它可能试图在与geckodriver所在目录相同的目录中创建日志文件。相反,在驱动程序设置中显式设置日志路径:

browser = webdriver.Firefox(log_path=<some writable file here>)

最新更新