El 28/06/12 15:45, Paul Childs escribió:
Hello,
I'm using Django 1.4 and was really excited to learn about the new
testing features. I am totally new to this.
I seem to have hit a bump in the road. If I overcome this I'm hopeful
it will be smooth sailing and I will experience some great testing
goodness.
I've been mucking around with this all morning and I can't seem to get
the selenium Firefox webdriver to navigate to the given URL.
I have read the docs:
https://docs.djangoproject.com/en/1.4/topics/testing/#django.test.LiveServerTestCase
and read this tutorial
http://www.tdd-django-tutorial.com/tutorial/1/
and tried to run the test code that they suggest.
When I run the very simple test:
from django.test import LiveServerTestCase
from selenium import webdriver
class MySeleniumTests(LiveServerTestCase):
fixtures = ['lookups_security.json']
def setUp(self):
self.browser = webdriver.Firefox()
def tearDown(self):
self.browser.quit()
def test_login(self):
# Gertrude opens her web browser, and goes to the admin page
self.browser.get(self.live_server_url + '/admin/login/')
# She sees the familiar 'Django administration' heading
body = self.browser.find_element_by_tag_name('body')
self.assertIn('CISSIMP Admin', body.text)
A blank Firefox browser pops up, sits there and then closes.
The test output is:
(sitar_env2) C:\virtual_env\sitar_env2\cissimp>python manage.py test
--liveserver=localhost:8082 sitar
Creating test database for alias 'default'...
E
======================================================================
ERROR: test_login (sitar.tests.MySeleniumTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\virtual_env\sitar_env2\cissimp\sitar\tests.py", line 54, in
test_login
self.assertIn('CISSIMP Admin', body.text)
AttributeError: 'NoneType' object has no attribute 'text'
----------------------------------------------------------------------
Ran 1 test in 22.546s
FAILED (errors=1)
Destroying test database for alias 'default'...
It seems obvious that the browser is not navigating to the URL I want
so the code is trying to get a reference to an non-existent body tag.
Can anyone see what I am doing wrong?
Thanks
/Paulr
--
You received this message because you are subscribed to the Google
Groups "Django users" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/django-users/-/jh47T9WA7QkJ.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.
The error is quite obvious, body is None and thus it doesn't have 'text'
attribute, why body is None is not so obvious since I think selenium
should raise NoSuchElementExceptionif it can't find the body tag, no
tjust returning None. When you manually browse the url, what do you get?
is the body tag there or are your getting a blank page?
--
You received this message because you are subscribed to the Google Groups "Django
users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.