playwright-pytest
playwright-pytest copied to clipboard
[FEATURE] Run Browser once in TestClass
Hi! I have the following code:
class TestClass:
def test_a(self, page):
print("open site")
self.page = page
self.page.goto("https://microsoft.com")
def test_b(self, page):
print("check title of site")
self.page = page
page_title = self.page.title()#
assert page_title == "Microsoft - Official Home Page"
The question is - how can I run browser once for 2 tests? Sequence should be the following - browser is starting, test_a is executing, then test_b is executing, then browser is closing.
Currently the test runner is optimised for method based tests: https://docs.pytest.org/en/latest/getting-started.html#create-your-first-test where the best support is given.
We might explore class based testing in the future, will mark it as "p3-collecting-feedback".
I suggest to spawn your own browser based custom_page or something because of its session implementation: