The purpose of this repo is to create a structured playground for automating end-to-end tests for the company page https://www.stxnext.com. Feel free to contribute and have fun!
Project implements Page Object Pattern architecture as it's Playwright compliant and nobody ever got fired for using it.
-
tests: definition of test suites and scenarios
-
conftest.py: allows you to define fixtures, plugins, and hooks that can be shared across multiple test files in a subdirectories.
-
pages: main project library combines pages construction and behaviour in
page_objects
, pages locator definition and generation inlocators
and common elements like navbars or textinputs inelements
. -
pytest.ini is a configuration file for Pytest that allows you to set options and modify the behavior of Pytest for a specific project.
Poetry is a dependency management and packaging tool for Python that helps you manage your project's dependencies and build your project. It's similar to pip, but provides additional features and benefits.
-
Dependency management: Poetry provides version constraints, installation and updating of packages, and virtual environment management.
-
Lockfile: Poetry generates a poetry.lock file that ensures that everyone working on the project uses the same set of dependencies with the same versions
-
Packaging: Poetry generates a pyproject.toml file that describes your project and its dependencies, as well as a source distribution and wheel package that you can distribute to others.
-
Integration with other tools: Poetry integrates with other tools, such as Pytest and Flake8, to help you manage your project's dependencies and testing.
Poetry can be installed via python standard package manager PIP
pip install poetry
To spawn poetry session inside your environment, write
poetry shell
This command starts a new shell and activates the virtual environment. As such, exit should be used to properly exit the shell and the virtual environment instead of deactivate.
To add a new dependency to your project, use the add command:
poetry add <package>
This will add the requests package to your project and update the pyproject.toml file.
To install dependencies defined in pyproject.toml
, simply run
poetry install
Pre-commit is a framework used for pre-commits git hooks management. It allows to define actions that confirm that written code is formatted and configured properly according to defined practices.
TLDR you cannot commit stuff unless it's green and your code fits the language guidelines like PEP8
To run validation automatically before each commit, please use:
pre-commit install
This will add pre-commit to git hooks and perform all the checks defined in .pre-commit-config.yaml
To check stying in all files, please use:
pre-commit run -a
Every pull request should pass pre-commit stage to be merged
This project uses pytest
with pytest-playwright
as a test runner.
To run all the scripts with default setting simply type:
pytest
pytest tests/test_stx_blog.py::test_blog_page_and_filter_articles
pytest -k stx
For more fancy ways of defining your suite check the official markers documentation
This will run tests in a headed browser with a delay of 500 milliseconds between actions. It will make observing browser behaviour easier.
pytest --headed --slowmo 500
You can insert a breakpoint in your test. It will open interactive pdb session in your console which allows you to use commands like: continue, return, quit
def test_something(pytestconfig) -> None:
base_url = pytestconfig.getini("base_url")
breakpoint()
To run tests on specific browsers, use the Pytest command with the --browser option:
pytest --browser firefox
This will run tests on Firefox. You can also specify multiple browsers:
pytest --browser firefox --browser chromium
This repo uses pytest-xdist
package to allow multiple test being performed in parallel.
Here is an example of running 5 parallel sessions on 3 browsers:
pytest --base-url https://www.stxnext.com -n 5 --browser chromium --browser firefox --browser webkit
Playwright comes with video recording and screen capturing out of the box. The results are saved in test-results directory by default.
pytest --screenshot={on,off,only-on-failure}
pytest --video={on,off,retain-on-failure}
Sometimes it's convenient to control the browser in interactive session in your python console. To run Playwright without Pytest, try this snippet
from playwright.sync_api import sync_playwright
playwright = sync_playwright().start()
# Use playwright.chromium, playwright.firefox or playwright.webkit
# Pass headless=False to launch() to see the browser UI
browser = playwright.chromium.launch(headless=False)
page = browser.new_page()
page.goto("https://www.stxnext.com")
page.screenshot(path="example.png")
browser.close()
playwright.stop()
The purpose of Continuous integration in this repo is to:
- Validate created Pull Requests - confirm the pre-commit and test are passing
- Create a template for regularly launched tasks that will Test the targeted environment
This project is licensed under the terms of the MIT license.