Skip to content

Commit 8e46b10

Browse files
committed
fix: upgrade readthedocs and add pytest/unittest doc
1 parent eb9b668 commit 8e46b10

7 files changed

Lines changed: 86 additions & 19 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ jobs:
5959
needs: tests
6060
runs-on: ubuntu-latest
6161
steps:
62-
- name: Set up python 3.10
62+
- name: Set up python 3.13
6363
uses: actions/setup-python@v6
6464
with:
65-
python-version: '3.10'
65+
python-version: '3.13'
6666
- name: Install dependencies
6767
run: |
6868
python -m pip install --upgrade pip

.readthedocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ version: 2
66

77
# Set the version of Python and other tools you might need
88
build:
9-
os: ubuntu-20.04
9+
os: ubuntu-24.04
1010
tools:
11-
python: "3.10"
11+
python: "3.13"
1212

1313
# Build documentation in the docs/ directory with Sphinx
1414
sphinx:

CHANGELOG.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ v3.8.1
77
*Release date: In development*
88

99
- Add token usage tracking to OpenAI requests
10+
- Add pytest and unittest runners documentation in `Docs <http://toolium.readthedocs.io/en/latest/tests_runners_integration.html>`_
1011

1112
v3.8.0
1213
------
@@ -596,7 +597,7 @@ v1.3.0
596597

597598
*Release date: 2017-09-12*
598599

599-
- Add Behave dynamic environment (more info in `Docs <http://toolium.readthedocs.io/en/latest/bdd_integration.html#behave-dynamic-environment>`_)
600+
- Add Behave dynamic environment (more info in `Docs <http://toolium.readthedocs.io/en/latest/tests_runners_integration.html#behave-dynamic-environment>`_)
600601
- Fix visual screenshot filename error when behave feature name contains :
601602
- Add a config property 'explicitly_wait' in [Driver] section to set the default timeout used in *wait_until* methods
602603
- When reuse_driver is true using behave, driver is initialized in *before_feature* method and closed in *after_feature*

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Toolium is a Python wrapper tool of Selenium, Playwright and Appium libraries to
77
project. It provides a way of choosing and configuring the driver through a configuration file, implements a Page Object
88
pattern and includes a simple visual testing solution.
99

10-
.. |Build Status| image:: https://github.com/Telefonica/toolium/workflows/build/badge.svg?branch=master
10+
.. |Build Status| image:: https://github.com/Telefonica/toolium/actions/workflows/ci.yml/badge.svg?branch=master
1111
:target: https://github.com/Telefonica/toolium/actions?query=branch%3Amaster
1212
.. |Documentation Status| image:: https://readthedocs.org/projects/toolium/badge/?version=latest
1313
:target: http://toolium.readthedocs.org/en/latest
@@ -100,7 +100,7 @@ Main Features
100100

101101
- `Choosing a driver through a configuration file </docs/driver_configuration.rst>`_
102102
- `Page Object pattern </docs/page_objects.rst>`_
103-
- `BDD integration </docs/bdd_integration.rst>`_
103+
- `Tests runners integration </docs/tests_runners_integration.rst>`_
104104
- `Visual testing solution </docs/visual_testing.rst>`_
105105
- `Tests result analysis </docs/tests_result_analysis.rst>`_
106106

docs/index.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Main Features
1111

1212
- :ref:`Choosing driver through a configuration file <driver_configuration>`
1313
- :ref:`Page Object pattern <page_objects>`
14-
- :ref:`BDD integration <bdd_integration>`
14+
- :ref:`Tests runners integration <tests_runners_integration>`
1515
- :ref:`AI utils <ai_utilities>`
1616
- :ref:`Visual testing solution <visual_testing>`
1717
- :ref:`Tests result analysis <tests_result_analysis>`
@@ -24,7 +24,7 @@ Library Reference
2424

2525
driver_configuration.rst
2626
page_objects.rst
27-
bdd_integration.rst
27+
tests_runners_integration.rst
2828
ai_utils.rst
2929
visual_testing.rst
3030
tests_result_analysis.rst
@@ -40,4 +40,4 @@ Indices and Tables
4040

4141
* :ref:`genindex`
4242
* :ref:`modindex`
43-
* :ref:`search`
43+
* :ref:`search`
Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
.. _bdd_integration:
1+
.. _tests_runners_integration:
22

3-
BDD Integration
4-
===============
3+
Tests runners integration
4+
=========================
55

6-
Behave
7-
~~~~~~
6+
Behave (BDD)
7+
~~~~~~~~~~~~
88

99
Behave tests should be developed as usual, only *environment.py* file should be modified to initialize driver and the
1010
rest of Toolium configuration.
@@ -260,3 +260,72 @@ returns the value of 'reference'
260260
* 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
261261

262262
* file_path contains relative path of downloaded POEditor terms file (default value: _output/poeditor_terms.json)
263+
264+
Nose2 / unittest
265+
~~~~~~~~~~~~~~~~
266+
267+
To use Toolium with nose2 or unittest, you only need to extend from one of the base test case classes provided by Toolium:
268+
269+
- `BasicTestCase` for API tests
270+
- `SeleniumTestCase` for Selenium tests
271+
- `AppiumTestCase` for Appium tests
272+
273+
These classes already implement the setup and teardown logic to initialize and close the driver automatically.
274+
275+
Example:
276+
277+
.. code-block:: python
278+
279+
from toolium.test_cases import SeleniumTestCase
280+
from web_nose2.pageobjects.login import LoginPageObject
281+
282+
class LoginTest(SeleniumTestCase):
283+
def test_successful_login(self):
284+
user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'}
285+
secure_area = LoginPageObject().open().login(user)
286+
self.assertIn('You logged into a secure area!', secure_area.message.get_message())
287+
288+
You can see a complete example of nose2 integration with Toolium in `toolium-examples repository <https://github.com/Telefonica/toolium-examples/tree/master/web_nose2>`_.
289+
290+
Pytest
291+
~~~~~~
292+
293+
To run tests with pytest using Toolium, simply import Toolium's fixtures in your `conftest.py` file:
294+
295+
.. code-block:: python
296+
297+
from toolium.pytest_fixtures import *
298+
299+
This will automatically initialize the driver before each test, module, or session, and close it automatically after
300+
the test execution, according to your configuration.
301+
302+
Example:
303+
304+
.. code-block:: python
305+
306+
from web_nose2.pageobjects.login import LoginPageObject
307+
308+
def test_successful_login():
309+
user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'}
310+
secure_area = LoginPageObject().open().login(user)
311+
assert 'You logged into a secure area!' in secure_area.message.get_message()
312+
313+
You can see a complete example of pytest integration with Toolium in `toolium-examples repository <https://github.com/Telefonica/toolium-examples/tree/master/web_pytest>`_.
314+
315+
Pytest also allows to run tests that extend from a ``unittest.TestCase`` class. In this case, it is recommended to
316+
extend directly from ``unittest.TestCase``, not from Toolium's test case classes. In this scenario, the driver will be
317+
initialized using the Toolium fixtures (as shown above), not with setUp and tearDown methods. This ensures proper driver
318+
management and compatibility with pytest's fixture system.
319+
320+
Example:
321+
322+
.. code-block:: python
323+
324+
import unittest
325+
from web_nose2.pageobjects.login import LoginPageObject
326+
327+
class LoginTest(unittest.TestCase):
328+
def test_successful_login(self):
329+
user = {'username': 'tomsmith', 'password': 'SuperSecretPassword!'}
330+
secure_area = LoginPageObject().open().login(user)
331+
self.assertIn('You logged into a secure area!', secure_area.message.get_message())

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,7 @@ addopts = "-v --tb=short"
8787
[tool.coverage.run]
8888
source = ["toolium"]
8989
omit = [
90-
"*/test*",
91-
"*/tests/*",
92-
"*/venv/*",
93-
"*/.venv/*",
90+
"*/test/*"
9491
]
9592

9693
[tool.coverage.report]

0 commit comments

Comments
 (0)