Skip to content

[scout] use project deps as global hooks for parallel tests#211409

Merged
dmlemeshko merged 30 commits intoelastic:mainfrom
dmlemeshko:scout/use-project-deps-for-setup-hook
Mar 13, 2025
Merged

[scout] use project deps as global hooks for parallel tests#211409
dmlemeshko merged 30 commits intoelastic:mainfrom
dmlemeshko:scout/use-project-deps-for-setup-hook

Conversation

@dmlemeshko
Copy link
Copy Markdown
Contributor

@dmlemeshko dmlemeshko commented Feb 17, 2025

Summary

Currently we are using globalSetup script in configuration file 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:

config: [
({ log }, use, testInfo) => {
const configName = 'local';
const projectUse = testInfo.project.use as ScoutTestOptions;
const serversConfigDir = projectUse.serversConfigDir;
const configInstance = createScoutConfig(serversConfigDir, configName, log);
use(configInstance);
},
{ scope: 'worker' },
],

testInfo is how Playwright exposes currently running configuration in a form of project interface: 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:

    {
      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);
  }
});
  1. it is supported by VSCode Playwright plugin
Screenshot 2025-02-17 at 11 26 12

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

@dmlemeshko dmlemeshko self-assigned this Feb 18, 2025
@dmlemeshko dmlemeshko added v9.0.0 backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Mar 4, 2025
@dmlemeshko dmlemeshko marked this pull request as ready for review March 4, 2025 17:52
@dmlemeshko dmlemeshko requested review from a team as code owners March 4, 2025 17:52
@dmlemeshko dmlemeshko requested review from dolaru and pheyos March 4, 2025 17:52
```bash
// ESS
npx playwright test --config x-pack/solutions/observability/plugins/observability_onboarding/ui_tests/playwright.config.ts --grep @ess
npx playwright test --config x-pack/solutions/observability/plugins/observability_onboarding/ui_tests/playwright.config.ts --project=local --grep @ess
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For MKI run we will need just to generate json and update --project flag

Copy link
Copy Markdown
Contributor

@dolaru dolaru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implementation LGTM 👍🏽

The only thing I'm not a fan of is the clash in terminology with the word project. That could easily be confused with a serverless project.

A couple of options to make this better would be:

  • increase the specificity of the term to make it clear this is for Playwright (e.g. pw-project / pwProject)
  • change the term used to something like target/testTarget to eliminate ambiguity

@dmlemeshko
Copy link
Copy Markdown
Contributor Author

dmlemeshko commented Mar 6, 2025

A couple of options to make this better would be:

  • increase the specificity of the term to make it clear this is for Playwright (e.g. pw-project / pwProject)
  • change the term used to something like target/testTarget to eliminate ambiguity

@dolaru I agree, it is confusing. Sadly we can only change it for scripts/scout, if we merge it running tests directly with playwright will require smth like

npx playwright test --config path/to/config --project local --grep=@svlSearch

Still if we agree on unified project names, it will be less confusing:

- local
- cloud-mki
- cloud-ech

for each of the defined projects there should be a corresponding json file, ideally same name cloud-mki.json where consumer puts hosts/credentials.

Some consumers might say "I want to run test agaist both Search and Oblt serverless projects without changing json back and forth": should we then have smth like

- local
- cloud-mki-es
- cloud-mki-oblt
- cloud-mki-security
- cloud-ech

for platform and limit it to just 3 options within Playwright config when it is in specific solution?

As for node scripts/scout run-tests I agree with you on target / testTarget, that would be pretty clear

Copy link
Copy Markdown
Contributor

@mykolaharmash mykolaharmash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Onboarding changes LGTM, thank you!

@dmlemeshko dmlemeshko added the release_note:skip Skip the PR/issue when compiling release notes label Mar 7, 2025
const scoutProjects: PlaywrightTestConfig<ScoutTestOptions>['projects'] = [
{
name: 'local',
use: { ...devices['Desktop Chrome'], configName: 'local' },
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each project will override default configName to pass source of servers configuration ('local.json', 'cloud-mki', 'cloud-ech', etc)

@jennypavlova jennypavlova self-requested a review March 12, 2025 15:54
Copy link
Copy Markdown
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sharing the error I am getting when running the apm UI tests also here for visibility:

image

Comment on lines +20 to +23
await test.step('shows correct heading', async () => {
expect(page.url()).toContain('/app/apm/services');
await expect(page.getByRole('heading', { name: 'Services', level: 1 })).toBeVisible();
});
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@dmlemeshko
Copy link
Copy Markdown
Contributor Author

Verified locally:

node scripts/scout run-tests --config x-pack/solutions/observability/plugins/apm/ui_tests/parallel.playwright.config.ts --stateful
node scripts/scout start-server --serverless=oblt
npx playwright test --config x-pack/solutions/observability/plugins/apm/ui_tests/parallel.playwright.config.ts --project local --grep @svlOblt

Copy link
Copy Markdown
Member

@jennypavlova jennypavlova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 💯
✅ The APM UI tests are now passing locally using
node scripts/scout.js start-server --stateful
and
npx playwright test --config x-pack/solutions/observability/plugins/apm/ui_tests/parallel.playwright.config.ts --project=local --grep @ess

Thank you for all the fixes!

@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
apm 66 65 -1
discoverEnhanced 3 2 -1
total -2

Total ESLint disabled count

id before after diff
apm 79 78 -1
discoverEnhanced 3 2 -1
total -2

History

cc @dmlemeshko

@dmlemeshko dmlemeshko merged commit 1b30686 into elastic:main Mar 13, 2025
10 checks passed
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.x, 9.0

https://github.com/elastic/kibana/actions/runs/13830858430

@kibanamachine
Copy link
Copy Markdown
Contributor

💔 All backports failed

Status Branch Result
8.x Backport failed because of merge conflicts
9.0 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 211409

Questions ?

Please refer to the Backport tool documentation

@dmlemeshko
Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

dmlemeshko added a commit to dmlemeshko/kibana that referenced this pull request Mar 14, 2025
…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:
#	x-pack/platform/plugins/shared/triggers_actions_ui/public/application/sections/field_browser/index.ts
#	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/solutions/observability/plugins/apm/ui_tests/tsconfig.json
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 17, 2025
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

1 similar comment
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync.

dmlemeshko added a commit that referenced this pull request Mar 18, 2025
…11409) (#214645)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[scout] use project deps as global hooks for parallel tests
(#211409)](#211409)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Dzmitry
Lemechko","email":"dzmitry.lemechko@elastic.co"},"sourceCommit":{"committedDate":"2025-03-13T09:06:26Z","message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:obs-ux-infra_services","backport:version","test:scout","v9.1.0","v8.19.0"],"title":"[scout]
use project deps as global hooks for parallel
tests","number":211409,"url":"https://github.com/elastic/kibana/pull/211409","mergeCommit":{"message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164"}},"sourceBranch":"main","suggestedTargetBranches":["9.0","8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211409","number":211409,"mergeCommit":{"message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
@kibanamachine kibanamachine removed the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 18, 2025
dmlemeshko added a commit to dmlemeshko/kibana that referenced this pull request Mar 18, 2025
…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
Copy link
Copy Markdown
Contributor Author

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

dmlemeshko added a commit that referenced this pull request Mar 19, 2025
…11409) (#215066)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[scout] use project deps as global hooks for parallel tests
(#211409)](#211409)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Dzmitry
Lemechko","email":"dzmitry.lemechko@elastic.co"},"sourceCommit":{"committedDate":"2025-03-13T09:06:26Z","message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164","branchLabelMapping":{"^v9.1.0$":"main","^v8.19.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:obs-ux-infra_services","backport:version","test:scout","v9.1.0","v8.19.0"],"title":"[scout]
use project deps as global hooks for parallel
tests","number":211409,"url":"https://github.com/elastic/kibana/pull/211409","mergeCommit":{"message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"9.0","label":"v9.0.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/214645","number":214645,"state":"MERGED","mergeCommit":{"sha":"1101afbf997857637543419abb56415e41c2edec","message":"[9.0]
[scout] use project deps as global hooks for parallel tests (#211409)
(#214645)\n\n# Backport\n\nThis will backport the following commits from
`main` to `9.0`:\n- [[scout] use project deps as global hooks for
parallel
tests\n(#211409)](https://github.com/elastic/kibana/pull/211409)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n"}},{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/211409","number":211409,"mergeCommit":{"message":"[scout]
use project deps as global hooks for parallel tests (#211409)\n\n##
Summary\n\nCurrently we are using `globalSetup` [script in
configuration\nfile](https://playwright.dev/docs/test-global-setup-teardown#option-2-configure-globalsetup-and-globalteardown)\nto
ingest Elasticsearch data before running the tests in parallel\nagainst
the same ES/Kibana instances.\n\nThis approach doesn't work well when
you need to adjust `globalSetup`\nlogic based on specific condition,
e.g. configuration file defining\nwhere servers are hosted, its
credentials, etc.\n\nNot only global hook, but `ScoutConfig` fixture
expects an argument to\ndefine where servers configuration is
defined:\n\n\nhttps://github.com/elastic/kibana/blob/cd502acea12979979497f62897be663044ade3aa/packages/kbn-scout/src/playwright/fixtures/worker/core_fixtures.ts#L65-L75\n\n`testInfo`
is how Playwright exposes currently running configuration in\na form of
`project`
interface:\n[projects](https://playwright.dev/docs/test-projects) can be
used to\ngroup tests, e.g. for specific envs or
browsers.\n\nUnfortunately `testInfo` is not exposed in global scripts,
because in\nPlaywright project design `globalSetup` scripts are run
before multiple\nprojects and projects can have its own `setup` hooks
via\n[dependencies](https://playwright.dev/docs/test-global-setup-teardown#option-1-project-dependencies):\n\n```\n
{\n name: 'setup',\n testMatch: /global.setup\\.ts/,\n },\n {\n name:
'local',\n use: { ...devices['Desktop Chrome'], configName: 'local' },\n
dependencies: 'setup',\n },\n``` \n\nWe already use project API to get
`serversConfigDir` path, where we plan\nto store local and cloud server
configurations. This PR proposes to\ndefine projects as `local` and
`cloud` (maybe even separate `cloud-mki`,\n`cloud-ech`) as a way to
provide playwright information about
servers\nconfiguration.\n\nAdvantages:\n1. we can re-use existing
fixtures as-is, without adding custom exported\nhelper functions for ES
data ingestion\n2. project dependency is displayed as `setup` in
Playwright report\n3. way better and simpler design for
consumers:\n```\nimport { globalSetupHook } from
'@kbn/scout';\n\nglobalSetupHook('Ingest data to Elasticsearch', async
({ esArchiver, log }) => {\n // add archives to load, if needed\n const
archives = [\n testData.ES_ARCHIVES.LOGSTASH,\n ];\n\n
log.debug('[setup] loading test data (only if indexes do not
exist)...');\n for (const archive of archives) {\n await
esArchiver.loadIfNeeded(archive);\n }\n});\n```\n4. it is supported by
VSCode Playwright plugin\n<img width=\"1271\" alt=\"Screenshot
2025-02-17 at 11 26
12\"\nsrc=\"https://github.com/user-attachments/assets/ba7eeb38-d39d-4785-9c11-18647599ec4a\"\n/>\n\nI
find it extremely useful because you don't need to change env var
when\nyou want to switch b/w local or cloud run, all the configurations
are\nloaded automatically and you just tick the
checkbox!\n\nDisadvantages:\n1. it is important to run `playwright test`
with `--project` flag to use\nthe proper configuration\n2. we have to
define how `projects` are used for local and cloud\nconfiguration, and
make sure it meets requirements of multiple teams. We\ncan expose a way
to pass custom project definitions in\n`createPlaywrightConfig`
function, but it might complicate the support\neffort when every Team
has too many custom projects.\n3. `project` term is something we can't
change and might be confusing\n4. Since it is a Playwright feature, we
might not have consistency with\nAPI tests runner under Scout\n\nFor
reviewers: \n\nPlaying with it locally might give a better understanding
about the\npros/cons, especially with IDE playwright plugin
installed.\n\nRunning servers with tests:\n```\nnode scripts/scout.js
run-tests --serverless=oblt --testTarget=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnode
scripts/scout.js run-tests --serverless=oblt --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n```\n\nRunning
test only requires passing `project` argument:\n\n```\nnpx playwright
test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts\n\nnpx
playwright test --project=local --config
x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts\n```\n\n---------\n\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>\nCo-authored-by:
jennypavlova
<jennypavlova94@gmail.com>","sha":"1b30686181df5410e92983ede4002ac5f693a164"}},{"branch":"8.x","label":"v8.19.0","branchLabelMappingKey":"^v8.19.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->
CAWilson94 pushed a commit to CAWilson94/kibana that referenced this pull request Mar 22, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:obs-ux-infra_services - DEPRECATED DEPRECATED - Use Team:obs-presentation. test:scout v8.19.0 v9.0.0 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants