Skip to content

Commit

Permalink
[Infrastructure UI] Fix hosts view flaky funcional test (elastic#157913)
Browse files Browse the repository at this point in the history
fixes: elastic#157718
fixes: elastic#157719
fixes: elastic#157720
fixes: elastic#157721
fixes: elastic#157733
fixes: elastic#157734

## Summary

Fixes hosts view flaky tests

https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2258

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 051ac85)
  • Loading branch information
crespocarlos committed May 31, 2023
1 parent cf1a516 commit 3e0875e
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 51 deletions.
137 changes: 89 additions & 48 deletions x-pack/test/functional/apps/infra/hosts_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,15 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
'infraHostsView',
'security',
'settings',
'header',
]);

// Helpers
const setHostViewEnabled = (value: boolean = true) =>
kibanaServer.uiSettings.update({ [enableInfrastructureHostsView]: value });

const loginWithReadOnlyUser = async () => {
const roleCreation = security.role.create('global_hosts_read_privileges_role', {
const roleCreation = await security.role.create('global_hosts_read_privileges_role', {
elasticsearch: {
indices: [{ names: ['metricbeat-*'], privileges: ['read', 'view_index_metadata'] }],
},
Expand All @@ -126,10 +127,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
full_name: 'test user',
});

const logout = pageObjects.security.forceLogout();

await Promise.all([roleCreation, userCreation, logout]);
await Promise.all([roleCreation, userCreation]);

await pageObjects.security.forceLogout();
await pageObjects.security.login(
'global_hosts_read_privileges_user',
'global_hosts_read_privileges_user-password',
Expand All @@ -146,11 +146,8 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
security.user.delete('global_hosts_read_privileges_user'),
]);

const enableHostView = () => pageObjects.infraHostsView.clickEnableHostViewButton();

describe('Hosts View', function () {
// Failing: See https://github.com/elastic/kibana/issues/157718
// this.tags('includeFirefox');
this.tags('includeFirefox');

before(async () => {
await Promise.all([
Expand All @@ -171,6 +168,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

it('should be accessible from the Inventory page', async () => {
await pageObjects.common.navigateToApp('infraOps');

await pageObjects.infraHome.clickDismissKubernetesTourButton();
await pageObjects.infraHostsView.clickTryHostViewBadge();

Expand All @@ -179,74 +177,98 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
expect(pageUrl).to.contain(HOSTS_VIEW_PATH);
});

// FLAKY: https://github.com/elastic/kibana/issues/157718
describe.skip('#Landing page', () => {
beforeEach(() => {
setHostViewEnabled(false);
describe('#Landing page', () => {
beforeEach(async () => {
await setHostViewEnabled(false);
});

it('as a user with read permission, should show hosts landing page with callout when the hosts view is disabled', async () => {
await loginWithReadOnlyUser();
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
afterEach(async () => {
await setHostViewEnabled(true);
});

const landingPageDisabled = await pageObjects.infraHostsView.getHostsLandingPageDisabled();
const learnMoreDocsUrl = await pageObjects.infraHostsView.getHostsLandingPageDocsLink();
const parsedUrl = new URL(learnMoreDocsUrl);
describe('User with read permission', () => {
beforeEach(async () => {
await loginWithReadOnlyUser();
});

expect(parsedUrl.host).to.be('www.elastic.co');
expect(parsedUrl.pathname).to.be('/guide/en/kibana/current/kibana-privileges.html');
expect(landingPageDisabled).to.contain(
'Your user role doesn’t have sufficient privileges to enable this feature'
);
afterEach(async () => {
await logoutAndDeleteReadOnlyUser();
});

await logoutAndDeleteReadOnlyUser();
});
it('Should show hosts landing page with callout when the hosts view is disabled', async () => {
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await pageObjects.header.waitUntilLoadingHasFinished();

it('as an admin, should see an enable button when the hosts view is disabled', async () => {
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
const landingPageDisabled =
await pageObjects.infraHostsView.getHostsLandingPageDisabled();
const learnMoreDocsUrl = await pageObjects.infraHostsView.getHostsLandingPageDocsLink();
const parsedUrl = new URL(learnMoreDocsUrl);

const landingPageEnableButton =
await pageObjects.infraHostsView.getHostsLandingPageEnableButton();
const landingPageEnableButtonText = await landingPageEnableButton.getVisibleText();
expect(landingPageEnableButtonText).to.eql('Enable hosts view');
expect(parsedUrl.host).to.be('www.elastic.co');
expect(parsedUrl.pathname).to.be('/guide/en/kibana/current/kibana-privileges.html');
expect(landingPageDisabled).to.contain(
'Your user role doesn’t have sufficient privileges to enable this feature'
);
});
});

it('as an admin, should be able to enable the hosts view feature', async () => {
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await enableHostView();
describe('Admin user', () => {
it('as an admin, should see an enable button when the hosts view is disabled', async () => {
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await pageObjects.header.waitUntilLoadingHasFinished();

const landingPageEnableButton =
await pageObjects.infraHostsView.getHostsLandingPageEnableButton();
const landingPageEnableButtonText = await landingPageEnableButton.getVisibleText();
expect(landingPageEnableButtonText).to.eql('Enable hosts view');
});

const titleElement = await find.byCssSelector('h1');
const title = await titleElement.getVisibleText();
it('as an admin, should be able to enable the hosts view feature', async () => {
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await pageObjects.header.waitUntilLoadingHasFinished();
await pageObjects.infraHostsView.clickEnableHostViewButton();

expect(title).to.contain('Hosts');
const titleElement = await find.byCssSelector('h1');
const title = await titleElement.getVisibleText();

expect(title).to.contain('Hosts');
});
});
});

// FLAKY: https://github.com/elastic/kibana/issues/157719
// FLAKY: https://github.com/elastic/kibana/issues/157720
describe.skip('#Single host Flyout', () => {
before(async () => {
await setHostViewEnabled(true);
await loginWithReadOnlyUser();
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await pageObjects.header.waitUntilLoadingHasFinished();
await pageObjects.timePicker.setAbsoluteRange(
START_HOST_PROCESSES_DATE.format(timepickerFormat),
END_HOST_PROCESSES_DATE.format(timepickerFormat)
);
await pageObjects.infraHostsView.clickTableOpenFlyoutButton();
});

after(async () => {
await pageObjects.infraHostsView.clickCloseFlyoutButton();
await logoutAndDeleteReadOnlyUser();
});

beforeEach(async () => {
await pageObjects.infraHostsView.clickTableOpenFlyoutButton();
});

afterEach(async () => {
await retry.try(async () => {
await pageObjects.infraHostsView.clickCloseFlyoutButton();
});
});

it('should render metadata tab, add and remove filter', async () => {
const metadataTab = await pageObjects.infraHostsView.getMetadataTabName();
expect(metadataTab).to.contain('Metadata');

await pageObjects.infraHostsView.clickAddMetadataFilter();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();

// Add Filter
const addedFilter = await pageObjects.infraHostsView.getAppliedFilter();
Expand All @@ -256,29 +278,29 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

// Remove filter
await pageObjects.infraHostsView.clickRemoveMetadataFilter();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();
const removeFilterShouldNotExist = await pageObjects.infraHostsView.getRemoveFilterExist();
expect(removeFilterShouldNotExist).to.be(false);
});

it('should navigate to Uptime after click', async () => {
await pageObjects.infraHostsView.clickFlyoutUptimeLink();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();
const url = await browser.getCurrentUrl();
expect(url).to.contain(
'app/uptime/?search=host.name%3A%20%22Jennys-MBP.fritz.box%22%20OR%20host.ip%3A%20%22192.168.1.79%22'
);
await browser.goBack();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();
});

it('should navigate to APM services after click', async () => {
await pageObjects.infraHostsView.clickFlyoutApmServicesLink();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();
const url = await browser.getCurrentUrl();
expect(url).to.contain('app/apm/services?kuery=host.hostname%3A%22Jennys-MBP.fritz.box%22');
await browser.goBack();
await pageObjects.infraHome.waitForLoading();
await pageObjects.header.waitUntilLoadingHasFinished();
});

describe('should render processes tab', async () => {
Expand Down Expand Up @@ -323,9 +345,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
// FLAKY: https://github.com/elastic/kibana/issues/157721
describe.skip('#Page Content', () => {
before(async () => {
await setHostViewEnabled(true);
await loginWithReadOnlyUser();
await pageObjects.common.navigateToApp(HOSTS_VIEW_PATH);
await pageObjects.header.waitUntilLoadingHasFinished();
await pageObjects.timePicker.setAbsoluteRange(
START_DATE.format(timepickerFormat),
END_DATE.format(timepickerFormat)
Expand Down Expand Up @@ -396,6 +418,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.infraHostsView.visitMetricsTab();
});

after(async () => {
await browser.scrollTop();
});

it('should load 8 lens metric charts', async () => {
const metricCharts = await pageObjects.infraHostsView.getAllMetricsCharts();
expect(metricCharts.length).to.equal(8);
Expand All @@ -412,6 +438,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.infraHostsView.visitLogsTab();
});

after(async () => {
await browser.scrollTop();
});

it('should load the Logs tab section when clicking on it', async () => {
await testSubjects.existOrFail('hostsView-logs');
});
Expand All @@ -428,6 +458,10 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await pageObjects.infraHostsView.visitAlertTab();
});

after(async () => {
await browser.scrollTop();
});

it('should correctly load the Alerts tab section when clicking on it', async () => {
testSubjects.existOrFail('hostsView-alerts');
});
Expand Down Expand Up @@ -496,6 +530,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});

after(async () => {
await browser.scrollTop();
await pageObjects.infraHostsView.submitQuery('');
});

Expand Down Expand Up @@ -560,8 +595,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await browser.scrollTop();
});

after(async () => {
await browser.scrollTop();
});

beforeEach(async () => {
await pageObjects.infraHostsView.changePageSize(5);
await retry.try(async () => {
await pageObjects.infraHostsView.changePageSize(5);
});
});

it('should show 5 rows on the first page', async () => {
Expand Down
5 changes: 2 additions & 3 deletions x-pack/test/functional/page_objects/infra_hosts_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ export function InfraHostsViewProvider({ getService }: FtrProviderContext) {
},

async getHostsLandingPageEnableButton() {
const container = await testSubjects.find('hostsView-enable-feature-button');
return container;
return testSubjects.find('hostsView-enable-feature-button');
},

async clickEnableHostViewButton() {
return await testSubjects.click('hostsView-enable-feature-button');
return testSubjects.click('hostsView-enable-feature-button');
},

async getHostsTable() {
Expand Down

0 comments on commit 3e0875e

Please sign in to comment.