Creating and running Test Cases
This guide will help you create and run test cases using Selenium in conjunction with Django's testing tools. Follow these steps to set up your test environment and generate the necessary data.
How to write good test cases?
Generally test cases should be written for the following to reasons mainly:
To test a part of the website that has broken frequently. This is called regression testing.
To test most critical aspects of website which if broken could be costly for the buisness of the website.
Create test cases
1. Add Relevant Data in the Admin
Before writing your test cases, ensure that all the relevant data is added to the Django admin. This will be the data your test cases will interact with.
2. Export the Database
Once you have added the necessary data in the admin, export the database to a JSON file.
3. Write Your Test Cases
Add the database to the fixtures
folder in tests_ubyssey
directory. Then you can start the static live server that Django provides which runs in the background and feed it the database you created as a fixture. Then you can do the test setup similar to what is done in tests.py
file in tests_ubyssey
directory. For more details kindly refer to the Django testing documentation and selenium documentation for detailed instructions on creating test cases.
Testing Setup
To ensure that the parameterized tests are working as expected, follow these steps:
Rebuild Docker Compose:
First, rebuild your Docker Compose configuration to reflect the three new containers added to the
ubyssey-dev
repository.
Run this command:
Collect static files
If you don't have a directory
ubyssey.ca/static
, then navigate toubyssey.ca/config/settings/base.py
and uncomment out the line'whitenoise.runserver_nostatic'
inINSTALLED_APPS
. Then run the commandpython manage.py collectstatic
in theubyssey.ca
directory in terminal. This will create the directoryubyssey.ca/static
and populate it with the project's static files. These static files have to exist in order to run the tests because the test server is run withDEBUG=False
which changes where the static files are expected to be.
Run the Tests
Testing in Chrome
Start the Chrome Container:
In Docker Desktop, start the
selenium/standalone-chrome:latest
container.
Run the Tests:
Set the browser environment variable to Chrome and run the tests:
Testing in Firefox
Start the Firefox Container:
In Docker Desktop, start the
selenium/standalone-firefox:latest
container.
Run the Tests:
Set the browser environment variable to Firefox and run the tests:
Testing in Edge
Start the Edge Container:
In Docker Desktop, start the
selenium/standalone-edge:latest
container.
Run the Tests:
Set the browser environment variable to Edge and run the tests:
By following these steps, you will be able to verify that the parameterized tests work correctly across different browsers.
Last updated