Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional tests: convert more test/services to TS #45176

Merged
merged 7 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion test/functional/apps/visualize/_tag_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function ({ getService, getPageObjects }) {
];

await inspector.open();
await await inspector.setTablePageSize('50');
await await inspector.setTablePageSize(50);
await inspector.expectTableData(expectedTableData);
});

Expand Down
111 changes: 68 additions & 43 deletions test/functional/services/combo_box.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,32 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
// wrapper around EuiComboBox interactions
class ComboBox {
/**
* set value inside combobox
* Finds combobox element and sets specified value
*
* @param comboBoxSelector test subject selector
* @param value
* @param comboBoxSelector data-test-subj selector
* @param value option text
*/

public async set(comboBoxSelector: string, value: string): Promise<void> {
log.debug(`comboBox.set, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
await this.setElement(comboBox, value);
}

private async clickOption(isMouseClick: boolean, element: WebElementWrapper) {
/**
* Clicks option in combobox dropdown
*
* @param isMouseClick if 'true', click will be done with mouse
* @param element element that wraps up option
*/
private async clickOption(isMouseClick: boolean, element: WebElementWrapper): Promise<void> {
return isMouseClick ? await element.clickMouseButton() : await element.click();
}

/**
* set value inside combobox element
* Sets value for specified combobox element
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
* @param value
*/
public async setElement(
Expand All @@ -69,7 +76,7 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

comboBoxElement.scrollIntoViewIfNecessary();
await this._filterOptionsList(comboBoxElement, value);
await this.setFilterValue(comboBoxElement, value);
await this.openOptionsList(comboBoxElement);

if (value !== undefined) {
Expand All @@ -93,30 +100,42 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* This method set custom value to comboBox.
* Finds combobox element and sets custom value
* It applies changes by pressing Enter key. Sometimes it may lead to auto-submitting a form.
*
* @param comboBoxSelector test subject selector
* @param value
* @param comboBoxSelector data-test-subj selector
* @param value option text
*/
async setCustom(comboBoxSelector: string, value: string) {
public async setCustom(comboBoxSelector: string, value: string): Promise<void> {
log.debug(`comboBox.setCustom, comboBoxSelector: ${comboBoxSelector}, value: ${value}`);
const comboBoxElement = await testSubjects.find(comboBoxSelector);
await this._filterOptionsList(comboBoxElement, value);
await this.setFilterValue(comboBoxElement, value);
await PageObjects.common.pressEnterKey();
await this.closeOptionsList(comboBoxElement);
}

async filterOptionsList(comboBoxSelector: string, filterValue: string) {
/**
* Finds combobox element and sets filter value
*
* @param comboBoxSelector data-test-subj selector
* @param filterValue text
*/
public async filterOptionsList(comboBoxSelector: string, filterValue: string): Promise<void> {
log.debug(
`comboBox.filterOptionsList, comboBoxSelector: ${comboBoxSelector}, filter: ${filterValue}`
);
const comboBox = await testSubjects.find(comboBoxSelector);
await this._filterOptionsList(comboBox, filterValue);
await this.setFilterValue(comboBox, filterValue);
await this.closeOptionsList(comboBox);
}

private async _filterOptionsList(
/**
* Sets new filter value in specified combobox element
*
* @param comboBoxElement element that wraps up EuiComboBox
* @param filterValue text
*/
private async setFilterValue(
comboBoxElement: WebElementWrapper,
filterValue: string
): Promise<void> {
Expand All @@ -127,10 +146,20 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
await this.waitForOptionsListLoading(comboBoxElement);
}

/**
* Waits options list to be loaded
*
* @param comboBoxElement element that wraps up EuiComboBox
*/
private async waitForOptionsListLoading(comboBoxElement: WebElementWrapper): Promise<void> {
await comboBoxElement.waitForDeletedByCssSelector('.euiLoadingSpinner');
}

/**
* Returns options list as a single string
*
* @param comboBoxSelector data-test-subj selector
*/
public async getOptionsList(comboBoxSelector: string): Promise<string> {
log.debug(`comboBox.getOptionsList, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
Expand All @@ -148,37 +177,33 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
return optionsText;
}

/**
* Finds combobox element and checks if it has selected options
*
* @param comboBoxSelector data-test-subj selector
*/
public async doesComboBoxHaveSelectedOptions(comboBoxSelector: string): Promise<boolean> {
log.debug(`comboBox.doesComboBoxHaveSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
const comboBox = await testSubjects.find(comboBoxSelector);
const selectedOptions = await comboBox.findAllByClassName(
'euiComboBoxPill',
WAIT_FOR_EXISTS_TIME
);
return selectedOptions.length > 0;
const $ = await comboBox.parseDomContent();
return $('.euiComboBoxPill').toArray().length > 0;
dmlemeshko marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* Returns selected options
* @param comboBoxSelector data-test-subj selector
*/
public async getComboBoxSelectedOptions(comboBoxSelector: string): Promise<string[]> {
log.debug(`comboBox.getComboBoxSelectedOptions, comboBoxSelector: ${comboBoxSelector}`);
return await retry.try(async () => {
const comboBox = await testSubjects.find(comboBoxSelector);
const selectedOptions = await comboBox.findAllByClassName(
'euiComboBoxPill',
WAIT_FOR_EXISTS_TIME
);
if (selectedOptions.length === 0) {
return [];
}
return Promise.all(
selectedOptions.map(async optionElement => {
return await optionElement.getVisibleText();
})
);
});
const comboBox = await testSubjects.find(comboBoxSelector);
const $ = await comboBox.parseDomContent();
return $('.euiComboBoxPill')
.toArray()
.map(option => $(option).text());
dmlemeshko marked this conversation as resolved.
Show resolved Hide resolved
}

/**
* clearing value from combobox
* Finds combobox element and clears value in the input field by clicking clear button
*
* @param comboBoxSelector data-test-subj selector
*/
Expand Down Expand Up @@ -212,9 +237,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* closing option list for combobox
* Closes options list
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
*/
public async closeOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
Expand All @@ -225,9 +250,9 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* opened list of options for combobox
* Opens options list
*
* @param comboBoxElement
* @param comboBoxElement element that wraps up EuiComboBox
*/
public async openOptionsList(comboBoxElement: WebElementWrapper): Promise<void> {
const isOptionsListOpen = await testSubjects.exists('comboBoxOptionsList');
Expand All @@ -240,10 +265,10 @@ export function ComboBoxProvider({ getService, getPageObjects }: FtrProviderCont
}

/**
* check if option is already selected
* Checks if specified option is already selected
*
* @param comboBoxElement
* @param value
* @param comboBoxElement element that wraps up EuiComboBox
* @param value option text
*/
public async isOptionSelected(
comboBoxElement: WebElementWrapper,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@
* under the License.
*/

export function EmbeddingProvider({ getService, getPageObjects }) {
import { FtrProviderContext } from '../ftr_provider_context';

export function EmbeddingProvider({ getService, getPageObjects }: FtrProviderContext) {
wayneseymour marked this conversation as resolved.
Show resolved Hide resolved
const browser = getService('browser');
const log = getService('log');
const PageObjects = getPageObjects(['header']);

class Embedding {

async openInEmbeddedMode() {
/**
* Opens current page in embeded mode
*/
public async openInEmbeddedMode(): Promise<void> {
const currentUrl = await browser.getCurrentUrl();
log.debug(`Opening in embedded mode: ${currentUrl}`);
await browser.get(`${currentUrl}&embed=true`);
await PageObjects.header.waitUntilLoadingHasFinished();
}

}

return new Embedding();
Expand Down
Loading