[ML] Functional tests - fix typing issue (#52167)

* Use char by char typing in all text fields

* Add dely before first typed charakter when typing char by char

* Remove delay before typing again

* Use clearCharByChar option for input fields

* Revert "Use clearCharByChar option for input fields"

This reverts commit e412d7bc64.

* Revert "Use char by char typing in all text fields"

This reverts commit 2fbccc57c6.

* Disable jobCreatorUpdate for tests

* Revert "Disable jobCreatorUpdate for tests"

This reverts commit e178fd82ab.

* Check typing char by char for job wizard inputs

* Remove .only from anomaly detection suite

* Move setValueWithChecks from testSubjects to a ML service
This commit is contained in:
Robert Oskamp 2019-12-10 00:00:36 +01:00 committed by Spencer
parent 3293ede421
commit d429a9a1e8
5 changed files with 97 additions and 11 deletions

View file

@ -0,0 +1,73 @@
/*
* 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';
interface SetValueOptions {
clearWithKeyboard?: boolean;
typeCharByChar?: boolean;
}
export function MachineLearningCommonProvider({ getService }: FtrProviderContext) {
const log = getService('log');
const retry = getService('retry');
const testSubjects = getService('testSubjects');
const find = getService('find');
return {
async setValueWithChecks(
selector: string,
text: string,
options: SetValueOptions = {}
): Promise<void> {
return await retry.try(async () => {
const { clearWithKeyboard = false, typeCharByChar = false } = options;
log.debug(`TestSubjects.setValueWithChecks(${selector}, ${text})`);
await testSubjects.click(selector);
// in case the input element is actually a child of the testSubject, we
// call clearValue() and type() on the element that is focused after
// clicking on the testSubject
const input = await find.activeElement();
await retry.tryForTime(5000, async () => {
let currentValue = await input.getAttribute('value');
if (currentValue !== '') {
if (clearWithKeyboard === true) {
await input.clearValueWithKeyboard();
} else {
await input.clearValue();
}
currentValue = await input.getAttribute('value');
}
if (currentValue === '') {
return true;
} else {
throw new Error(`Expected input to be empty, but got value '${currentValue}'`);
}
});
for (const chr of text) {
await retry.tryForTime(5000, async () => {
const oldValue = await input.getAttribute('value');
await input.type(chr, { charByChar: typeCharByChar });
await retry.tryForTime(1000, async () => {
const newValue = await input.getAttribute('value');
if (newValue === `${oldValue}${chr}`) {
return true;
} else {
throw new Error(
`After typing character '${chr}', the new value in the input should be '${oldValue}${chr}' (got ${newValue})`
);
}
});
});
}
});
},
};
}

View file

@ -6,6 +6,7 @@
export { MachineLearningAnomalyExplorerProvider } from './anomaly_explorer';
export { MachineLearningAPIProvider } from './api';
export { MachineLearningCommonProvider } from './common';
export { MachineLearningCustomUrlsProvider } from './custom_urls';
export { MachineLearningDataFrameAnalyticsProvider } from './data_frame_analytics';
export { MachineLearningDataFrameAnalyticsCreationProvider } from './data_frame_analytics_creation';

View file

@ -4,10 +4,15 @@
* you may not use this file except in compliance with the Elastic License.
*/
import expect from '@kbn/expect';
import { ProvidedType } from '@kbn/test/types/ftr';
import { FtrProviderContext } from '../../ftr_provider_context';
import { MachineLearningCommonProvider } from './common';
export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProviderContext) {
export function MachineLearningJobWizardAdvancedProvider(
{ getService }: FtrProviderContext,
mlCommon: ProvidedType<typeof MachineLearningCommonProvider>
) {
const comboBox = getService('comboBox');
const testSubjects = getService('testSubjects');
const retry = getService('retry');
@ -44,7 +49,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},
async setQueryDelay(queryDelay: string) {
await testSubjects.setValue('mlJobWizardInputQueryDelay', queryDelay, {
await mlCommon.setValueWithChecks('mlJobWizardInputQueryDelay', queryDelay, {
clearWithKeyboard: true,
typeCharByChar: true,
});
@ -61,7 +66,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},
async setFrequency(frequency: string) {
await testSubjects.setValue('mlJobWizardInputFrequency', frequency, {
await mlCommon.setValueWithChecks('mlJobWizardInputFrequency', frequency, {
clearWithKeyboard: true,
typeCharByChar: true,
});
@ -78,7 +83,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},
async setScrollSize(scrollSize: string) {
await testSubjects.setValue('mlJobWizardInputScrollSize', scrollSize, {
await mlCommon.setValueWithChecks('mlJobWizardInputScrollSize', scrollSize, {
clearWithKeyboard: true,
typeCharByChar: true,
});
@ -257,7 +262,7 @@ export function MachineLearningJobWizardAdvancedProvider({ getService }: FtrProv
},
async setDetectorDescription(description: string) {
await testSubjects.setValue('mlAdvancedDetectorDescriptionInput', description, {
await mlCommon.setValueWithChecks('mlAdvancedDetectorDescriptionInput', description, {
clearWithKeyboard: true,
});
await this.assertDetectorDescriptionValue(description);

View file

@ -7,10 +7,12 @@ import expect from '@kbn/expect';
import { ProvidedType } from '@kbn/test/types/ftr';
import { FtrProviderContext } from '../../ftr_provider_context';
import { MachineLearningCommonProvider } from './common';
import { MachineLearningCustomUrlsProvider } from './custom_urls';
export function MachineLearningJobWizardCommonProvider(
{ getService }: FtrProviderContext,
mlCommon: ProvidedType<typeof MachineLearningCommonProvider>,
customUrls: ProvidedType<typeof MachineLearningCustomUrlsProvider>
) {
const comboBox = getService('comboBox');
@ -113,7 +115,7 @@ export function MachineLearningJobWizardCommonProvider(
},
async setBucketSpan(bucketSpan: string) {
await testSubjects.setValue('mlJobWizardInputBucketSpan', bucketSpan, {
await mlCommon.setValueWithChecks('mlJobWizardInputBucketSpan', bucketSpan, {
clearWithKeyboard: true,
typeCharByChar: true,
});
@ -130,7 +132,9 @@ export function MachineLearningJobWizardCommonProvider(
},
async setJobId(jobId: string) {
await testSubjects.setValue('mlJobWizardInputJobId', jobId, { clearWithKeyboard: true });
await mlCommon.setValueWithChecks('mlJobWizardInputJobId', jobId, {
clearWithKeyboard: true,
});
await this.assertJobIdValue(jobId);
},
@ -146,7 +150,7 @@ export function MachineLearningJobWizardCommonProvider(
},
async setJobDescription(jobDescription: string) {
await testSubjects.setValue('mlJobWizardInputJobDescription', jobDescription, {
await mlCommon.setValueWithChecks('mlJobWizardInputJobDescription', jobDescription, {
clearWithKeyboard: true,
});
await this.assertJobDescriptionValue(jobDescription);
@ -307,7 +311,7 @@ export function MachineLearningJobWizardCommonProvider(
await this.ensureAdvancedSectionOpen();
subj = advancedSectionSelector(subj);
}
await testSubjects.setValue(subj, modelMemoryLimit, { clearWithKeyboard: true });
await mlCommon.setValueWithChecks(subj, modelMemoryLimit, { clearWithKeyboard: true });
await this.assertModelMemoryLimitValue(modelMemoryLimit, {
withAdvancedSection: sectionOptions.withAdvancedSection,
});

View file

@ -9,6 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
import {
MachineLearningAnomalyExplorerProvider,
MachineLearningAPIProvider,
MachineLearningCommonProvider,
MachineLearningCustomUrlsProvider,
MachineLearningDataFrameAnalyticsProvider,
MachineLearningDataFrameAnalyticsCreationProvider,
@ -29,6 +30,8 @@ import {
} from './machine_learning';
export function MachineLearningProvider(context: FtrProviderContext) {
const common = MachineLearningCommonProvider(context);
const anomalyExplorer = MachineLearningAnomalyExplorerProvider(context);
const api = MachineLearningAPIProvider(context);
const customUrls = MachineLearningCustomUrlsProvider(context);
@ -41,8 +44,8 @@ export function MachineLearningProvider(context: FtrProviderContext) {
const jobSourceSelection = MachineLearningJobSourceSelectionProvider(context);
const jobTable = MachineLearningJobTableProvider(context);
const jobTypeSelection = MachineLearningJobTypeSelectionProvider(context);
const jobWizardAdvanced = MachineLearningJobWizardAdvancedProvider(context);
const jobWizardCommon = MachineLearningJobWizardCommonProvider(context, customUrls);
const jobWizardAdvanced = MachineLearningJobWizardAdvancedProvider(context, common);
const jobWizardCommon = MachineLearningJobWizardCommonProvider(context, common, customUrls);
const jobWizardMultiMetric = MachineLearningJobWizardMultiMetricProvider(context);
const jobWizardPopulation = MachineLearningJobWizardPopulationProvider(context);
const navigation = MachineLearningNavigationProvider(context);