A quick login for selenium tests to be used in Django projects
Project description
django-selenium-login sets a session cookie for the Selenium driver and a creates a session object for the Django backend in order to force a user to quickly login.
Usage
With django-selenium-login you can use the force_login function to force a user to qucikly login before using the the Selenium driver to proceeds on pages that requires login. The function takes a Django user, a Selenium driver, and the base url for the live server. Here is an example of how to use the force_login function in a test:
from seleniumlogin import force_login
def test_use_django_selenium_login_to_force_login(selenium, live_server):
User = get_user_model()
user = User.objects.create_user(username='myuser', password='password')
force_login(user, selenium, live_server.url)
selenium.get('{}/a/url/which/requires/login/'.format(live_server.url))
Before setting the session cookie for the Selenium driver, the driver must access a page in the project. By default it will try to access the /page_404/ page. This can be changed by changing the SELENIUM_LOGIN_START_PAGE setting in the settings file for your tests. A blank page is used for the tests in this lib.
The force_login function specifies True as default value for set_domain_in_session_cookie. If set to False, domain will not be set for the cookie. This can be useful when using force_login with Firefox when liveserver is started with localhost. For some reason domain names without dots are not accepted in the session cookie with Firefox.
Installation
Use pip to install django-selenium-login:
pip install django-selenium-login
For developers
Create venv using:
make venv
Run tests for multiple versions of Python and Django for a specific browser using tox:
tox -- --driver=Chrome
Use environment variable SESSION_ENGINE to change authentication backend.
To run tests for all authentication backends for Chrome, Firefox, and PhantomJS:
./run_tests.sh
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-selenium-login-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6566c113e9d1f90055d07d44387303418c3a4b4d14d3c19f0dd39ca8baf2bc17 |
|
MD5 | 3f4549fb508714d90ba6e046abf85be1 |
|
BLAKE2b-256 | 112aa843cab9ab741b5b0a7a2d601881b7594445b709fc654dab3817a462a4e1 |
Hashes for django_selenium_login-1.1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 942f853bd935f580eaeeb5ba97a145a42a30e59065a79738d8af2cc7ba5a3257 |
|
MD5 | 1e28aeb0e575aa28aab4350dac244273 |
|
BLAKE2b-256 | 4b04e83bca1bbed30a86a38cb420e11b3dde1688364514283949523f9b359c78 |