Skip to content

Commit a4e5dab

Browse files
[8.x] [Scout] add maps test (#204607) (#211350)
# Backport This will backport the following commits from `main` to `8.x`: - [[Scout] add maps test (#204607)](#204607) <!--- Backport version: 9.6.4 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Tre","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-01-30T11:55:35Z","message":"[Scout] add maps test (#204607)\n\n## Summary\r\n\r\nAdd MapsPage to the scout core to be re-used by others.\r\nAdd rudimentary docs to show how to run these tests.\r\nAdded a `waitForRender` method.\r\nAdd test id.\r\n\r\n---------\r\n\r\nCo-authored-by: Robert Oskamp <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"ce1904533d46e3b1e02d0d177fe4503ad0e495df","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","backport:version","test:scout","v9.1.0","v8.19.0"],"title":"[Scout] add maps test","number":204607,"url":"https://github.com/elastic/kibana/pull/204607","mergeCommit":{"message":"[Scout] add maps test (#204607)\n\n## Summary\r\n\r\nAdd MapsPage to the scout core to be re-used by others.\r\nAdd rudimentary docs to show how to run these tests.\r\nAdded a `waitForRender` method.\r\nAdd test id.\r\n\r\n---------\r\n\r\nCo-authored-by: Robert Oskamp <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"ce1904533d46e3b1e02d0d177fe4503ad0e495df"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/204607","number":204607,"mergeCommit":{"message":"[Scout] add maps test (#204607)\n\n## Summary\r\n\r\nAdd MapsPage to the scout core to be re-used by others.\r\nAdd rudimentary docs to show how to run these tests.\r\nAdded a `waitForRender` method.\r\nAdd test id.\r\n\r\n---------\r\n\r\nCo-authored-by: Robert Oskamp <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Nick Partridge <[email protected]>\r\nCo-authored-by: Elastic Machine <[email protected]>\r\nCo-authored-by: Dzmitry Lemechko <[email protected]>","sha":"ce1904533d46e3b1e02d0d177fe4503ad0e495df"}},{"branch":"9.1","label":"v9.1.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Tre <[email protected]>
1 parent 66ee361 commit a4e5dab

File tree

13 files changed

+179
-7
lines changed

13 files changed

+179
-7
lines changed

.buildkite/scripts/steps/functional/scout_ui_tests.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ run_tests() {
2424

2525
EXIT_CODE=0
2626

27-
# Discovery Enhanced
27+
# Discovery Enhanced && Maps
2828
for run_mode in "--stateful"; do
2929
run_tests "Discovery Enhanced: Parallel Workers" "x-pack/platform/plugins/private/discover_enhanced/ui_tests/parallel.playwright.config.ts" "$run_mode"
3030
run_tests "Discovery Enhanced" "x-pack/platform/plugins/private/discover_enhanced/ui_tests/playwright.config.ts" "$run_mode"
31+
run_tests "Maps" "x-pack/platform/plugins/shared/maps/ui_tests/playwright.config.ts" "$run_mode"
3132
done
3233

3334
exit $EXIT_CODE

packages/kbn-scout/src/playwright/config/create_config.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe('createPlaywrightConfig', () => {
5050
serversConfigDir: SCOUT_SERVERS_ROOT,
5151
[VALID_CONFIG_MARKER]: true,
5252
screenshot: 'only-on-failure',
53+
testIdAttribute: 'data-test-subj',
5354
trace: 'on-first-retry',
5455
});
5556
expect(config.globalSetup).toBeUndefined();

packages/kbn-scout/src/playwright/config/create_config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export function createPlaywrightConfig(options: ScoutPlaywrightOptions): Playwri
4747
],
4848
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
4949
use: {
50+
testIdAttribute: 'data-test-subj',
5051
serversConfigDir: SCOUT_SERVERS_ROOT,
5152
[VALID_CONFIG_MARKER]: true,
5253
/* Base URL to use in actions like `await page.goto('/')`. */

packages/kbn-scout/src/playwright/page_objects/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,17 @@ import { DashboardApp } from './dashboard_app';
1212
import { DatePicker } from './date_picker';
1313
import { DiscoverApp } from './discover_app';
1414
import { FilterBar } from './fiter_bar';
15+
import { MapsPage } from './maps_page';
16+
import { RenderablePage } from './renderable_page';
1517
import { createLazyPageObject } from './utils';
1618

1719
export interface PageObjects {
1820
datePicker: DatePicker;
1921
discover: DiscoverApp;
2022
dashboard: DashboardApp;
2123
filterBar: FilterBar;
24+
maps: MapsPage;
25+
renderable: RenderablePage;
2226
}
2327

2428
/**
@@ -33,6 +37,8 @@ export function createCorePageObjects(page: ScoutPage): PageObjects {
3337
dashboard: createLazyPageObject(DashboardApp, page),
3438
discover: createLazyPageObject(DiscoverApp, page),
3539
filterBar: createLazyPageObject(FilterBar, page),
40+
maps: createLazyPageObject(MapsPage, page),
41+
renderable: createLazyPageObject(RenderablePage, page),
3642
// Add new page objects here
3743
};
3844
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { ScoutPage } from '..';
11+
12+
export class MapsPage {
13+
constructor(private readonly page: ScoutPage) {}
14+
15+
async gotoNewMap() {
16+
await this.page.gotoApp('maps/map');
17+
}
18+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the "Elastic License
4+
* 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side
5+
* Public License v 1"; you may not use this file except in compliance with, at
6+
* your election, the "Elastic License 2.0", the "GNU Affero General Public
7+
* License v3.0 only", or the "Server Side Public License, v 1".
8+
*/
9+
10+
import { ScoutPage, expect } from '..';
11+
12+
export class RenderablePage {
13+
constructor(private readonly page: ScoutPage) {}
14+
15+
async waitForRender(count: number = 1): Promise<void> {
16+
await expect(async () => await renderWait(count, this.page)).toPass({
17+
timeout: 10_000,
18+
});
19+
}
20+
}
21+
22+
const RENDER_COMPLETE_SELECTOR = '[data-render-complete="true"]';
23+
const RENDER_COMPLETE_PENDING_SELECTOR = '[data-render-complete="false"]';
24+
const DATA_LOADING_SELECTOR = '[data-loading]';
25+
26+
async function renderWait(count: number, page: ScoutPage) {
27+
const renderCompleteLocator = page.locator(RENDER_COMPLETE_SELECTOR);
28+
const renderPendingDataTitleLocator = page
29+
.locator(RENDER_COMPLETE_PENDING_SELECTOR)
30+
.and(page.locator('data-title'));
31+
const loadingLocator = page.locator(DATA_LOADING_SELECTOR);
32+
33+
await renderCompleteLocator.waitFor({ timeout: 1000 });
34+
const completedElementsCount = await renderCompleteLocator.count();
35+
36+
if (completedElementsCount < count)
37+
throw new Error(
38+
`${completedElementsCount} elements completed rendering, still waiting on a total of ${count} - ${await renderPendingDataTitleLocator.all()}`
39+
);
40+
41+
const loadingCount = await loadingLocator.count();
42+
if (loadingCount > 0) throw new Error(`${loadingCount} elements still loading contents`);
43+
}

packages/kbn-scout/src/playwright/page_objects/utils/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import { ScoutPage } from '../../fixtures';
1515
* in certain test scenarios.
1616
*
1717
* @param PageObjectClass - The page object class to be instantiated lazily.
18-
* @param scoutPage - ScoutPage instance, that extendes the Playwright `page` fixture and passed to the page object class constructor.
18+
* @param scoutPage - ScoutPage instance, that extends the Playwright `page` fixture and passed to the page object class constructor.
1919
* @param constructorArgs - Additional arguments to be passed to the page object class constructor.
2020
* @returns A proxy object that behaves like an instance of the page object class, instantiating it on demand.
2121
*/
22-
export function createLazyPageObject<T extends object>(
23-
PageObjectClass: new (page: ScoutPage, ...args: any[]) => T,
22+
export function createLazyPageObject<T extends object, Args extends any[]>(
23+
PageObjectClass: new (page: ScoutPage, ...args: Args) => T,
2424
scoutPage: ScoutPage,
25-
...constructorArgs: any[]
25+
...constructorArgs: Args
2626
): T {
2727
let instance: T | null = null;
2828
return new Proxy({} as T, {

packages/kbn-scout/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"@kbn/mock-idp-utils",
2828
"@kbn/test-subj-selector",
2929
"@kbn/scout-info",
30-
"@kbn/scout-reporting"
30+
"@kbn/scout-reporting",
3131
]
3232
}

x-pack/platform/plugins/shared/maps/tsconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"public/**/*",
1010
"server/**/*",
1111
"server/config.ts",
12-
"../../../../../typings/**/*"
12+
"../../../../../typings/**/*",
13+
"ui_tests/**/*",
1314
],
1415
"kbn_references": [
1516
"@kbn/core",
@@ -92,6 +93,7 @@
9293
"@kbn/field-utils",
9394
"@kbn/react-hooks",
9495
"@kbn/react-kibana-mount",
96+
"@kbn/scout",
9597
],
9698
"exclude": [
9799
"target/**/*",
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
## How to run tests
2+
3+
You can drop the following in your terminal.
4+
5+
```bash
6+
run_tests() {
7+
local suit_name=$1
8+
local config_path=$2
9+
local run_mode=$3
10+
11+
echo "--- $suit_name ($run_mode) UI Tests"
12+
if ! node scripts/scout run-tests "$run_mode" --config "$config_path"; then
13+
echo "$suit_name: failed"
14+
else
15+
echo "$suit_name: passed"
16+
fi
17+
}
18+
19+
for run_mode in "--stateful" "--serverless=es" "--serverless=oblt" "--serverless=security"; do
20+
run_tests "Maps" "x-pack/platform/plugins/shared/maps/ui_tests/playwright.config.ts" "$run_mode"
21+
done
22+
```

0 commit comments

Comments
 (0)