A Robot Framework library for Django.
Project description
Introduction
DjangoLibrary is a web testing library to test Django with Robot Framework. It uses SeleniumLibrary to run tests against a real browser instance.
The library will automatically start and stop your Django instance while running the tests. It also comes with serveral autologin keywords that allow you to login different users during your tests, without the need to actually access the login page.
DjangoLibrary is currently tested against Django 1.8.x, 1.9.x, 1.11.x with SQLite and Postgres on Python 2.7 and 3.6.
Documentation
Installation
Install robotframework-djangolibrary with pip:
$ pip install robotframework-djangolibrary
In order to be able to use DjangoLibrary’s Autologin, FactoryBoy, or QuerySet keywords you have to add the corresponding middleware classes to your MIDDLEWARE_CLASSES in yoursettings.py:
MIDDLEWARE_CLASSES = ( ... 'django.contrib.auth.middleware.AuthenticationMiddleware', 'DjangoLibrary.middleware.AutologinAuthenticationMiddleware', 'DjangoLibrary.middleware.FactoryBoyMiddleware', 'DjangoLibrary.middleware.QuerySetMiddleware', )
First Robot Test
In order to write your first robot test, make sure that you include SeleniumLibrary and DjangoLibrary. Create a test.robot file with the following content:
*** Variables *** ${HOSTNAME} 127.0.0.1 ${PORT} 55001 ${SERVER} http://${HOSTNAME}:${PORT}/ ${BROWSER} firefox *** Settings *** Documentation Django Robot Tests Library SeleniumLibrary timeout=10 implicit_wait=0 Library DjangoLibrary ${HOSTNAME} ${PORT} path=mysite/mysite manage=mysite/manage.py settings=mysite.settings Suite Setup Start Django and open Browser Suite Teardown Stop Django and close Browser *** Keywords *** Start Django and open Browser Start Django Open Browser ${SERVER} ${BROWSER} Stop Django and close browser Close Browser Stop Django *** Test Cases *** Scenario: As a visitor I can visit the django default page Go To ${SERVER} Wait until page contains element id=explanation Page Should Contain It worked! Page Should Contain Congratulations on your first Django-powered page.
License
Copyright kitconcept GmbH.
Distributed under the terms of the Apache License 2.0, robotframework-djangolibrary is free and Open Source software.
Contribute
Support
If you are having issues, please let us know. If you require professional support feel free to contact us at info@kitconcept.com.
Run Tests
Then you can run the test with robot:
$ robot test.robot
The output should look like this:
============================================================================== Test :: Django Robot Tests ============================================================================== Scenario: As a visitor I can visit the django default page | PASS | ------------------------------------------------------------------------------ Test :: Django Robot Tests | PASS | 1 critical test, 1 passed, 0 failed 1 test total, 1 passed, 0 failed ============================================================================== Output: /home/timo/workspace/prounix/robotframework-djangolibrary/output.xml Log: /home/timo/workspace/prounix/robotframework-djangolibrary/log.html Report: /home/timo/workspace/prounix/robotframework-djangolibrary/report.html
Test Isolation
robotframework-djangolibrary does not provide isolation between tests by default. This means if you add an object to the database in a test, this object will be present in the next test as well. You need to cleanup yourself in order to have a proper isolation between the tests. You can use the robotframework “Test Teardown” call to call the “Clear DB” keyword after each test:
*** Settings *** Library SeleniumLibrary timeout=10 implicit_wait=0 Library DjangoLibrary ${HOSTNAME} ${PORT} path=mysite/mysite manage=mysite/manage.py settings=mysite.settings db=mysite/db.sqlite3 Suite Setup Start Django and open Browser Suite Teardown Stop Django and close Browser Test Teardown Clear DB
Development
Checkout repository from github:
$ git clone https://github.com/kitconcept/robotframework-djangolibrary.git
Create a virtual Python environment:
$ cd robotframework-djangolibrary/ $ virtualenv .py27 $ source .py27/bin/activate
Install robotframework-djangolibrary in development mode:
$ python setup.py develop
Install the requirements:
$ pip install -r requirements.txt
Run Unit/Integration-Tests:
$ py.test mysite/
Run Acceptance Tests:
$ robot DjangoLibrary/tests/
3.1.0 (2018-12-24)
New Features:
Python 3.7 support. [timo]
3.0.0 (2018-11-26)
Breaking Changes:
Depend on SeleniumLibrary instead of Selenium2Library. The name changed from Selenium2Library to SeleniumLibrary. See https://github.com/robotframework/SeleniumLibrary/blob/master/docs/SeleniumLibrary-3.0.0.rst#name-changed-from-selenium2library-to-seleniumlibrary for details. [timo]
New Features:
Python 3.6 support (earlier versions most likely do support Python 3.6 as well, we just did not test it so far). [timo]
2.0.2 (2018-03-03)
Bugfixes / Minor Changes:
Fix Pypi markup. [timo]
2.0.1 (2018-03-03)
Bugfixes / Minor Changes:
Fix outdated documentation. [timo]
2.0 (2017-09-20)
Breaking Changes:
Remove deprecated method from internal startup flow. [cdvv7788]
New Features:
Use AUTH_MODEL to create user instead of django’s default [cdvv7788]
Upgrade FactoryBoy to version 2.8.1 [amarandon]
Add Django 1.10.7 and 1.11.1 support. [timo]
LICENSE.txt added. [timo]
Bugfixes / Minor Changes:
Move tests to use Chrome. [timo]
Upgrade tests to Django 1.11.5, 1.10.8, 1.9.13, 1.8.18. [timo]
Add Django 1.11 and 1.10 to setup.py. [timo]
1.2 (2016-07-08)
New Features:
Make Factory Boy keyword return ‘pk’ attribute. [timo]
1.1 (2016-07-07)
New Features:
Add QuerySet keyword. [timo]
Make it possible to override subfactories when using the FactoryBoy keyword. [timo]
Bugfixes:
Use Django’s model_to_dict method to serialize the response objects for the factory_boy keyword. [timo]
1.0 (2016-06-30)
Re-release 1.0a6 as 1.0. [timo]
1.0a6 (2016-04-29)
New Features:
Python 3 compatibility. Note that the latest offical release of robotframework-selenium2library is currently not compatible with Python 3. See https://github.com/HelioGuilherme66/robotframework-selenium2library/releases for a working pre-release and details. [timo]
Support for Postgres added. All Django database backends should work. We test SQLite and Postgres only though. [timo]
Add ‘Factory Boy’ keyword. This allows us to use factory_boy factories in Robot Framework tests. [timo]
Breaking Changes:
Drop Django 1.7.x support. We test and support Django 1.8.x and 1.9.x. [timo]
Change ‘Clear DB’ implementation to use “python manage.py flush” instead of deleting and re-building the database. [timo]
Remove ‘Debug’ and ‘Pause’ keywords. The ‘Debug’ keyword, which is provided by robotframework-debuglibrary is sufficient. [timo]
1.0a5 (2016-02-11)
Make middleware part Python 3 compatible.
robotframework-djangolibrary is still not compatible with Python 3 because robotframework-selenium2library does not work with Python 3 yet. Though, you can install robotframwork-djangolibrary on Python 3 with “pip install robotframework-djangolibrary –no-deps” and then run your tests with Python 2.7. [timo]
Add ‘Framework :: Robot Framework’ classifier to setup.py. [timo]
1.0a4 (2016-02-05)
Use ‘migrate’ instead of ‘syncdb’ for Django > 1.7.x. [timo]
1.0a3 (2015-09-28)
Add list_classifiers to setup.py. [timo]
Fix user creation and startup. This fixes #3. [MatthewWilkes]
1.0a2 (2015-06-25)
Remove Django and zest.releaser from requirements.txt. This fixes #2. [timo]
1.0a1 (2015-06-24)
Initial release. [timo]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file robotframework-djangolibrary-3.1.0.tar.gz
.
File metadata
- Download URL: robotframework-djangolibrary-3.1.0.tar.gz
- Upload date:
- Size: 70.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2df555462e58691986103297564f31f6bef73ae1212a87506a9a63770474ce |
|
MD5 | 4ce4932c81b80bf11a29f701ce483b03 |
|
BLAKE2b-256 | d7f409014888f58e1dfa50b3e6f4e3cea4cd2e5f2a58364493a66bef322d7364 |