1

So I am using playwright/test with Typescript

I have a testapp.ts setup which contains all my methods eg for logging in, navigating etc Inside my test example.spec.ts each test looks like this:

  const testapp = new TestApp(page);
  await testapp.methodName();
});

I tried to put the const testapp = new TestApp(page); inside the beforeEach so I don't have to start every test putting in that line, but I get an error:

TypeError: Cannot read properties of undefined (reading 'testName')

jest lets you put the new TestApp(page) inside the beforeEach but not playwright/test

Is there any way to do this? Or Do I have to switch to jest?

Putting it in global-setup is not an option as I don't want to create a new browser page for each test my goal is to do end to end

Open one browser for each test suite and login, and then each test will execute on that session. Currently, it's working that way, except I have to put the new TestApp(page) inside every test

1
  • Did you ever solve this? It should work the same in jest, where you just have to declare the variable outside the beforeEach and test (let testapp), then assign it in beforeEach and can then use in test. Or in Playwright you can use custom fixtures. Commented Feb 12, 2023 at 13:22

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.