From bd641870768bc6781dea710a0130a5ed11cf7527 Mon Sep 17 00:00:00 2001 From: Charlie Pichette Date: Thu, 20 Feb 2020 11:39:49 -0500 Subject: [PATCH 1/5] endpoint-161-refactor-management-list-test --- .../functional/apps/endpoint/management.ts | 68 +++++++++++++++---- .../endpoint/endpoints/api_feature/data.json | 6 +- .../functional/page_objects/endpoint_page.ts | 27 +++++++- 3 files changed, 82 insertions(+), 19 deletions(-) diff --git a/x-pack/test/functional/apps/endpoint/management.ts b/x-pack/test/functional/apps/endpoint/management.ts index bac87f34ceb82..ac97fc92342eb 100644 --- a/x-pack/test/functional/apps/endpoint/management.ts +++ b/x-pack/test/functional/apps/endpoint/management.ts @@ -25,19 +25,61 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { }); it('displays table data', async () => { - const data = await pageObjects.endpoint.getManagementTableData(); - [ - 'Hostnamecadmann-4.example.com', - 'PolicyPolicy Name', - 'Policy StatusPolicy Status', - 'Alerts0', - 'Operating Systemwindows 10.0', - 'IP Address10.192.213.130, 10.70.28.129', - 'Sensor Versionversion', - 'Last Activexxxx', - ].forEach((cellValue, index) => { - expect(data[1][index]).to.equal(cellValue); - }); + const expectedData = [ + [ + 'Hostname', + 'Policy', + 'Policy Status', + 'Alerts', + 'Operating System', + 'IP Address', + 'Sensor Version', + 'Last Active', + ], + [ + 'cadmann-4.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.192.213.130, 10.70.28.129', + 'version', + 'xxxx', + ], + [ + 'thurlow-9.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.46.229.234', + 'version', + 'xxxx', + ], + [ + 'rezzani-7.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.101.149.26, 2606:a000:ffc0:39:11ef:37b9:3371:578c', + 'version', + 'xxxx', + ], + ]; + const tableData = await pageObjects.endpoint.getEndpointAppTableData('managementListTable'); + expect(tableData).to.eql(expectedData); + }); + + it('displays no items found', async () => { + // clear out the data and reload the page + await esArchiver.unload('endpoint/endpoints/api_feature'); + await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management'); + // get the table data and verify no entries appear + const tableData = await pageObjects.endpoint.getEndpointAppTableData('managementListTable'); + expect(tableData[1][0]).to.equal('No items found'); + // reload the data so the other tests continue to pass + await esArchiver.load('endpoint/endpoints/api_feature'); }); after(async () => { diff --git a/x-pack/test/functional/es_archives/endpoint/endpoints/api_feature/data.json b/x-pack/test/functional/es_archives/endpoint/endpoints/api_feature/data.json index 87720b068f0e8..6a7911b5be61f 100644 --- a/x-pack/test/functional/es_archives/endpoint/endpoints/api_feature/data.json +++ b/x-pack/test/functional/es_archives/endpoint/endpoints/api_feature/data.json @@ -110,7 +110,7 @@ "id": "fc0ff548-feba-41b6-8367-65e8790d0eaf", "ip": [ "10.101.149.26", - "10.12.85.216" + "2606:a000:ffc0:39:11ef:37b9:3371:578c" ], "mac": [ "e2-6d-f9-0-46-2e" @@ -238,7 +238,7 @@ "id": "fc0ff548-feba-41b6-8367-65e8790d0eaf", "ip": [ "10.101.149.26", - "10.12.85.216" + "2606:a000:ffc0:39:11ef:37b9:3371:578c" ], "mac": [ "e2-6d-f9-0-46-2e" @@ -365,7 +365,7 @@ "id": "fc0ff548-feba-41b6-8367-65e8790d0eaf", "ip": [ "10.101.149.26", - "10.12.85.216" + "2606:a000:ffc0:39:11ef:37b9:3371:578c" ], "mac": [ "e2-6d-f9-0-46-2e" diff --git a/x-pack/test/functional/page_objects/endpoint_page.ts b/x-pack/test/functional/page_objects/endpoint_page.ts index 54f537dd0e8c3..185b95b00527d 100644 --- a/x-pack/test/functional/page_objects/endpoint_page.ts +++ b/x-pack/test/functional/page_objects/endpoint_page.ts @@ -4,11 +4,11 @@ * you may not use this file except in compliance with the Elastic License. */ +import { WebElementWrapper } from 'test/functional/services/lib/web_element_wrapper'; import { FtrProviderContext } from '../ftr_provider_context'; export function EndpointPageProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); - const table = getService('table'); return { /** @@ -34,8 +34,29 @@ export function EndpointPageProvider({ getService }: FtrProviderContext) { return await testSubjects.getVisibleText('welcomeTitle'); }, - async getManagementTableData() { - return await table.getDataFromTestSubj('managementListTable'); + /** + * Finds a table and returns the data in a nested array with row 0 is the headers if they exist. + * It uses euiTableCellContent to avoid poluting the array data with the euiTableRowCell__mobileHeader data. + * @param dataTestSubj + * @returns Promise + */ + async getEndpointAppTableData(dataTestSubj: string) { + await testSubjects.exists(dataTestSubj); + const hostTable: WebElementWrapper = await testSubjects.find(dataTestSubj); + const $ = await hostTable.parseDomContent(); + return $('tr') + .toArray() + .map(row => + $(row) + .find('.euiTableCellContent') + .toArray() + .map(cell => + $(cell) + .text() + .replace(/ /g, '') + .trim() + ) + ); }, }; } From 6e1c87f40700051f7691376e5a2348b8c36bbb5a Mon Sep 17 00:00:00 2001 From: Charlie Pichette Date: Fri, 21 Feb 2020 09:20:21 -0500 Subject: [PATCH 2/5] fix location of es archive file --- x-pack/test/functional/apps/endpoint/management.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/test/functional/apps/endpoint/management.ts b/x-pack/test/functional/apps/endpoint/management.ts index 56e06740fc336..4925fa7678ab0 100644 --- a/x-pack/test/functional/apps/endpoint/management.ts +++ b/x-pack/test/functional/apps/endpoint/management.ts @@ -73,13 +73,13 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { it('displays no items found', async () => { // clear out the data and reload the page - await esArchiver.unload('endpoint/endpoints/api_feature'); + await esArchiver.unload('endpoint/metadata/api_feature'); await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/management'); // get the table data and verify no entries appear const tableData = await pageObjects.endpoint.getEndpointAppTableData('managementListTable'); expect(tableData[1][0]).to.equal('No items found'); // reload the data so the other tests continue to pass - await esArchiver.load('endpoint/endpoints/api_feature'); + await esArchiver.load('endpoint/metadata/api_feature'); }); after(async () => { From 97ec7aaa22572f1c31b3c29e926c06e7b1a4b51d Mon Sep 17 00:00:00 2001 From: Charlie Pichette Date: Tue, 21 Apr 2020 15:41:31 -0400 Subject: [PATCH 3/5] Fix Endpoint App Host List Test Failure --- x-pack/test/functional_endpoint/apps/endpoint/host_list.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts index 35843dc6a76db..c21c7a1c86f85 100644 --- a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts +++ b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts @@ -13,13 +13,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const testSubjects = getService('testSubjects'); // FLAKY: https://github.com/elastic/kibana/issues/63621 - describe.skip('host list', function() { + describe('host list', function() { this.tags('ciGroup7'); const sleep = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); before(async () => { await esArchiver.load('endpoint/metadata/api_feature'); await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); await pageObjects.header.waitUntilLoadingHasFinished(); + await pageObjects.endpoint.waitForTableToHaveData('hostListTable'); }); it('finds title', async () => { @@ -121,6 +122,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { after(async () => { // reload the data so the other tests continue to pass await esArchiver.load('endpoint/metadata/api_feature'); + await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); + await pageObjects.header.waitUntilLoadingHasFinished(); + await pageObjects.endpoint.waitForTableToHaveData('hostListTable'); }); it('displays no items found when empty', async () => { // get the host list table data and verify message From 96bc8f34e8a03721506addaa0dde05dc8bde2165 Mon Sep 17 00:00:00 2001 From: Charlie Pichette Date: Tue, 21 Apr 2020 15:45:07 -0400 Subject: [PATCH 4/5] remove comment --- x-pack/test/functional_endpoint/apps/endpoint/host_list.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts index c21c7a1c86f85..2fcb226116255 100644 --- a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts +++ b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts @@ -12,7 +12,6 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { const esArchiver = getService('esArchiver'); const testSubjects = getService('testSubjects'); - // FLAKY: https://github.com/elastic/kibana/issues/63621 describe('host list', function() { this.tags('ciGroup7'); const sleep = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); From dd3d7f4f9550b5ca823eae128d4512ba87cb262c Mon Sep 17 00:00:00 2001 From: Charlie Pichette Date: Wed, 22 Apr 2020 08:29:27 -0400 Subject: [PATCH 5/5] reorganize the test script --- .../apps/endpoint/host_list.ts | 215 +++++++++--------- 1 file changed, 109 insertions(+), 106 deletions(-) diff --git a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts index 2fcb226116255..5202bb6df7527 100644 --- a/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts +++ b/x-pack/test/functional_endpoint/apps/endpoint/host_list.ts @@ -16,126 +16,113 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { this.tags('ciGroup7'); const sleep = (ms = 100) => new Promise(resolve => setTimeout(resolve, ms)); before(async () => { - await esArchiver.load('endpoint/metadata/api_feature'); await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); await pageObjects.header.waitUntilLoadingHasFinished(); - await pageObjects.endpoint.waitForTableToHaveData('hostListTable'); }); - it('finds title', async () => { - const title = await testSubjects.getVisibleText('hostListTitle'); - expect(title).to.equal('Hosts'); - }); - - it('displays table data', async () => { - const expectedData = [ - [ - 'Hostname', - 'Policy', - 'Policy Status', - 'Alerts', - 'Operating System', - 'IP Address', - 'Sensor Version', - 'Last Active', - ], - [ - 'cadmann-4.example.com', - 'Policy Name', - 'Policy Status', - '0', - 'windows 10.0', - '10.192.213.130, 10.70.28.129', - 'version', - 'xxxx', - ], - [ - 'thurlow-9.example.com', - 'Policy Name', - 'Policy Status', - '0', - 'windows 10.0', - '10.46.229.234', - 'version', - 'xxxx', - ], - [ - 'rezzani-7.example.com', - 'Policy Name', - 'Policy Status', - '0', - 'windows 10.0', - '10.101.149.26, 2606:a000:ffc0:39:11ef:37b9:3371:578c', - 'version', - 'xxxx', - ], - ]; - const tableData = await pageObjects.endpoint.getEndpointAppTableData('hostListTable'); - expect(tableData).to.eql(expectedData); - }); - - it('no details flyout when host page displayed', async () => { - await testSubjects.missingOrFail('hostDetailsFlyout'); - }); - - it('display details flyout when the hostname is clicked on', async () => { - await (await testSubjects.find('hostnameCellLink')).click(); - await testSubjects.existOrFail('hostDetailsUpperList'); - await testSubjects.existOrFail('hostDetailsLowerList'); - }); - - it('update details flyout when new hostname is clicked on', async () => { - // display flyout for the first host in the list - await (await testSubjects.findAll('hostnameCellLink'))[0].click(); - await testSubjects.existOrFail('hostDetailsFlyoutTitle'); - const hostDetailTitle0 = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); - // select the 2nd host in the host list - await (await testSubjects.findAll('hostnameCellLink'))[1].click(); - await pageObjects.endpoint.waitForVisibleTextToChange( - 'hostDetailsFlyoutTitle', - hostDetailTitle0 - ); - const hostDetailTitle1 = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); - expect(hostDetailTitle1).to.not.eql(hostDetailTitle0); - }); - - it('details flyout remains the same when current hostname is clicked on', async () => { - // display flyout for the first host in the list - await (await testSubjects.findAll('hostnameCellLink'))[1].click(); - await testSubjects.existOrFail('hostDetailsFlyoutTitle'); - const hostDetailTitleInitial = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); - // select the same host in the host list - await (await testSubjects.findAll('hostnameCellLink'))[1].click(); - await sleep(500); // give page time to refresh and verify it did not change - const hostDetailTitleNew = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); - expect(hostDetailTitleNew).to.eql(hostDetailTitleInitial); - }); - - describe('no data', () => { + describe('with data', () => { before(async () => { - // clear out the data and reload the page - await esArchiver.unload('endpoint/metadata/api_feature'); - await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); - await pageObjects.header.waitUntilLoadingHasFinished(); - }); - after(async () => { - // reload the data so the other tests continue to pass await esArchiver.load('endpoint/metadata/api_feature'); await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); await pageObjects.header.waitUntilLoadingHasFinished(); await pageObjects.endpoint.waitForTableToHaveData('hostListTable'); }); - it('displays no items found when empty', async () => { - // get the host list table data and verify message - const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData( - 'hostListTable' + after(async () => { + await esArchiver.unload('endpoint/metadata/api_feature'); + }); + it('finds title', async () => { + const title = await testSubjects.getVisibleText('hostListTitle'); + expect(title).to.equal('Hosts'); + }); + + it('displays table data', async () => { + const expectedData = [ + [ + 'Hostname', + 'Policy', + 'Policy Status', + 'Alerts', + 'Operating System', + 'IP Address', + 'Sensor Version', + 'Last Active', + ], + [ + 'cadmann-4.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.192.213.130, 10.70.28.129', + 'version', + 'xxxx', + ], + [ + 'thurlow-9.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.46.229.234', + 'version', + 'xxxx', + ], + [ + 'rezzani-7.example.com', + 'Policy Name', + 'Policy Status', + '0', + 'windows 10.0', + '10.101.149.26, 2606:a000:ffc0:39:11ef:37b9:3371:578c', + 'version', + 'xxxx', + ], + ]; + const tableData = await pageObjects.endpoint.getEndpointAppTableData('hostListTable'); + expect(tableData).to.eql(expectedData); + }); + + it('no details flyout when host page displayed', async () => { + await testSubjects.missingOrFail('hostDetailsFlyout'); + }); + + it('display details flyout when the hostname is clicked on', async () => { + await (await testSubjects.find('hostnameCellLink')).click(); + await testSubjects.existOrFail('hostDetailsUpperList'); + await testSubjects.existOrFail('hostDetailsLowerList'); + }); + + it('update details flyout when new hostname is clicked on', async () => { + // display flyout for the first host in the list + await (await testSubjects.findAll('hostnameCellLink'))[0].click(); + await testSubjects.existOrFail('hostDetailsFlyoutTitle'); + const hostDetailTitle0 = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); + // select the 2nd host in the host list + await (await testSubjects.findAll('hostnameCellLink'))[1].click(); + await pageObjects.endpoint.waitForVisibleTextToChange( + 'hostDetailsFlyoutTitle', + hostDetailTitle0 ); - expect(noItemsFoundMessage).to.equal('No items found'); + const hostDetailTitle1 = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); + expect(hostDetailTitle1).to.not.eql(hostDetailTitle0); + }); + + it('details flyout remains the same when current hostname is clicked on', async () => { + // display flyout for the first host in the list + await (await testSubjects.findAll('hostnameCellLink'))[1].click(); + await testSubjects.existOrFail('hostDetailsFlyoutTitle'); + const hostDetailTitleInitial = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); + // select the same host in the host list + await (await testSubjects.findAll('hostnameCellLink'))[1].click(); + await sleep(500); // give page time to refresh and verify it did not change + const hostDetailTitleNew = await testSubjects.getVisibleText('hostDetailsFlyoutTitle'); + expect(hostDetailTitleNew).to.eql(hostDetailTitleInitial); }); }); describe('has a url with a host id', () => { before(async () => { + await esArchiver.load('endpoint/metadata/api_feature'); await pageObjects.common.navigateToUrlWithBrowserHistory( 'endpoint', '/hosts', @@ -143,6 +130,9 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { ); await pageObjects.header.waitUntilLoadingHasFinished(); }); + after(async () => { + await esArchiver.unload('endpoint/metadata/api_feature'); + }); it('shows a flyout', async () => { await testSubjects.existOrFail('hostDetailsFlyout'); @@ -178,8 +168,21 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { ]); }); }); - after(async () => { - await esArchiver.unload('endpoint/metadata/api_feature'); + + describe('no data', () => { + before(async () => { + // clear out the data and reload the page + await esArchiver.unload('endpoint/metadata/api_feature'); + await pageObjects.common.navigateToUrlWithBrowserHistory('endpoint', '/hosts'); + await pageObjects.header.waitUntilLoadingHasFinished(); + }); + it('displays no items found when empty', async () => { + // get the host list table data and verify message + const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData( + 'hostListTable' + ); + expect(noItemsFoundMessage).to.equal('No items found'); + }); }); }); };