-
Hi everyone, First of all, many thanks for this awesome automation library! I've done some research, but I failed to find something that would fit our needs: I’m currently working on a test automation project using SeleniumBase and Pytest, and I’ve encountered a challenge with fixture scopes. SeleniumBase’s sb fixture is limited to function scope, but I need to perform setup tasks at the class scope to avoid repeating the same initialization for every test in the class. Here’s the scenario: I want to prepare some shared data or environment setup (using SeleniumBase) once per test class. Each test in the class should still access the sb fixture individually. Since the sb fixture is restricted to function scope, I’m struggling to integrate it within a class-scoped setup fixture. Has anyone faced this limitation before? How did you handle this? Some additional information: Our automation architecture relies heavily on the sb fixture, which we use throughout our Page and Component objects. We’ve created a CustomBaseCase class that extends the BaseCase class, and we’ve overridden the sb fixture in a global conftest.py. This custom fixture instantiates the CustomBaseCase and ensures that the setUp() method is called as needed. We took this approach because we needed to implement various custom methods and features to better fit our testing requirements. Thanks in advance for your insights! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can override the sb class fixture in order to accomplish that. (One of the 25 Syntax Formats) Eg. SeleniumBase/examples/test_override_sb_fixture.py That basically lets you do anything that's allowable by Note that overriding the Another option would be If tests are grouped by class (via Also useful are the |
Beta Was this translation helpful? Give feedback.
You can override the sb class fixture in order to accomplish that. (One of the 25 Syntax Formats)
Eg. SeleniumBase/examples/test_override_sb_fixture.py
That basically lets you do anything that's allowable by
pytest
, while still getting access to SeleniumBase'sBaseCase
methods.Note that overriding the
sb
fixture means replacing all default configuration in browser_launcher.py, which means special modes that are configured inbrowser_launcher.py
(such as UC Mode, CDP Mode, etc.) won't be there anymore. Depending on what you're doing, that might not be the best option for you.Another option would be
pytest --dist=loadscope
to group tests by class. (https://stackoverflow.com/a/56475200/705…