Loading

Global setup hook

Use a global setup hook to run code once before any tests start (even with multiple workers). This is most useful for parallel suites, where you want shared data/setup to exist before workers begin. It is also supported by non-parallel test suites.

Common uses:

  • Load Elasticsearch archives with esArchiver
  • Run one-time API setup with apiServices
  • Apply shared Kibana settings via kbnClient
Note

Scout doesn’t currently have a global teardown hook. Most environments are ephemeral and are shut down after the run.

  1. Turn it on in your config

    Set runGlobalSetup: true in your Playwright config:

    import { createPlaywrightConfig } from '@kbn/scout';
    
    export default createPlaywrightConfig({
      testDir: './parallel_tests',
      workers: 2,
      runGlobalSetup: true,
    });
    		
  2. Create global.setup.ts

    Add global.setup.ts inside the testDir folder. Scout will discover and run it automatically.

    test/scout/ui/
    └── parallel_tests/
        ├── global.setup.ts
        └── some_suite.spec.ts
    		
  3. Write setup code

    Example: load an ES archive once:

    import { globalSetupHook } from '@kbn/scout';
    
    globalSetupHook('Load test data', async ({ esArchiver, log }) => {
      log.info('[setup] loading ES archive (only if needed)...');
      await esArchiver.loadIfNeeded('x-pack/platform/test/fixtures/es_archives/ml/farequote');
    });
    		
    Warning

    The global setup hook only has access to worker-scoped fixtures. It cannot use test-scoped fixtures like page, browserAuth, or pageObjects.

  4. Run tests

    Run tests as usual via Run Scout tests. The global setup hook will execute first—check console logs to verify it ran successfully.