Global Setup and Teardown | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
This lesson covers the concept of global setup and global teardown in the Playwright framework . These processes allow you to execute code before the framework initializes and after all tests have run, respectively. Key Concepts Global Setup: Used to run code that is not part of the Playwright framework, such as seeding a database or notifying third-party systems. Global Teardown: Executes code after all tests have completed, which can be useful for cleanup tasks. Implementation Steps Create two TypeScript files in the project root: global setup.ts global teardown.ts Define the globalSetup function in global setup.ts : async function globalSetup() { console.log("I am a global setup process"); } export default globalSetup; Define the globalTeardown function in global teardown.ts : async function globalTeardown() { console.log("I am a global teardown process"); } export default globalTeardown; Configure these functions in the Playwright configuration file: globalSetup: require.resolve('./global setup.ts'), globalTeardown: require.resolve('./global teardown.ts') When you run your tests, the global setup will execute first, followed by the tests, and finally the global teardown. Note that debugging issues in these functions can be challenging, as errors may not appear in the Playwright report. In summary, while global setup and teardown can be useful, they should be used judiciously due to potential debugging difficulties.