Skip to content

Commit

Permalink
[Canvas] Fix flaky test failures when navigating to Canvas app (#164376)
Browse files Browse the repository at this point in the history
## Summary

Closes #163303.
Closes #163368.
Closes #163903.

This fixes a rarely occurring flaky test failure while navigating to the
Canvas app where the `currentURL` check fails. The cause is
`navigateToApp` goes to `app/canvas#/` which includes a hash get
redirected by the Canvas app to `app/canvas/`, and fails when
`app/canvas/` doesn't match `app/canvas#/`. I've chosen to disable this
check when navigating to Canvas to avoid this flakiness because I
couldn't remove the hash from the URL while using `navigateToApp` or
`navigateToURL`.

Instead of checking the URLs match, I opted to check that the workpad
listing page loaded correctly.

### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)
  • Loading branch information
cqliu1 authored Sep 19, 2023
1 parent dc34810 commit 94587c9
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 50 deletions.
8 changes: 8 additions & 0 deletions test/functional/page_objects/common_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,14 @@ export class CommonPageObject extends FtrService {
} = {}
) {
let appUrl: string;

// See https://github.com/elastic/kibana/pull/164376
if (appName === 'canvas' && !path) {
throw new Error(
'This causes flaky test failures. Use Canvas page object goToListingPage instead'
);
}

if (this.config.has(['apps', appName])) {
// Legacy applications
const appConfig = this.config.get(['apps', appName]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const Home = ({ activeTab = 'workpads' }: Props) => {
{
label: strings.getMyWorkpadsTabLabel(),
id: 'myWorkpads',
'data-test-subj': 'workpadListing',
isSelected: tab === 'workpads',
onClick: () => setTab('workpads'),
},
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/accessibility/apps/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const esArchiver = getService('esArchiver');
const retry = getService('retry');
const { common } = getPageObjects(['common']);
const { canvas } = getPageObjects(['canvas']);

describe('Canvas Accessibility', () => {
before(async () => {
await esArchiver.load('x-pack/test/functional/es_archives/canvas/default');
await common.navigateToApp('canvas');
await canvas.goToListingPage();
});

it('loads workpads', async function () {
Expand Down
9 changes: 3 additions & 6 deletions x-pack/test/functional/apps/canvas/custom_elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function canvasCustomElementTest({
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const retry = getService('retry');
const PageObjects = getPageObjects(['canvas', 'common']);
const PageObjects = getPageObjects(['canvas']);
const find = getService('find');
const kibanaServer = getService('kibanaServer');
const archive = 'x-pack/test/functional/fixtures/kbn_archiver/canvas/default';
Expand All @@ -26,12 +26,9 @@ export default function canvasCustomElementTest({

before(async () => {
await kibanaServer.importExport.load(archive);
// open canvas home
await PageObjects.common.navigateToApp('canvas');
// load test workpad
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31/page/1',
});
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('Test Workpad');
});

after(async () => {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/canvas/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';

export default function canvasExpressionTest({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['canvas', 'common']);
const PageObjects = getPageObjects(['canvas']);
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const monacoEditor = getService('monacoEditor');
Expand All @@ -35,7 +35,7 @@ export default function canvasExpressionTest({ getService, getPageObjects }: Ftr
});

// create new test workpad
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.createNewWorkpad();
});

Expand Down
9 changes: 4 additions & 5 deletions x-pack/test/functional/apps/canvas/embeddables/lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function canvasLensTest({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['canvas', 'common', 'header', 'lens']);
const PageObjects = getPageObjects(['canvas', 'header', 'lens']);
const esArchiver = getService('esArchiver');
const dashboardAddPanel = getService('dashboardAddPanel');
const dashboardPanelActions = getService('dashboardPanelActions');
Expand All @@ -25,7 +25,7 @@ export default function canvasLensTest({ getService, getPageObjects }: FtrProvid
await kibanaServer.savedObjects.cleanStandardList();
await kibanaServer.importExport.load(archives.kbn);
await kibanaServer.uiSettings.replace({ defaultIndex: 'logstash-lens' });
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.createNewWorkpad();
});

Expand All @@ -49,9 +49,8 @@ export default function canvasLensTest({ getService, getPageObjects }: FtrProvid

it('renders lens visualization using savedLens expression', async () => {
// load test workpad
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31/page/1',
});
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('Test Workpad');
await PageObjects.header.waitUntilLoadingHasFinished();

await PageObjects.lens.assertLegacyMetric('Maximum of bytes', '16,788');
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/canvas/embeddables/maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['canvas', 'common', 'header', 'maps']);
const PageObjects = getPageObjects(['canvas', 'header', 'maps']);
const dashboardPanelActions = getService('dashboardPanelActions');
const dashboardAddPanel = getService('dashboardAddPanel');
const testSubjects = getService('testSubjects');
Expand All @@ -19,7 +19,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
before(async () => {
await kibanaServer.savedObjects.cleanStandardList();
// open canvas home
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
// create new workpad
await PageObjects.canvas.createNewWorkpad();
await PageObjects.canvas.setWorkpadName('maps tests');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const PageObjects = getPageObjects(['canvas', 'common', 'header', 'discover']);
const PageObjects = getPageObjects(['canvas', 'header', 'discover']);
const testSubjects = getService('testSubjects');
const kibanaServer = getService('kibanaServer');
const dashboardAddPanel = getService('dashboardAddPanel');
Expand All @@ -21,7 +21,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
'test/functional/fixtures/kbn_archiver/dashboard/current/kibana'
);
// open canvas home
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
// create new workpad
await PageObjects.canvas.createNewWorkpad();
await PageObjects.canvas.setWorkpadName('saved search tests');
Expand All @@ -41,7 +41,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
it('edits saved search by-reference embeddable', async () => {
await dashboardPanelActions.editPanelByTitle('Rendering Test: saved search');
await PageObjects.discover.saveSearch('Rendering Test: saved search v2');
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('saved search tests');
await testSubjects.existOrFail('embeddablePanelHeading-RenderingTest:savedsearchv2');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { FtrProviderContext } from '../../../ftr_provider_context';

export default function ({ getService, getPageObjects }: FtrProviderContext) {
const retry = getService('retry');
const PageObjects = getPageObjects(['canvas', 'common', 'header', 'visualize']);
const PageObjects = getPageObjects(['canvas', 'header', 'visualize']);
const kibanaServer = getService('kibanaServer');
const testSubjects = getService('testSubjects');
const dashboardAddPanel = getService('dashboardAddPanel');
Expand All @@ -30,7 +30,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
);

// open canvas home
await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
// create new workpad
await PageObjects.canvas.createNewWorkpad();
await PageObjects.canvas.setWorkpadName('visualization tests');
Expand Down
7 changes: 3 additions & 4 deletions x-pack/test/functional/apps/canvas/expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function canvasExpressionTest({ getService, getPageObjects }: Ftr
const find = getService('find');
const kibanaServer = getService('kibanaServer');
const monacoEditor = getService('monacoEditor');
const PageObjects = getPageObjects(['canvas', 'common']);
const PageObjects = getPageObjects(['canvas']);
const retry = getService('retry');
const testSubjects = getService('testSubjects');

Expand All @@ -27,9 +27,8 @@ export default function canvasExpressionTest({ getService, getPageObjects }: Ftr
await kibanaServer.importExport.load(archive);

// load test workpad
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31/page/1',
});
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('Test Workpad');
});

after(async () => {
Expand Down
7 changes: 3 additions & 4 deletions x-pack/test/functional/apps/canvas/filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
export default function canvasFiltersTest({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const retry = getService('retry');
const PageObjects = getPageObjects(['canvas', 'common']);
const PageObjects = getPageObjects(['canvas']);
const find = getService('find');
const kibanaServer = getService('kibanaServer');
const archive = 'x-pack/test/functional/fixtures/kbn_archiver/canvas/filter';
Expand All @@ -24,9 +24,8 @@ export default function canvasFiltersTest({ getService, getPageObjects }: FtrPro
before(async () => {
await kibanaServer.importExport.load(archive);
// load test workpad
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-b5618217-56d2-47fa-b756-1be2306cda68/page/1',
});
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('Filter Debug Workpad');
});

after(async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import path from 'path';
import { FtrProviderContext } from '../../ftr_provider_context';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const PageObjects = getPageObjects(['common', 'settings', 'savedObjects']);
const PageObjects = getPageObjects(['settings', 'savedObjects']);

describe('migration smoke test', function () {
it('imports an 8.2 workpad', async function () {
Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/canvas/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const browser = getService('browser');
const log = getService('log');
const security = getService('security');
const PageObjects = getPageObjects(['reporting', 'common', 'canvas']);
const PageObjects = getPageObjects(['reporting', 'canvas']);
const archive = 'x-pack/test/functional/fixtures/kbn_archiver/canvas/reports';

describe('Canvas PDF Report Generation', () => {
Expand Down Expand Up @@ -52,7 +52,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
// Generating and then comparing reports can take longer than the default 60s timeout
this.timeout(180000);

await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('The Very Cool Workpad for PDF Tests');

await PageObjects.reporting.openPdfReportingPanel();
Expand Down
24 changes: 16 additions & 8 deletions x-pack/test/functional/apps/canvas/saved_object_resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ export default function canvasFiltersTest({ getService, getPageObjects }: FtrPro
});

it('redirects an alias match', async () => {
await PageObjects.common.navigateToApp('canvas', {
basePath: '/s/custom_space',
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31-old-id/page/1',
});
await PageObjects.common.navigateToUrl(
'canvas',
'workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31-old-id/page/1',
{
basePath: '/s/custom_space',
shouldUseHashForSubUrl: false,
}
);

// Wait for the redirect toast
await retry.try(async () => {
Expand All @@ -111,10 +115,14 @@ export default function canvasFiltersTest({ getService, getPageObjects }: FtrPro
});

it('handles a conflict match', async () => {
await PageObjects.common.navigateToApp('canvas', {
basePath: '/s/custom_space',
hash: '/workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31-conflict-old/page/1',
});
await PageObjects.common.navigateToUrl(
'canvas',
'workpad/workpad-1705f884-6224-47de-ba49-ca224fe6ec31-conflict-old/page/1',
{
basePath: '/s/custom_space',
shouldUseHashForSubUrl: false,
}
);

await testSubjects.click('legacy-url-conflict-go-to-other-button');

Expand Down
4 changes: 2 additions & 2 deletions x-pack/test/functional/apps/canvas/smoke_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function canvasSmokeTest({ getService, getPageObjects }) {
const testSubjects = getService('testSubjects');
const browser = getService('browser');
const retry = getService('retry');
const PageObjects = getPageObjects(['common']);
const PageObjects = getPageObjects(['canvas']);
const kibanaServer = getService('kibanaServer');
const config = getService('config');
const archive = {
Expand All @@ -31,7 +31,7 @@ export default function canvasSmokeTest({ getService, getPageObjects }) {
await kibanaServer.importExport.load(archive.local);
}

await PageObjects.common.navigateToApp('canvas');
await PageObjects.canvas.goToListingPage();
});

after(async () => {
Expand Down
5 changes: 2 additions & 3 deletions x-pack/test/functional/apps/maps/group2/embeddable/canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {

describe('Map embeddable in canvas', () => {
before(async () => {
await PageObjects.common.navigateToApp('canvas', {
hash: '/workpad/workpad-c74f9c27-a142-4664-bf8a-69bf782fc268/page/1',
});
await PageObjects.canvas.goToListingPage();
await PageObjects.canvas.loadFirstWorkpad('Canvas with map');
});

it('should render map embeddable', async () => {
Expand Down
Loading

0 comments on commit 94587c9

Please sign in to comment.