|
1 | | -.. _bdd_integration: |
| 1 | +.. _tests_runners_integration: |
2 | 2 |
|
3 | | -BDD Integration |
4 | | -=============== |
| 3 | +Tests runners integration |
| 4 | +========================= |
5 | 5 |
|
6 | | -Behave |
7 | | -~~~~~~ |
| 6 | +Behave (BDD) |
| 7 | +~~~~~~~~~~~~ |
8 | 8 |
|
9 | 9 | Behave tests should be developed as usual, only *environment.py* file should be modified to initialize driver and the |
10 | 10 | rest of Toolium configuration. |
@@ -260,3 +260,72 @@ returns the value of 'reference' |
260 | 260 | * 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 |
261 | 261 |
|
262 | 262 | * 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()) |
0 commit comments