Django acceptance testing automation with robot framework

Testing is a typical phase in the Web application development flow, because a Web application is made of multiple layers of logic starting from HTTP request handling, to request data validation and processing, to template rendering.

But testing phase of a Django Application development, it’s really easy. We use Unittest module built in to python standard library to write the test cases to simulate requests, insert the test data and inspect the application’s output.

You can perform automated testing in your Django application using different tools. Few of them are,

  • Writing the unit test cases using the python’s test client
  • Writing the unit test cases using the selenium
  • Writing the behavioral test cases using Django-behave framework
  • Writing the generic test cases for acceptance testing using Robot framework

In this blog, let's try to learn of what is Robot framework and how to write simple test cases using robot framework.

Robot Framework is one of the best testing automation frameworks for acceptance testing. Which can be very useful in the acceptance test-driven development. This framework uses a keyword-driven testing approach, and it has easy-to-use tabular test data syntax, which is a very effective way to achieve user acceptance testing. This framework is having an extensive amount of test libraries implemented either with Python or Java. The testers can create new higher-level keywords from existing ones using the same syntax that is used for creating test cases. Robot framework is implemented using Python, and it can run also on Jython (JVM) and IronPython (.NET).

Write your first test case using Robot framework:

You can install robot framework with the following command

pip install robotframework

Starting from Robot Framework 3.0, tests are executed using the robot script and results post-processed with the robot script: The following is the syntax to run the test cases

robot tests.robot
robot output.xml

The other way to run tests is executing the installed robot module is directly using Python's -m command line option.

python -m robot tests.robot
python -m robot.rebot output.xml

Writing your test cases in robot framework:

As we discussed in the beginning of this blog post Robot framework uses a keyword-driven testing approach, and It has easy-to-use tabular test data syntax. Lets us start with a simple example of user account creation and sign in process. Following are the two cases that we try in this example.

  • User can create an account and log in
  • User cannot log in with the bad password
*** Test Cases ***

User can create an account and log in
    Create Valid User    fred    P4ssw0rd
    Attempt to Login with Credentials    fred    P4ssw0rd
    Status Should Be    Logged In 

User cannot log in with bad password
    Create Valid User    betty    P4ssw0rd
    Attempt to Login with Credentials    betty    wrong
    Status Should Be    Access Denied

In the above example, the syntax is more like natural English language rather than complex programming language style syntaxes.
You can save this with .robot extension and execute the test case using

robot myfirsttest.robot
robot output.xml

As discussed in this blog post, keywords are the major essentials of this framework. The keywords can be created keywords that can come from two sources.

  • Library keywords come from imported test libraries
  • User keywords can be created using the same tabular syntax that is used for creating test cases.

We can discuss more about keywords, variables in coming blog posts on Robot framework.

Posted On 26 October 2018 By MicroPyramid

About Micropyramid

Micropyramid is a software development and cloud consulting partner for enterprise businesses across the world. We work on python, Django, Salesforce, Angular, Reactjs, React Native, MySQL, PostgreSQL, Docker, Linux, Ansible, git, amazon web services. We are Amazon and salesforce consulting partner with 5 years of cloud architect experience. We develop e-commerce, retail, banking, machine learning, CMS, CRM web and mobile applications.

Need any Help in your Project?Let's Talk


Subscribe To our news letter

Subscribe and Stay Updated about our Webinars, news and articles on Django, Python, Machine Learning, Amazon Web Services, DevOps, Salesforce, ReactJS, AngularJS, React Native.
*We don't provide your email contact details to any third parties