【问题标题】:Unable to test my first Django code无法测试我的第一个 Django 代码
【发布时间】:2017-03-26 17:54:35
【问题描述】:

我刚开始使用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

【问题讨论】:

    标签: python django git selenium


    【解决方案1】:

    从错误来看,硒在尝试为壁虎创建日志文件时似乎失败了:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多