Skip to content

[8.x] [scout] use project deps as global hooks for parallel tests (#211409)#215066

Merged
dmlemeshko merged 2 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-211409
Mar 19, 2025
Merged

[8.x] [scout] use project deps as global hooks for parallel tests (#211409)#215066
dmlemeshko merged 2 commits intoelastic:8.xfrom
dmlemeshko:backport/8.x/pr-211409

Conversation

@dmlemeshko
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

…211409)

## Summary

Currently we are using `globalSetup` [script in configuration
file](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)
to ingest Elasticsearch data before running the tests in parallel
against the same ES/Kibana instances.

This approach doesn't work well when you need to adjust `globalSetup`
logic based on specific condition, e.g. configuration file defining
where servers are hosted, its credentials, etc.

Not only global hook, but `ScoutConfig` fixture expects an argument to
define where servers configuration is defined:

https://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75

`testInfo` is how Playwright exposes currently running configuration in
a form of `project` interface:
[projects](https://playwright.dev/docs/test-projects) can be used to
group tests, e.g. for specific envs or browsers.

Unfortunately `testInfo` is not exposed in global scripts, because in
Playwright project design `globalSetup` scripts are run before multiple
projects and projects can have its own `setup` hooks via
[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):

```
    {
      name: 'setup',
      testMatch: /global.setup\.ts/,
    },
    {
      name: 'local',
      use: { ...devices['Desktop Chrome'], configName: 'local' },
      dependencies: 'setup',
    },
```

We already use project API to get `serversConfigDir` path, where we plan
to store local and cloud server configurations. This PR proposes to
define projects as `local` and `cloud` (maybe even separate `cloud-mki`,
`cloud-ech`) as a way to provide playwright information about servers
configuration.

Advantages:
1. we can re-use existing fixtures as-is, without adding custom exported
helper functions for ES data ingestion
2. project dependency is displayed as `setup` in Playwright report
3. way better and simpler design for consumers:
```
import { globalSetupHook } from '@kbn/scout';

globalSetupHook('Ingest data to Elasticsearch', async ({ esArchiver, log }) => {
  // add archives to load, if needed
  const archives = [
    testData.ES_ARCHIVES.LOGSTASH,
  ];

  log.debug('[setup] loading test data (only if indexes do not exist)...');
  for (const archive of archives) {
    await esArchiver.loadIfNeeded(archive);
  }
});
```
4. it is supported by VSCode Playwright plugin
<img width="1271" alt="Screenshot 2025-02-17 at 11 26 12"
src="https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a"
/>

I find it extremely useful because you don't need to change env var when
you want to switch b/w local or cloud run, all the configurations are
loaded automatically and you just tick the checkbox!

Disadvantages:
1. it is important to run `playwright test` with `--project` flag to use
the proper configuration
2. we have to define how `projects` are used for local and cloud
configuration, and make sure it meets requirements of multiple teams. We
can expose a way to pass custom project definitions in
`createPlaywrightConfig` function, but it might complicate the support
effort when every Team has too many custom projects.
3. `project` term is something we can't change and might be confusing
4. Since it is a Playwright feature, we might not have consistency with
API tests runner under Scout

For reviewers:

Playing with it locally might give a better understanding about the
pros/cons, especially with IDE playwright plugin installed.

Running servers with tests:
```
node scripts/scout.js run-tests --serverless=oblt --testTarget=local --config x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts

node scripts/scout.js run-tests --serverless=oblt --config x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts
```

Running test only requires passing `project` argument:

```
npx playwright test --project=local --config x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts

npx playwright test --project=local --config x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: jennypavlova <jennypavlova94@gmail.com>
(cherry picked from commit 1b30686)

# Conflicts:
#	src/platform/test/common/plugins/newsfeed/tsconfig.json
#	x-pack/solutions/observability/plugins/apm/ui_tests/README.md
#	x-pack/solutions/observability/plugins/apm/ui_tests/fixtures/index.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/fixtures/page_objects/service_inventory.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/fixtures/page_objects/service_map.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/fixtures/synthtrace/opbeans.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/parallel_tests/global_setup.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/parallel_tests/service_inventory/service_inventory.spec.ts
#	x-pack/solutions/observability/plugins/apm/ui_tests/parallel_tests/sevice_map/service_map.spec.ts
#	x-pack/test/spaces_api_integration/security_and_spaces/copy_to_space_config_basic.ts
@dmlemeshko dmlemeshko added the backport This PR is a backport of another PR label Mar 18, 2025
@dmlemeshko dmlemeshko enabled auto-merge (squash) March 18, 2025 20:34
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Public APIs missing comments

Total count of every public API that lacks a comment. Target amount is 0. Run node scripts/build_api_docs --plugin [yourplugin] --stats comments for more detailed information.

id before after diff
@kbn/scout 102 97 -5
@kbn/scout-oblt 74 65 -9
total -14
Unknown metric groups

API count

id before after diff
@kbn/scout 393 388 -5
@kbn/scout-oblt 365 356 -9
total -14

ESLint disabled line counts

id before after diff
discoverEnhanced 3 2 -1

Total ESLint disabled count

id before after diff
discoverEnhanced 3 2 -1

History

@dmlemeshko dmlemeshko requested a review from pheyos March 19, 2025 10:59
@dmlemeshko dmlemeshko merged commit 991ce36 into elastic:8.x Mar 19, 2025
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants