From 679d8ad738cf51c84394cb9118bf1a099f056fe3 Mon Sep 17 00:00:00 2001 From: Spencer Date: Fri, 4 Aug 2017 18:49:12 -0700 Subject: [PATCH] Add some testSubject helpers (#13305) * [testSubjects] add getVisibleTextAll() helper * [testSubjects] add isSelected() and isSelectedAll() helpers * [testSubjects/setValue] support wrappers around inputs * [testSubjects] add isEnabled() helper * fix typo (cherry picked from commit 8ee85f8fedeb344c61c7537389c19da56e1c1bb5) --- test/functional/services/test_subjects.js | 47 +++++++++++++++++++++-- 1 file changed, 44 insertions(+), 3 deletions(-) diff --git a/test/functional/services/test_subjects.js b/test/functional/services/test_subjects.js index 23f3ac56ac5e2..84aef32ba1629 100644 --- a/test/functional/services/test_subjects.js +++ b/test/functional/services/test_subjects.js @@ -1,5 +1,8 @@ import testSubjSelector from '@spalger/test-subj-selector'; -import { filter as filterAsync } from 'bluebird'; +import { + filter as filterAsync, + map as mapAsync, +} from 'bluebird'; export function TestSubjectsProvider({ getService }) { const log = getService('log'); @@ -51,19 +54,57 @@ export function TestSubjectsProvider({ getService }) { async setValue(selector, text) { return await retry.try(async () => { - const input = await this.find(selector); - await input.click(); + const element = await this.find(selector); + await element.click(); + + // 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 remote.getActiveElement(); await input.clearValue(); await input.type(text); }); } + async isEnabled(selector) { + return await retry.try(async () => { + const element = await this.find(selector); + return await element.isEnabled(); + }); + } + + async isSelected(selector) { + return await retry.try(async () => { + const element = await this.find(selector); + return await element.isSelected(); + }); + } + + async isSelectedAll(selectorAll) { + return await this._mapAll(selectorAll, async (element) => { + return await element.isSelected(); + }); + } + async getVisibleText(selector) { return await retry.try(async () => { const element = await this.find(selector); return await element.getVisibleText(); }); } + + async getVisibleTextAll(selectorAll) { + return await this._mapAll(selectorAll, async (element) => { + return await element.getVisibleText(); + }); + } + + async _mapAll(selectorAll, mapFn) { + return await retry.try(async () => { + const elements = await this.findAll(selectorAll); + return await mapAsync(elements, mapFn); + }); + } } return new TestSubjects();