playwright-pytest icon indicating copy to clipboard operation
playwright-pytest copied to clipboard

[FEATURE] Run Browser once in TestClass

Open akozyreva opened this issue 4 years ago • 2 comments

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.

akozyreva avatar Jun 14 '21 15:06 akozyreva

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".

mxschmitt avatar Jul 30 '21 11:07 mxschmitt

I suggest to spawn your own browser based custom_page or something because of its session implementation: Screenshot 2024-02-19 at 23 35 17

storenth avatar Feb 19 '24 16:02 storenth