Skip to content

Commit

Permalink
More efficient clickOnEuiCheckbox utility + fix policy details test
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-tavares committed Jun 8, 2020
1 parent 194cd70 commit efdcc0c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 43 deletions.
22 changes: 12 additions & 10 deletions x-pack/test/functional_endpoint/apps/endpoint/policy_details.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,13 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
);
});
it('should have updated policy data in overall agent configuration', async () => {
// Turn off file events.
// This test ensures that updates made to the Endpoint Policy are carried all the way through
// to the generated Agent Configuration that is dispatch down to the Elastic Agent.

await Promise.all([
pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyWindowsEvent_file'),
pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyLinuxEvent_file'),
pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyMaxEvent_file'),
pageObjects.endpointPageUtils.clickOnEuiCheckbox('policyMacEvent_file'),
]);
await pageObjects.policy.confirmAndSave();
await testSubjects.existOrFail('policyDetailsSuccessMessage');
Expand All @@ -100,7 +102,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
datasources: [
{
enabled: true,
id: 'e5cfd120-a9b8-11ea-8cdc-f3228a168e40',
id: policyInfo.datasource.id,
inputs: [
{
enabled: true,
Expand All @@ -120,7 +122,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
},
},
events: {
file: true,
file: false,
network: true,
process: true,
},
Expand All @@ -144,7 +146,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
},
},
events: {
file: true,
file: false,
network: true,
process: true,
},
Expand Down Expand Up @@ -172,8 +174,8 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
},
events: {
dll_and_driver_load: true,
dns: false,
file: true,
dns: true,
file: false,
network: true,
process: true,
registry: true,
Expand All @@ -196,19 +198,19 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
namespace: 'default',
package: {
name: 'endpoint',
version: '0.2.0',
version: policyInfo.packageInfo.version,
},
use_output: 'default',
},
],
id: 'e59252f0-a9b8-11ea-8cdc-f3228a168e40',
id: policyInfo.agentConfig.id,
outputs: {
default: {
hosts: ['http://localhost:9200'],
type: 'elasticsearch',
},
},
revision: 5,
revision: 3,
settings: {
monitoring: {
enabled: false,
Expand Down
37 changes: 8 additions & 29 deletions x-pack/test/functional_endpoint/page_objects/page_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
* 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 EndpointPageUtils({ getService }: FtrProviderContext) {
const find = getService('find');
const log = getService('log');

return {
/**
Expand All @@ -18,34 +16,15 @@ export function EndpointPageUtils({ getService }: FtrProviderContext) {
* @param euiCheckBoxTestId
*/
async clickOnEuiCheckbox(euiCheckBoxTestId: string) {
// FIXME: this method is extreemly slow - fix it
const checkboxes = await find.allByCssSelector('.euiCheckbox');
const silentCatch = () => {};
// 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`
);

log.debug(`Found ${checkboxes.length} EuiCheckbox's`);

for (const checkbox of checkboxes) {
log.debug('Checking EuiCheckBox');
const checkBoxInput: WebElementWrapper | void = await checkbox
.findByTestSubject(euiCheckBoxTestId)
.catch(silentCatch);
if (checkBoxInput !== undefined) {
log.debug(`Found EuiCheckBox with data-test-subj=${euiCheckBoxTestId}`);

const labelElement = await checkbox.findByCssSelector('.euiCheckbox__label');

// Want to ensure that the Click actually did an update - case the internals of
// EuiCheckbox change in the future
const beforeClickIsChecked = await checkBoxInput.isSelected();
await labelElement.click();
const afterClickIsChecked = await checkBoxInput.isSelected();
if (beforeClickIsChecked === afterClickIsChecked) {
throw new Error('click did not update checkbox!');
}
return checkbox;
}
}
throw new Error(`EuiCheckbox with data-test-subj of [${euiCheckBoxTestId}] not found!`);
await euiCheckboxLabelElement.click();
},
};
}
11 changes: 7 additions & 4 deletions x-pack/test/functional_endpoint/services/endpoint_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ export interface PolicyTestResourceInfo {
* This is where Endpoint Policy is stored.
*/
datasource: Immutable<CreateDatasourceResponse['item']>;
/**
* Information about the endpoint package
*/
packageInfo: Immutable<GetPackagesResponse['response'][0]>;
/** will clean up (delete) the objects created (agent config + datasource) */
cleanup: () => Promise<void>;
}
Expand Down Expand Up @@ -160,10 +164,9 @@ export function EndpointPolicyTestResourcesProvider({ getService }: FtrProviderC
}

return {
// @ts-ignore
agentConfig,
// @ts-ignore
datasource,
agentConfig: agentConfig!,
datasource: datasource!,
packageInfo: endpointPackageInfo!,
async cleanup() {
// Delete Datasource
try {
Expand Down

0 comments on commit efdcc0c

Please sign in to comment.