mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
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
This commit is contained in:
parent
a4b72f2ad7
commit
8ee85f8fed
1 changed files with 44 additions and 3 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue