Is it possible to test successful loading of static page components in Django automatic test?

是否可以在Django自动测试中测试成功加载静态页面组件?

For example, using django test client, besides testing the client.get('x').status_code to be 200, I want to test if all page's static resources (linked css and js files) are successfully loaded.

例如,使用django测试客户端,除了测试client.get('x')。status_code为200之外,我想测试是否所有页面的静态资源(链接的css和js文件)都已成功加载。

If its not possible using client, Is there a plugin or suplementary test system, e.g. Selenium, to enable such type of tests?

如果不能使用客户端,是否有插件或补充测试系统,例如硒,能够进行这类测试吗?

2 个解决方案

#1


3

I guess you want to find out if django's staticfile finder is able to find your static resources.

我想你想知道django的静态文件查找器能否找到你的静态资源。

Consider your app name is my_app. You have a folder called static inside it. You again have a folder called my_app inside it which contains your static resource, let's say some image named 'test.jpg'.

考虑您的应用名称是my_app。你有一个名为static的文件夹。你再次在其中有一个名为my_app的文件夹,其中包含你的静态资源,比方说一些名为'test.jpg'的图像。

myapp
|-- __init__.py 
`-- models.py
`-- static
    `-- myapp
        `-- test.jpg

from django.contrib.staticfiles import finders
from django.contrib.staticfiles.storage import staticfiles_storage

class TestStaticFiles(TestCase):
"""Check if app contains required static files"""
def test_images(self):
    abs_path = finders.find('myapp/test.jpg')
    self.assertTrue(staticfiles_storage.exists(abs_path))

finders looks inside static/ subdirectory of all apps to find the static resource.

finders查看所有应用程序的static /子目录内部以查找静态资源。

更多相关文章

  1. Python进阶----类的结构(公有成员 , 私有成员(私有属性,私有方法
  2. Appium基于Python APP自动化测试框架
  3. 初学者的Selenium自动化测试指南,基于Python(五)——常用键盘事件
  4. 基于Python的XSS测试工具XSStrike使用方法
  5. [caffe(二)]Python加载训练caffe模型并进行测试2
  6. LTP--linux稳定性测试 linux性能测试 ltp压力测试 ---IBM 的 lin
  7. Kali Linux渗透测试 131 拒绝服务--NTP 放大攻击
  8. 如何静态构建qt5
  9. Linux-自己创建动态库静态库

随机推荐

  1. 手把手教你用Bokeh进行可视化数据分析(附
  2. 分布式爬虫的部署之Gerapy分布式管理
  3. Scrapy框架的使用之Scrapy爬取新浪微博
  4. 分布式爬虫原理之分布式爬虫原理
  5. OpenCV:图像检索。
  6. 分布式爬虫原理之Scrapy分布式实现
  7. 各项工具大pk,分组聚合哪家强?
  8. 决策树学习笔记(一):特征选择
  9. NBA球员投篮数据可视化。
  10. OpenCV:边缘检测。