kibana/x-pack/test/security_solution_endpoint/page_objects/page_utils.ts
Paul Tavares 521493f344
[7.x] [Endpoint] Functional Tests cleanup (#68756) (#68822)
* [Endpoint] Functional Tests cleanup (#68756)

* Removed several unnecessary disabled eslint rules
* moved common pageobject from endpoint_list to page_utils
* Rename functional_endpoint to security_solution_endpoint
* Delete `functional_endpoint_ingest_failure` no longer applicable

# Conflicts:
#	.github/CODEOWNERS
#	x-pack/test/security_solution_endpoint/apps/endpoint/resolver.ts

* Sync Endpoint Alerts page objects with master

- PR https://github.com/elastic/kibana/pull/64704 was never
  backported, thus this change is needed to ensure build is
  successful.

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-06-12 08:04:45 -04:00

76 lines
2.5 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
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 {
/**
* Finds a given EuiCheckbox by test subject and clicks on it
*
* @param euiCheckBoxTestId
*/
async clickOnEuiCheckbox(euiCheckBoxTestId: string) {
// This utility is needed because EuiCheckbox forwards the test subject on to
// the actual `<input>` which is not actually visible/accessible on the page.
// In order to actually cause the state of the checkbox to change, the `<label>`
// must be clicked.
const euiCheckboxLabelElement = await find.byXPath(
`//input[@data-test-subj='${euiCheckBoxTestId}']/../label`
);
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()
)
);
},
};
}