Skip to content

Add the "sb" pytest fixture #353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions examples/test_sb_fixture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@


# "sb" pytest fixture test in a method with no class
def test_sb_fixture_with_no_class(sb):
sb.open("https://google.com/ncr")
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
sb.click('a[title="seleniumbase"]')


# "sb" pytest fixture test in a method inside a class
class Test_SB_Fixture():
def test_sb_fixture_inside_class(self, sb):
sb.open("https://google.com/ncr")
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
sb.click('a[title="examples"]')
14 changes: 14 additions & 0 deletions examples/test_usefixtures.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import pytest


@pytest.mark.usefixtures("sb")
class Test_UseFixtures():
def test_usefixtures_on_class(self):
sb = self.sb
sb.open("https://google.com/ncr")
sb.update_text('input[title="Search"]', 'SeleniumBase\n')
sb.click('a[href*="github.com/seleniumbase/SeleniumBase"]')
sb.assert_text("SeleniumBase", "h1.public")
sb.assert_text("integrations")
sb.assert_element('a[title="help_docs"]')
sb.click('a[title="examples"]')
20 changes: 20 additions & 0 deletions seleniumbase/plugins/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,26 @@ def pytest_runtest_teardown(item):
pass


@pytest.fixture()
def sb(request):
from seleniumbase import BaseCase

class BaseClass(BaseCase):
def base_method():
pass

if request.cls:
request.cls.sb = BaseClass("base_method")
request.cls.sb.setUp()
yield request.cls.sb
request.cls.sb.tearDown()
else:
sb = BaseClass("base_method")
sb.setUp()
yield sb
sb.tearDown()


@pytest.mark.hookwrapper
def pytest_runtest_makereport(item, call):
pytest_html = item.config.pluginmanager.getplugin('html')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

setup(
name='seleniumbase',
version='1.26.4',
version='1.27.0',
description='Fast, Easy, and Reliable Browser Automation & Testing.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down