Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Testing with LiveServerTestCase and Selenium

1,192 views
Skip to first unread message

Paul Childs

unread,
Jun 28, 2012, 9:45:30 AM6/28/12
to django...@googlegroups.com
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:
and read this tutorial
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
/Paul

Rafael Durán Castañeda

unread,
Jun 30, 2012, 7:39:54 AM6/30/12
to django...@googlegroups.com
El 28/06/12 15:45, Paul Childs escribi�:
> /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...@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users...@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?

Paul Childs

unread,
Jul 4, 2012, 1:32:35 PM7/4/12
to django...@googlegroups.com
I thought it might be a good idea to remove Django testing from the equation by opening up an IPython session and executing the following:

from selenium import webdriver
browser = webdriver.Firefox()
browser.title
''     # empty string

The the same thing is happening with just the webdriver alone.

The company I work for has McAffee installed on my machine. Could it be blocking automated browser activity?

On Saturday, June 30, 2012 8:39:54 AM UTC-3, Rafael Durán Castañeda wrote:
El 28/06/12 15:45, Paul Childs escribi�:

Paul Childs

unread,
Jul 10, 2012, 11:27:47 AM7/10/12
to django...@googlegroups.com
Just to close the loop on this, in case others have this problem, I found the answer on stackoverflow...


In a nutshell: Do not have an HTTP_PROXY environment variable set.
Reply all
Reply to author
Forward
0 new messages