Skip to content

Commit

Permalink
Add some testSubject helpers (elastic#13305)
Browse files Browse the repository at this point in the history
* [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 8ee85f8)
  • Loading branch information
spalger committed Aug 5, 2017
1 parent b1f6ddd commit 679d8ad
Showing 1 changed file with 44 additions and 3 deletions.
47 changes: 44 additions & 3 deletions test/functional/services/test_subjects.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 679d8ad

Please sign in to comment.