Skip to content

Commit

Permalink
moved common pageobject from endpoint_list to page_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Jun 9, 2020
1 parent 8c00d83 commit 99b4a32
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import expect from '@kbn/expect';
import { FtrProviderContext } from '../../ftr_provider_context';

export default ({ getPageObjects, getService }: FtrProviderContext) => {
const pageObjects = getPageObjects(['common', 'endpoint', 'header']);
const pageObjects = getPageObjects(['common', 'endpoint', 'header', 'endpointPageUtils']);
const esArchiver = getService('esArchiver');
const testSubjects = getService('testSubjects');

Expand Down Expand Up @@ -73,7 +73,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
'Jan 24, 2020 @ 16:06:09.541',
],
];
const tableData = await pageObjects.endpoint.getEndpointAppTableData('hostListTable');
const tableData = await pageObjects.endpointPageUtils.tableData('hostListTable');
expect(tableData).to.eql(expectedData);
});

Expand Down Expand Up @@ -126,7 +126,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
it('displays no items found when empty', async () => {
// get the endpoint list table data and verify message
const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData(
const [, [noItemsFoundMessage]] = await pageObjects.endpointPageUtils.tableData(
'hostListTable'
);
expect(noItemsFoundMessage).to.equal('No items found');
Expand Down
10 changes: 6 additions & 4 deletions x-pack/test/functional_endpoint/apps/endpoint/policy_list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { FtrProviderContext } from '../../ftr_provider_context';
import { PolicyTestResourceInfo } from '../../services/endpoint_policy';

export default function ({ getPageObjects, getService }: FtrProviderContext) {
const pageObjects = getPageObjects(['common', 'endpoint', 'policy']);
const pageObjects = getPageObjects(['common', 'endpoint', 'policy', 'endpointPageUtils']);
const testSubjects = getService('testSubjects');
const policyTestResources = getService('policyTestResources');
const RELATIVE_DATE_FORMAT = /\d (?:seconds|minutes) ago/i;
Expand All @@ -31,7 +31,9 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
expect(policyTotal).to.equal('0 Policies');
});
it('has correct table headers', async () => {
const allHeaderCells = await pageObjects.endpoint.tableHeaderVisibleText('policyTable');
const allHeaderCells = await pageObjects.endpointPageUtils.tableHeaderVisibleText(
'policyTable'
);
expect(allHeaderCells).to.eql([
'Policy Name',
'Created By',
Expand All @@ -43,7 +45,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
]);
});
it('should show empty table results message', async () => {
const [, [noItemsFoundMessage]] = await pageObjects.endpoint.getEndpointAppTableData(
const [, [noItemsFoundMessage]] = await pageObjects.endpointPageUtils.tableData(
'policyTable'
);
expect(noItemsFoundMessage).to.equal('No items found');
Expand All @@ -65,7 +67,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});

it('should show policy on the list', async () => {
const [, policyRow] = await pageObjects.endpoint.getEndpointAppTableData('policyTable');
const [, policyRow] = await pageObjects.endpointPageUtils.tableData('policyTable');
// Validate row data with the exception of the Date columns - since those are initially
// shown as relative.
expect([policyRow[0], policyRow[1], policyRow[3], policyRow[5], policyRow[6]]).to.eql([
Expand Down
48 changes: 2 additions & 46 deletions x-pack/test/functional_endpoint/page_objects/endpoint_page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context';

export function EndpointPageProvider({ getService, getPageObjects }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const pageObjects = getPageObjects(['common', 'header']);
const pageObjects = getPageObjects(['common', 'header', 'endpointPageUtils']);
const retry = getService('retry');

return {
Expand All @@ -23,53 +23,9 @@ export function EndpointPageProvider({ getService, getPageObjects }: FtrProvider
await pageObjects.header.waitUntilLoadingHasFinished();
},

/**
* Finds the Table with the given `selector` (test subject) and returns
* back an array containing the table's header column text
*
* @param selector
* @returns Promise<string[]>
*/
async tableHeaderVisibleText(selector: string) {
const $ = await (await testSubjects.find('policyTable')).parseDomContent();
return $('thead tr th')
.toArray()
.map((th) =>
$(th)
.text()
.replace(/&nbsp;/g, '')
.trim()
);
},

/**
* 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<string[][]>
*/
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(/&nbsp;/g, '')
.trim()
)
);
},

async waitForTableToHaveData(dataTestSubj: string) {
await retry.waitForWithTimeout('table to have data', 2000, async () => {
const tableData = await this.getEndpointAppTableData(dataTestSubj);
const tableData = await pageObjects.endpointPageUtils.tableData(dataTestSubj);
if (tableData[1][0] === 'No items found') {
return false;
}
Expand Down
46 changes: 46 additions & 0 deletions x-pack/test/functional_endpoint/page_objects/page_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
*/

import { FtrProviderContext } from '../ftr_provider_context';
import { WebElementWrapper } from '../../../../test/functional/services/lib/web_element_wrapper';

export function EndpointPageUtils({ getService }: FtrProviderContext) {
const testSubjects = getService('testSubjects');
const find = getService('find');

return {
Expand All @@ -26,5 +28,49 @@ export function EndpointPageUtils({ getService }: FtrProviderContext) {

await euiCheckboxLabelElement.click();
},

/**
* Finds the Table with the given `selector` (test subject) and returns
* back an array containing the table's header column text
*
* @param selector
* @returns Promise<string[]>
*/
async tableHeaderVisibleText(selector: string) {
const $ = await (await testSubjects.find(selector)).parseDomContent();
return $('thead tr th')
.toArray()
.map((th) =>
$(th)
.text()
.replace(/&nbsp;/g, '')
.trim()
);
},

/**
* 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<string[][]>
*/
async tableData(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(/&nbsp;/g, '')
.trim()
)
);
},
};
}

0 comments on commit 99b4a32

Please sign in to comment.