【问题标题】:django application selenium testing no static filesdjango应用程序硒测试没有静态文件
【发布时间】:2015-01-24 03:04:47
【问题描述】:

我想对我的 django 应用程序进行一些功能测试。我正在使用硒,测试有效,但问题出在静态文件上。未找到 css/js 状态。 我的测试在 localhost:8081 上运行。 示例 bootstrap.css:

<h1>Not Found</h1><p>The requested URL /static/frontend/bootstrap/3.3.0/css/bootstrap.css was not found on this server.</p>

我找不到任何信息,我是否为 selenium 应用程序添加了一些额外的配置?

引用:

Traceback (most recent call last):
  File "/usr/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1028, in __call__
    return super(FSFilesHandler, self).__call__(environ, start_response)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 187, in __call__
    response = self.get_response(request)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1011, in get_response
    return self.serve(request)
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/test/testcases.py", line 1023, in serve
    return serve(request, final_rel_path, document_root=self.get_base_dir())
  File "/home/t/py/django/bid/src/venv/local/lib/python2.7/site-packages/django/views/static.py", line 50, in serve
    fullpath = os.path.join(document_root, newpath)
  File "/home/t/py/django/bid/src/venv/lib/python2.7/posixpath.py", line 77, in join
    elif path == '' or path.endswith('/'):
AttributeError: 'NoneType' object has no attribute 'endswith'

【问题讨论】:

    标签: python django selenium


    【解决方案1】:

    您可以使用django.test 中的LiveServerTestCase 而不是 StaticLiveServerTestCase 来自django.contrib.staticfiles.testing

    不仅要注意不同的类名,还要注意不同的模块名:

    from django.test import LiveServerTestCase
    #     ^-- vs --v
    from django.contrib.staticfiles.testing import StaticLiveServerTestCase
    

    【讨论】:

    • 救命稻草。我发现的所有 selenium doco 都适用于 django 1.6。
    【解决方案2】:

    好的,我找到了解决方案。首先我必须在设置中添加

    STATIC_ROOT = 'my static dir'
    

    然后:

    ./manage.py collectstatic
    

    【讨论】:

    • 谢谢,LiveServerTestCase 使用生产设置 (DEBUG = True),因此需要先收集静态文件。现在很清楚了
    • @MartinM 应该是DEBUG = False
    猜你喜欢
    • 2012-04-15
    • 2011-10-30
    • 2018-12-12
    • 2021-04-02
    • 2011-06-01
    • 2014-02-05
    • 2011-10-24
    • 2016-04-06
    • 1970-01-01
    相关资源
    最近更新 更多