Skip to content

Commit 13266d8

Browse files
committed
Add Selenim test.
1 parent ac79628 commit 13266d8

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ test:
1111
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \
1212
django-admin.py test tests
1313

14+
test_selenium:
15+
DJANGO_SELENIUM_TESTS=true DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \
16+
django-admin.py test tests
17+
1418
coverage:
1519
coverage erase
1620
DJANGO_SETTINGS_MODULE=tests.settings PYTHONPATH=. \

docs/contributing.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,19 @@ Python::
4646

4747
This is strongly recommended before committing changes to Python code.
4848

49+
The test suite includes frontend tests written with Selenium. Since they're
50+
annoyingly slow, they're disabled by default. You can run them as follows::
51+
52+
$ make test_selenium
53+
54+
or by setting the ``DJANGO_SELENIUM_TESTS`` environment variable::
55+
56+
$ DJANGO_SELENIUM_TESTS=true make test
57+
$ DJANGO_SELENIUM_TESTS=true make coverage
58+
$ DJANGO_SELENIUM_TESTS=true tox
59+
4960
At this time, there isn't an easy way to test against databases other than
50-
SQLite. The JaveScript code isn't tested either.
61+
SQLite.
5162

5263
Style
5364
-----

requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ sqlparse
1111

1212
coverage
1313
flake8
14+
selenium
1415
tox
1516

1617
# Documentation

tests/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
'tests',
2525
]
2626

27+
MEDIA_URL = '/media/' # Avoids https://code.djangoproject.com/ticket/21451
28+
2729
MIDDLEWARE_CLASSES = [
2830
'debug_toolbar.middleware.DebugToolbarMiddleware',
2931
'django.contrib.sessions.middleware.SessionMiddleware',

tests/test_integration.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,19 @@
22

33
from __future__ import unicode_literals
44

5+
import os
56
from xml.etree import ElementTree as ET
67

7-
from django.test import TestCase, RequestFactory
8+
try:
9+
from selenium import webdriver
10+
from selenium.common.exceptions import NoSuchElementException
11+
from selenium.webdriver.support.wait import WebDriverWait
12+
except ImportError:
13+
webdriver = None
14+
15+
from django.test import LiveServerTestCase, RequestFactory, TestCase
816
from django.test.utils import override_settings
17+
from django.utils.unittest import skipIf, skipUnless
918

1019
from debug_toolbar.middleware import DebugToolbarMiddleware, show_toolbar
1120

@@ -92,3 +101,29 @@ def test_non_utf8_charset(self):
92101
def test_xml_validation(self):
93102
response = self.client.get('/regular/XML/')
94103
ET.fromstring(response.content) # shouldn't raise ParseError
104+
105+
106+
@skipIf(webdriver is None, "selenium isn't installed")
107+
@skipUnless('DJANGO_SELENIUM_TESTS' in os.environ, "selenium tests not requested")
108+
@override_settings(DEBUG=True)
109+
class DebugToolbarLiveTestCase(LiveServerTestCase):
110+
111+
@classmethod
112+
def setUpClass(cls):
113+
super(DebugToolbarLiveTestCase, cls).setUpClass()
114+
cls.selenium = webdriver.Firefox()
115+
116+
@classmethod
117+
def tearDownClass(cls):
118+
cls.selenium.quit()
119+
super(DebugToolbarLiveTestCase, cls).tearDownClass()
120+
121+
def test_basic(self):
122+
self.selenium.get(self.live_server_url + '/regular/basic/')
123+
version_button = self.selenium.find_element_by_class_name('VersionDebugPanel')
124+
version_panel = self.selenium.find_element_by_id('VersionDebugPanel')
125+
with self.assertRaises(NoSuchElementException):
126+
version_panel.find_element_by_tag_name('table')
127+
version_button.click() # load contents of the version panel
128+
WebDriverWait(self.selenium, timeout=10).until(
129+
lambda selenium: version_panel.find_element_by_tag_name('table'))

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ envlist =
1515
[testenv]
1616
commands = make test
1717
deps =
18+
selenium
1819
sqlparse
1920
whitelist_externals = make
2021

0 commit comments

Comments
 (0)