Global Setup and Teardown | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Advanced Tricks and Techniques
Instructor: Artem Bondar
Lesson Summary
In this lesson, we discuss how to configure global setup and global teardown in a testing framework. These configurations allow certain code to run before and after the entire test suite executes. Key Concepts Global Setup: Code that runs before any tests, useful for initializing resources. Global Teardown: Code that runs after all tests, useful for cleaning up resources. Project Update We updated a regression project to exclude the likes-counter.spec.ts file, which depends on the article setup. Instead, we created a new spec file, likes-counter-global.spec.ts , that relies on global setup and teardown. Configuration Steps Create a new file for global setup: global-setup.ts . Create a file for global teardown: global-teardown.ts . In playwright-config.ts , add settings for global setup and teardown: global-setup: require.resolve('./global-setup.ts'), global-teardown: require.resolve('./global-teardown.ts') Implement the setup function to create a new article and export it. Implement the teardown function to delete the article and export it. Implementation Details The setup function should handle API requests to create resources, while the teardown function should clean up those resources. Both functions must be exported for visibility. Conclusion By using global setup and teardown, you can ensure that necessary operations are performed for any project or spec file within the framework, enhancing the test execution process.