Test automation framework for testing UI, front-end and back-end API of restful-booker web-site - https://automationintesting.online.
- Latest project documentation available on ReadTheDocs: 'Python TA Framework Docs'
- Published documentation has minor issues and not all features of published documents can work as expected
- Resources of web app
- Test framework configuration and setup
- Project docs
- Project setup process 0. Setup by scripts
- Tests
- Test execution by pytest
- Run all Tests
- Run tests in a module
- Test run for specific test (by test name) by command
- Run Tests in a directory
- Run tests of a specific class
- Run tests by marker expressions
- Run tests by node IDs
- Additonal parts for test run/configuration
- Test report generation
- Existing(created) tests by categories
- Publishing Sphinx doc on GitHub pages
- Resources for TA frameworks
https://automationintesting.online/
https://restful-booker.herokuapp.com/apidoc/index.html
Home web page: https://automationintesting.online
```
logo(picture)
welcome_text
rooms_section
room_section
hotel_picture
hotel_room_description
hotel_room_description_header
hotel_room_type
hotel_room_wheelchair_option
hotel_room_description_title
hotel_room_options
hotel_room_option_wifi
hotel_room_option_refreshments
hotel_room_option_tv
hotel_room_option_safe
hotel_room_option_radio
hotel_room_option_views
hotel_room_booking_button
booker_contact_form
name_input_form
email_input_form
phone_input_form
subject_input_form
message_input_form
submit_button_on_contact_form
alert_booker_form
hotel_contact_details_field
map_picture
footer_panel
site_owner_info
cookie_policy_link
privacy_policy_link
admin_panel_link
```
Booking web page: https://automationintesting.online
Same URL as for Home page but with additional components on the page
Home web page: https://automationintesting.online/#/admin/
Report web page: https://automationintesting.online/#/admin/report
Branding web page: https://automationintesting.online/#/admin/branding
Messages web page: https://automationintesting.online/#/admin/messages
In this project used 'pip-tools' and approach to use high-level dependency tree. Main required packages presented
in requirements.in
. All used Python packages for the current project are generates in requirements.txt
Below is the list of main packages with references
-
pytest
- pypi.org docs: https://pypi.org/project/pytest/
- related info: https://docs.pytest.org/en/latest/
pip install pytest
-
hypothesis
- pypi.org docs: https://pypi.org/project/hypothesis/
- related info: https://hypothesis.works/
pip install hypothesis
-
selenium
- pypi.org docs: https://pypi.org/project/selenium/
- related info: https://selenium-python.readthedocs.io/
pip install selenium
-
webdriver-manager
- pypi.org docs: https://pypi.org/project/webdriver-manager/
- related info: https://github.com/bonigarcia/webdrivermanager
pip install webdriver-manager
-
mypy
- pypi.org docs: https://pypi.org/project/mypy/
- related info: https://mypy-lang.org/
pip install mypy
-
python-dotenv
- pypi.org docs: https://pypi.org/project/dotenv/
- related info: https://www.dotenv.org/docs/languages/python
pip install python-dotenv
-
pyyaml
- pypi.org docs: https://pypi.org/project/PyYAML/
- related info: https://pyyaml.org/
pip install pyyaml
-
configParser
- pypi.org docs: https://pypi.org/project/configparser/
- related info: https://docs.python.org/3/library/configparser.html
pip install configparser
-
openpyxl
- pypi.org docs: https://pypi.org/project/openpyxl/
- related info: https://openpyxl.readthedocs.io/en/stable/
pip install openpyxl
-
pylint
- pypi.org docs: https://pypi.org/project/pylint/
- related info: https://github.com/pylint-dev/pylint
pip install pylint
Generate a default configuration file for the Pylint code analyzer by
pylint --generate-rcfile > pylint.rc
-
pyreverse
- pypi.org docs: https://pypi.org/project/pyreverse/
- related info: https://pylint.readthedocs.io/en/latest/pyreverse.html
Pyreverse has now been integrated to pylint : http://pypi.python.org/pypi/pylint/
-
pipdeptree
- pypi.org docs: https://pypi.org/project/pipdeptree/
- related info: https://github.com/tox-dev/pipdeptree
pip install pipdeptree
-
invoke
- pypi.org docs: https://pypi.org/project/invoke/
- related info: https://www.pyinvoke.org/
pip install invoke
-
allure
- pypi.org docs: https://pypi.org/project/allure-pytest/
- related info: https://allurereport.org/docs/pytest/
pip install allure-pytest
-
pytest-html
- pypi.org docs: https://pypi.org/project/pytest-html/
- related info: https://pytest-html.readthedocs.io/en/latest/
pip install pytest-html
-
loguru
- pypi.org docs: https://pypi.org/project/loguru/
- related info: https://loguru.readthedocs.io/
pip install loguru
-
wonderwords
- pypi.org docs: https://pypi.org/project/wonderwords/
- related info: https://loguru.readthedocs.io/
pip install wonderwords
-
Faker
- pypi.org docs: https://pypi.org/project/Faker/
- related info: http://faker.rtfd.org/
pip install Faker
- mysql-connector-python
- pypi.org docs: https://pypi.org/project/mysql-connector-python/
- related info: https://dev.mysql.com/doc/connector-python/en/
pip install mysql-connector-python
-
PyHamcrest
- pypi.org docs: https://pypi.org/project/PyHamcrest/
- related info: https://pyhamcrest.readthedocs.io/
pip install PyHamcrest
-
regex
- pypi.org docs: https://pypi.org/project/regex/
- related info: https://github.com/mrabarnett/mrab-regex
pip install regex
- pylint
- pypi.org docs: https://pypi.org/project/pylint/
- related info: https://pylint.readthedocs.io/en/latest/
pip install pylint
This project contains generated documentation by Sphinx All documentation you can find by opening index.html in the browser or check ta_framework_ui_api.pdf Sphinx setup and generating process described here
By default, you can use file:
setup_env.bat
for Windows-based machine orsetup_env.sh
UNIX-based for validating python version, installing all packages required for running current project. Otherwise, you can manually install everything using described steps below or fix some issues that appears while project was configured via scripted file.
-
Create virtual environment.
Script below is creating environment with name 'env'.
If you want to create environment with unique name, please replace the env name using your env name in script
python -m {here_is_your_venv_name} ../envWorking script for creating venv with name 'venv' is below:
python -m venv ../env
then activate it
- for unix-based
source ../venv/bin/activate
- for windows
.\.venv\Scripts\Activate
If you like to have different name for the environment
python -m venv {venv_for_project}
and then
source {venv_for_project}/Scripts/activate
For deactivating created env use command
-
deactivate
pip install -r requirements.txt
If requirements.txt file is missing request, or you have different configuration of the project after installation, please check generate new requirements.txt file using command
pip-compile requirements.in
Created requirements.txt
file will have all dependency for the project.
In case if you are using 'pip-tools' do next steps,
- check
requirements.in
content for preventing conflicts with existing(venv/global) configurations. - compile requirements.txt by
pip-compile requirements.in
- install dependencies by
pip install -r requirements.txt
-
Check your system on installed and available :
-
JAVA
java -version
-
Node.js
node -v
If programs are missing install them using info below
-
-
Install Java 3
- Download Java 3 HERE
-
Install Node.js
- Download Node.js HERE
-
In command prompt, run the below command
npm install -g allure-commandline
-
Add npm and allure-commandline to system path
%AppData\Roaming\npm
%AppData\Roaming\npm\node_modules\allure-commandline\bin
-
Check that system can have access to allure by
allure --version
-
Install allure-pytest
pip install allure-pytest
or from your IDE
In case if your test data is stored in DB or external files, check the project configuration and adjust test data manually.
If you are using data from DB generate data based on your testing model or paste it manually preferable to use pip install mysql-connector-python
Basic Dependency Tree
pipdeptree
Dependency Tree in JSON Format
pipdeptree --json
Dependency Tree with Outdated Packages
pipdeptree --outdated
Dependency Tree for a Specific Package
pipdeptree -p <package_name>
Generate a Text Report and Save to File
pipdeptree > resources/project_dependencies.txt
Visualize Dependency Tree with Graphviz first install graphviz:
pip install graphviz
then generate a graphical representation:
pipdeptree --graph-output png > resources/project_dependencies.png
To check your code for missing docstrings for current project selected pydocstyle.
pydocstyle core
To check all Python files in a specific directory, you can run:
bash
pydocstyle path/to/your_directory/
You can specify the docstring conventions you want to enforce using the --convention
flag. The available conventions
are:
google
numpy
pep257
For example, to check using the Google style:
bash
pydocstyle --convention=google path/to/your_directory/
If you want to ignore certain error codes, you can use the --ignore
option followed by the error codes (
comma-separated). For example, to ignore error code D103 (missing docstring in public function):
bash
pydocstyle --ignore=D103 path/to/your_directory/
You can change the output format using the --format
option. The default format is a simple text output, but you can
change it to json
for easier parsing:
bash
pydocstyle --format=json path/to/your_directory/
To see more detailed output, you can run pydocstyle
in verbose mode:
bash
pydocstyle --verbose path/to/your_directory/
You can check a specific line in a file by appending the line number to the file path. For example, to check line 42
of your_file.py
:
bash
pydocstyle path/to/your_file.py:42
To see a list of all available error codes and their meanings, use the --help
option:
bash
pydocstyle --help
-
Check a specific file:
pydocstyle path/to/your_file.py
-
Check an entire directory:
pydocstyle path/to/your_directory/
-
Specify conventions:
pydocstyle --convention=google path/to/your_directory/
-
Ignore specific errors:
pydocstyle --ignore=D103 path/to/your_directory/
-
Output in JSON format:
pydocstyle --format=json path/to/your_directory/
- Install Sphinx in your project environment:
pip install sphinx
- Set Up Sphinx in Your Project
!!! IMPORTANT
For more convenient usage of project structure to better create separate folder where will be stored all
documentation and related Sphinx config files and folder.
For this project was created new folderdocs
and from that place all Sphinx related command should be executed. After navigation to thedocs
directory, run:sphinx-quickstart
This command will guide you through setting up Sphinx by asking several configuration questions.
Typical responses:
-
Separate source and build directories: Yes
-
Project name: [Your project name]
-
Author name: [Your name]
-
Project version: [Your project version]
-
Project language: [en]
This will generate\
source/
directory with a defaultconf.py
file for configuration and some starter.rst
(reStructuredText) files.\build/
directory (will be empty). It's default directory that will have all project related data if you will not use any different name for collecting generated Sphinx docs (pdf, html... etc).
It can be deleted or renamed if you want to have separate places for different types of generated docs. For this project will be generated documentation in HTML and PDF formats. Below you will find scripts and instructions for generating documents in PDF and HTML format using different Sphinx extensions.- make.bat - default script file for generating docs on Windows OS
- Makefile - default script file for generating docs on UNIX base OS
-
Configure conf.py Edit the generated conf.py file located in the source/ directory to customize your documentation. Key configurations to include:
- Extensions: Enable useful Sphinx extensions, such as autodoc for auto-generating documentation from your Python docstrings:
extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.napoleon', # For Google-style or NumPy-style docstrings ]
-
Paths: Set the path for your Python modules to be included in the docs:
import os import sys sys.path.insert(0, os.path.abspath('../..'))
('../..')) line tells Python to add the parent directory (two levels up) to the Python module search path. This is necessary when your project's files (modules, packages, etc.) are in a directory separate from the documentation (Sphinx docs) directory.
By specifying ../.., you're telling Sphinx (and Python) to include the top-level project directory in its search path, allowing it to find and import modules from the project directory while building the documentation.
-
HTML Theme: You can set the theme for your HTML documentation (default is alabaster):
html_theme = 'sphinx_rtd_theme' # Example: ReadTheDocs theme
-
Source file suffix*: Define which file extensions to look for:
source_suffix = ['.rst', '.md']
-
Install related to chosen Sphinx extensions packages.
-
For 'sphinx_rtd_theme' theme execute
pip install sphinx_rtd_theme
-
For 'myst_parser' theme execute
pip install myst_parser
-
For 'rst2pdf' theme execute
pip install rst2pdf
-
-
Document Your Code.
-
Generate reStructuredText (.rst) Files To automatically generate
.rst
files from your Python code, use sphinx-apidoc. This will generate asource/
directory with .rst files that describe your modules and classes:sphinx-apidoc -o source/ path/to/your/module
!!! IMPORTANT
For the current project all Sphinx documentation is stored indocs
folder and script below should be executed from the project root foldersphinx-apidoc -o docs/source .
-
Build HTML Documentation
!!! IMPORTANT
For the current project script below should be executed from the project root folder.
Once your.rst
files are in place andconf.py
is configured, you can build the HTML documentation:-
on Windows OS
sphinx-build -b html docs/source/ docs/html/
where html_docs - custom defined name for storing generated html docs.
If errors appears after generating docs try to clear the cached build.
Clear thebuild/
directory by deleting it or running:sphinx-build -b html -E source/ html/
The -E flag forces Sphinx to rebuild everything from scratch, avoiding potential caching issues.
-
on UNIX
make html
This command will generate the HTML files inside the build/html/ directory. Open the
index.html
file in your browser to view your documentation.
-
-
Build PDF Documentation
- on Windows OS
sphinx-build -b pdf source/ pdf_docs/
- View Documentation Navigate to the build/html/ directory and open index.html in your browser to view your generated documentation.
Additional Configurations (Optional) Include Markdown files: If you want to include .md files, ensure the myst_parser is installed and enabled:
pip install myst-parser
Then add it to conf.py
:
extensions = ['myst_parser']
Customizing Themes: You can install additional Sphinx themes by running pip install and configuring
html_theme in conf.py
.
More information about test runs by pytest you can find here
All tests are located in tests folder
To run all the tests from the root directory, you can use the following command:
python pytest
or just
pytest
You can add the -v flag to get more verbose output:
python pytest -v
You can enable live console logging using the pytest -s command too.
To run all tests in a specific file (module), use the following command:
pytest tests/unit/test_functions.py
Use the -k
option followed by the name of the test function or method you want to run
python -k {some_test}}
e.g. python -k test_dummy_test.py
Perhaps you may decide to split your tests by unit, integration, end-to-end, performance, regression and so on.
If you need an overview of the various types of testing for your Python applications, this article on the types of
software testing is a good introduction.
In these cases it’s helpful to run tests within a specific directory, and you can use:
pytest {path_to_the_folder_with_test}
e.g.
pytest tests/dummy_tests
To run a specific test, you can use the test’s node ID, which is essentially its path in the syntax:
{filename.py}::{test_function_name}.
For example, to run the test_add_negative_numbers function in the test_functions.py file, you can use the following
command:
pytest test/dummy_tests/test_functions.py::test_add_positive_numbers
This runs the test_add_positive_numbers test in the test_functions.py file.
You can also run all tests in a specific class. To do this, you use the :: operator followed by the class name.
For example, to run all tests in the RegressionTests class, you can use the following command:
pytest test/dummy_tests/test_functions.py::TestsUnit
By using markers, you can run specific groups of tests, exclude tests, and prioritize tests. This can help you to write better tests and to get more value from your test suite.
We’ve covered several kinds of markers in the articles on Pytest Timeout, Pytest Skip Tests and Pytes Asyncio.
In Pytest, you can assign markers to your test functions using the @pytest.mark decorator. You can then use these markers to run specific tests.
This is especially useful when you have different types of tests, such as fast and slow tests, and you want to run them selectively.
Example of pytest written with markers presented below
@pytest.mark.unit
def test_one():
result_of_doing = do_something()
assert result_of_doing ==1
To run tests based on marker expressions, you use the -m flag followed by the marker name.
[pytest]
markers =
unit : unit tests
end_to_end : end to end tests
skip : slow tests`
command is
pytest -m unit
In case if ini file located not in the root directory marker should be passed via flag -c
and valid configured path to
the ini file
The -c option allows you to specify the path to your pytest.ini file directly.
pytest -c path/to/your/pytest.ini
example of usage for current project is pytest -c config/pytest.ini -m unit
Better to set the PYTEST_ADDOPTS environment variable to include the config file path:
export PYTEST_ADDOPTS="-c config/pytest.ini"
Rerun for failed tests work after installation of pytest-rerunfailures
pip install pytest-rerunfailures
Check version of pytest-rerunfailures
pytest-rerunfailures --version
pytest --reruns 3 --alluredir="resources/project_test_reports/allure_reports
or in paralel
pytest -n 10 --reruns 3 --alluredir="resources/project_test_reports/allure_reports"
Full Command Breakdown
-n 10
: Runs tests in parallel using 10 worker processes.
--reruns 3
: Reruns any failed tests up to 3 times.
--alluredir="resources/project_test_reports/allure_reports"
: Specifies the directory to store Allure reports.
Installing Required Plugins
Make sure you have the required plugins installed:
- for parallel test execution
pytest-xdist
pytest -n 3
-n 4: Runs tests in parallel using 4 worker processes.
- Test for checking home page (not a booking view)
pytest test/web_app_tests/test_login_page.py::test_check_main_section_of_home_page
Simple pytest report generation in html format is possible by executing command
Short Traceback:
pytest --tb=short
Long Traceback (default):
pytest --tb=long
No Traceback (only show test results):
pytest --tb=short --disable-warnings
pytest --html=resources/project_test_reports/pytest_reports/pytest_general_test_report.html
using workers
pytest -n 10 --html=resources/project_test_reports/pytest_html_reports/pytest_html_general_test_report.html
pytest --junitxml=resources/project_test_reports/pytest_junit_xml_reports/pytest_junit_xml_general_test_report.xml
For generating Allure reports on the tests performed, you must first execute tests by pytest. You need specify a path for the test results directory in the --alluredir command-line argument when running your tests.
pytest --alluredir="resources/test_report/allure_reports"
If any any error appears
- Check that the system statisfy Allure requirements.
- Confirm that all components installed, report folder is created. need to specify execution tests by pytests with specific output format.
When test execution completed , Allure reports generation starts after executing
allure serve {path_to_report_folder}
Example of command execution:
(.venv) {project_dir_path} allure serve "resources/allure_reports"
command that is applicable for the current project configuration is
allure serve "resources/test_report/allure_reports"
After successful execution of command allure starts server and provide server URL for checking allure report in the browser.
List of existing tests for the current project is possible to generate by executing python
script make_list_of_tests.py.
Result will be presented in the list_of_all_project_tests.md.
All tests are grouping by categories.
IMPORTANT!!!
If you did any changes, please validate path to the test dir in
the make_list_of_tests.py
- Generate Sphinx HTML Docs (If docs were not created, see section Generating documentation by Sphinx)
- Create a Separate Branch for Documentation (Optional but Recommended):
- You can store the generated documentation in a dedicated branch, such as gh-pages, to keep it separate from your
main project code
git checkout --orphan gh-pages git rm -rf .
- Add the generated HTML files:
cp -R docs/_build/html/* . git add . git commit -m "Publish Sphinx docs" git push origin gh-pages
- You can store the generated documentation in a dedicated branch, such as gh-pages, to keep it separate from your
main project code
- Set Up GitHub Pages:
- Go to your repository settings on GitHub.
- Under Pages, select the branch (e.g.,
gh-pages
) and folder (e.g.,/root
or/docs
) where your documentation is stored. - Save the settings, and GitHub will publish your documentation at a URL like:
https://<username>.github.io/<repository-name>/
- Create workflow file
- Create separate branch on GitHub
3. Create
gh-pages
branch if for some reason workflowyaml
file failed to this from 1st attempt
- Contact List App - web app for pure API testing
- was available at 18 June 2024
- Web apps for testing
- OrangeHRM web app
- httpbin.org - web app
- tutorialsninja.com - web app
- was available at 18 June 2024