Programming: A concise tutorial on django-nose-selenium.

So you’d really like to perform integration testing on your Django site, to exercise the whole stack right from the client-side Javascript through to the database at the backend. There are a million ways to do this, but only a few work. Of the few that work, none have a fully worked out example showing you how to get them up and running. Enter this blog post! In this, I’m going to show you as compactly as possible how to get django-nose-selenium working on your Django 1.3 test setup.

Most importantly here, if you’re using sqlite3, is to specify TEST_NAME. If you don’t do this, Django by default uses an in memory sqlite3 database, and this breaks in infuriatingly mysterious ways, for example yielding “DatabaseError: no such table: django_site” or the same for “django_session”, while you can see that the test framework is creating those tables. After hours of frustration, I stumbled upon this important tidbit in this django-nose-selenium issue report.

Now you can start writing tests! Below is an example, which lives in project/app/tests.py, that loads up the front page, and also tries to log in. You can use the selenium IDE (firefox extension) to generate the Python exercise code you see below. I’m also making use of selenium_fixtures to load in two users into the database (the fixture itself is shown below this example):

Once all of this has been setup, first startup the Selenium RC server as explained here. In short, download from here, and invoke like this:
[shell]
java -jar selenium-server-standalone-2.5.0.jar
[/shell]

–with-selenium specifies that selenium tests should be executed, –with-selenium-fixtures that selenium fixtures should be loaded and cherrypyliveserver that the CherryPy multi-threaded webserver should be used instead of the built-in django one that’s not really multi-threading ready.

Let me know in the comments if this helped, or if I need to add or fix anything.

P.S. I also wasted a few precious hours with django-sane-testing. Fixtures didn’t work, python manage.py test didn’t work in spite of having correct TEST_RUNNER configured, and it also didn’t serve static files. It also complained about django_session not existing, so it could be that specifying TEST_NAME there might help for that bit.

I am comparatively new to selenium and played a little with selenium IDE, and trying to do with selenium rc. I am baffled to use the scripting language there. Can you tell me what is the most used language in selenium across industries? And also I came across this course http://www.wiziq.com/course/12451-selenium-automated-web-browser-testing-for-web-applications os selenium automated web browser testing is this good? If someone does in Java and he joins a company where everyone does in ruby, then it’ll be a pain to learn ruby again. And also it would be great if you address any comparison about the available languages like (perl, python, ruby, java etc.) or tell me any other guidance would really appreciate help and also i would like to thank for all the information you are providing.