From 4078cfa7231b17896cbf049a1d3ac5120fd685d3 Mon Sep 17 00:00:00 2001 From: Robert Oskamp Date: Wed, 21 Oct 2020 17:10:30 +0200 Subject: [PATCH] [ML] Functional tests - stabilize typing with checks service method --- x-pack/test/functional/services/ml/common_ui.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/x-pack/test/functional/services/ml/common_ui.ts b/x-pack/test/functional/services/ml/common_ui.ts index 319dc54fa6421..c3ee05db599a9 100644 --- a/x-pack/test/functional/services/ml/common_ui.ts +++ b/x-pack/test/functional/services/ml/common_ui.ts @@ -35,6 +35,7 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte // clicking on the testSubject const input = await find.activeElement(); + // make sure that clearing the element's value works await retry.tryForTime(5000, async () => { let currentValue = await input.getAttribute('value'); if (currentValue !== '') { @@ -53,6 +54,7 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte } }); + // make sure that typing a character really adds that character to the input value for (const chr of text) { await retry.tryForTime(5000, async () => { const oldValue = await input.getAttribute('value'); @@ -70,6 +72,16 @@ export function MachineLearningCommonUIProvider({ getService }: FtrProviderConte }); }); } + + // make sure that finally the complete text is entered + // this is needed because sometimes the field value is reset while typing + // and the above character checking might not catch it due to bad timing + const currentValue = await input.getAttribute('value'); + if (currentValue !== text) { + throw new Error( + `Expected input '${selector}' to have the value '${text}' (got ${currentValue})` + ); + } }); },