Django views automated testing with selenium


Mar 4, 2015 · 2 min read

Selenium is set of tools for automating browsers. It provides a lot of options and APIs for automating user interaction with the web applications. It is used for testing web applications, web scraping and automating boring repetitive tasks.

Selenium supports automation on all the major browsers including Firefox, Internet Explorer,Google Chrome, Safari, and Opera. Selenium can be also ran on android devices.

In our story we gonna use selenium WebDriver with Firefox for automating a django views test same as we were doing it manually.


Selenium WebDriver is available for various programming languages. on our case we gonna use python. To install the selenium package in a simple way, we gonna use pip.

$ sudo pip install selenium

Now our package is installed. Then, we gonna demonstrate how to write a functional test for a django project.


Our environment is ready now for writing our tests.

For a quick demo i gonna write an automated test for a the account app to create a new user account.

We will inherit LiveServerTestCase class that gonna run automatically a test server in the background. Then, our selenium tests will be ran against that server. We can run our test simply by using the following command by replacing appname with your django app name.

$ python test appname

In each django app there is a file dedicated to write and run our test. Im using the follow snippet in my tests file.

As we see, the code is so simple and all that’s is running our test.

### Links

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store