Skip to content

Commit c381b52

Browse files
authored
Merge pull request #353 from seleniumbase/sb-fixture
Add the "sb" pytest fixture
2 parents d6fc08c + c8a2b4b commit c381b52

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

examples/test_sb_fixture.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
# "sb" pytest fixture test in a method with no class
4+
def test_sb_fixture_with_no_class(sb):
5+
sb.open("https://google.com/ncr")
6+
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
7+
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
8+
sb.click('a[title="seleniumbase"]')
9+
10+
11+
# "sb" pytest fixture test in a method inside a class
12+
class Test_SB_Fixture():
13+
def test_sb_fixture_inside_class(self, sb):
14+
sb.open("https://google.com/ncr")
15+
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
16+
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
17+
sb.click('a[title="examples"]')

examples/test_usefixtures.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import pytest
2+
3+
4+
@pytest.mark.usefixtures("sb")
5+
class Test_UseFixtures():
6+
def test_usefixtures_on_class(self):
7+
sb = self.sb
8+
sb.open("https://google.com/ncr")
9+
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
10+
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
11+
sb.assert_text("SeleniumBase", "h1.public")
12+
sb.assert_text("integrations")
13+
sb.assert_element('a[title="help_docs"]')
14+
sb.click('a[title="examples"]')

seleniumbase/plugins/pytest_plugin.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,26 @@ def pytest_runtest_teardown(item):
384384
pass
385385

386386

387+
@pytest.fixture()
388+
def sb(request):
389+
from seleniumbase import BaseCase
390+
391+
class BaseClass(BaseCase):
392+
def base_method():
393+
pass
394+
395+
if request.cls:
396+
request.cls.sb = BaseClass("base_method")
397+
request.cls.sb.setUp()
398+
yield request.cls.sb
399+
request.cls.sb.tearDown()
400+
else:
401+
sb = BaseClass("base_method")
402+
sb.setUp()
403+
yield sb
404+
sb.tearDown()
405+
406+
387407
@pytest.mark.hookwrapper
388408
def pytest_runtest_makereport(item, call):
389409
pytest_html = item.config.pluginmanager.getplugin('html')

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
setup(
1919
name='seleniumbase',
20-
version='1.26.4',
20+
version='1.27.0',
2121
description='Fast, Easy, and Reliable Browser Automation & Testing.',
2222
long_description=long_description,
2323
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)