diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3fbb07cc..0a7c35b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -59,10 +59,10 @@ jobs: needs: tests runs-on: ubuntu-latest steps: - - name: Set up python 3.10 + - name: Set up python 3.13 uses: actions/setup-python@v6 with: - python-version: '3.10' + python-version: '3.13' - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.readthedocs.yaml b/.readthedocs.yaml index eedaacf8..bd800333 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -6,9 +6,9 @@ version: 2 # Set the version of Python and other tools you might need build: - os: ubuntu-20.04 + os: ubuntu-24.04 tools: - python: "3.10" + python: "3.13" # Build documentation in the docs/ directory with Sphinx sphinx: diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 76094019..450e5ee9 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -7,6 +7,7 @@ v3.8.1 *Release date: In development* - Add token usage tracking to OpenAI requests +- Add pytest and unittest runners documentation in `Docs `_ v3.8.0 ------ @@ -596,7 +597,7 @@ v1.3.0 *Release date: 2017-09-12* -- Add Behave dynamic environment (more info in `Docs `_) +- Add Behave dynamic environment (more info in `Docs `_) - Fix visual screenshot filename error when behave feature name contains : - Add a config property 'explicitly_wait' in [Driver] section to set the default timeout used in *wait_until* methods - When reuse_driver is true using behave, driver is initialized in *before_feature* method and closed in *after_feature* diff --git a/README.rst b/README.rst index d3691000..50b9105a 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Toolium is a Python wrapper tool of Selenium, Playwright and Appium libraries to project. It provides a way of choosing and configuring the driver through a configuration file, implements a Page Object pattern and includes a simple visual testing solution. -.. |Build Status| image:: https://github.com/Telefonica/toolium/workflows/build/badge.svg?branch=master +.. |Build Status| image:: https://github.com/Telefonica/toolium/actions/workflows/ci.yml/badge.svg?branch=master :target: https://github.com/Telefonica/toolium/actions?query=branch%3Amaster .. |Documentation Status| image:: https://readthedocs.org/projects/toolium/badge/?version=latest :target: http://toolium.readthedocs.org/en/latest @@ -100,7 +100,7 @@ Main Features - `Choosing a driver through a configuration file `_ - `Page Object pattern `_ -- `BDD integration `_ +- `Tests runners integration `_ - `Visual testing solution `_ - `Tests result analysis `_ diff --git a/docs/index.rst b/docs/index.rst index 01f250b5..f1feff01 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -11,7 +11,7 @@ Main Features - :ref:`Choosing driver through a configuration file ` - :ref:`Page Object pattern ` -- :ref:`BDD integration ` +- :ref:`Tests runners integration ` - :ref:`AI utils ` - :ref:`Visual testing solution ` - :ref:`Tests result analysis ` @@ -24,7 +24,7 @@ Library Reference driver_configuration.rst page_objects.rst - bdd_integration.rst + tests_runners_integration.rst ai_utils.rst visual_testing.rst tests_result_analysis.rst @@ -40,4 +40,4 @@ Indices and Tables * :ref:`genindex` * :ref:`modindex` -* :ref:`search` \ No newline at end of file +* :ref:`search` diff --git a/docs/bdd_integration.rst b/docs/tests_runners_integration.rst similarity index 81% rename from docs/bdd_integration.rst rename to docs/tests_runners_integration.rst index 6fa53526..56ca4862 100644 --- a/docs/bdd_integration.rst +++ b/docs/tests_runners_integration.rst @@ -1,10 +1,10 @@ -.. _bdd_integration: +.. _tests_runners_integration: -BDD Integration -=============== +Tests runners integration +========================= -Behave -~~~~~~ +Behave (BDD) +~~~~~~~~~~~~ Behave tests should be developed as usual, only *environment.py* file should be modified to initialize driver and the rest of Toolium configuration. @@ -260,3 +260,72 @@ returns the value of 'reference' * mode with value offline will try to get a local copy of POEditor terms from output directory, online mode (by default if not provided) will download always terms from POEditor * file_path contains relative path of downloaded POEditor terms file (default value: _output/poeditor_terms.json) + +Nose2 / unittest +~~~~~~~~~~~~~~~~ + +To use Toolium with nose2 or unittest, you only need to extend from one of the base test case classes provided by Toolium: + +- `BasicTestCase` for API tests +- `SeleniumTestCase` for Selenium tests +- `AppiumTestCase` for Appium tests + +These classes already implement the setup and teardown logic to initialize and close the driver automatically. + +Example: + +.. code-block:: python + + from toolium.test_cases import SeleniumTestCase + from web_nose2.pageobjects.login import LoginPageObject + + class LoginTest(SeleniumTestCase): + def test_successful_login(self): + user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'} + secure_area = LoginPageObject().open().login(user) + self.assertIn('You logged into a secure area!', secure_area.message.get_message()) + +You can see a complete example of nose2 integration with Toolium in `toolium-examples repository `_. + +Pytest +~~~~~~ + +To run tests with pytest using Toolium, simply import Toolium's fixtures in your `conftest.py` file: + +.. code-block:: python + + from toolium.pytest_fixtures import * + +This will automatically initialize the driver before each test, module, or session, and close it automatically after +the test execution, according to your configuration. + +Example: + +.. code-block:: python + + from web_nose2.pageobjects.login import LoginPageObject + + def test_successful_login(): + user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'} + secure_area = LoginPageObject().open().login(user) + assert 'You logged into a secure area!' in secure_area.message.get_message() + +You can see a complete example of pytest integration with Toolium in `toolium-examples repository `_. + +Pytest also allows to run tests that extend from a ``unittest.TestCase`` class. In this case, it is recommended to +extend directly from ``unittest.TestCase``, not from Toolium's test case classes. In this scenario, the driver will be +initialized using the Toolium fixtures (as shown above), not with setUp and tearDown methods. This ensures proper driver +management and compatibility with pytest's fixture system. + +Example: + +.. code-block:: python + + import unittest + from web_nose2.pageobjects.login import LoginPageObject + + class LoginTest(unittest.TestCase): + def test_successful_login(self): + user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'} + secure_area = LoginPageObject().open().login(user) + self.assertIn('You logged into a secure area!', secure_area.message.get_message()) diff --git a/pyproject.toml b/pyproject.toml index 5656beb8..d7f4f657 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -87,10 +87,7 @@ addopts = "-v --tb=short" [tool.coverage.run] source = ["toolium"] omit = [ - "*/test*", - "*/tests/*", - "*/venv/*", - "*/.venv/*", + "*/test/*" ] [tool.coverage.report]