2017-04-12 00:01:06 +02:00
|
|
|
export function HeaderPageProvider({ getService, getPageObjects }) {
|
|
|
|
const config = getService('config');
|
|
|
|
const remote = getService('remote');
|
|
|
|
const log = getService('log');
|
|
|
|
const retry = getService('retry');
|
2017-05-06 13:36:16 +02:00
|
|
|
const find = getService('find');
|
2017-04-12 00:01:06 +02:00
|
|
|
const testSubjects = getService('testSubjects');
|
|
|
|
const PageObjects = getPageObjects(['common']);
|
|
|
|
|
|
|
|
const defaultFindTimeout = config.get('timeouts.find');
|
|
|
|
|
|
|
|
class HeaderPage {
|
2017-05-31 18:29:08 +02:00
|
|
|
|
2017-04-12 00:01:06 +02:00
|
|
|
async clickSelector(selector) {
|
2017-06-02 18:38:47 +02:00
|
|
|
log.debug(`clickSelector(${selector})`);
|
|
|
|
await retry.try(async () => await remote.findByCssSelector(selector).click());
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async clickDiscover() {
|
|
|
|
log.debug('click Discover tab');
|
|
|
|
await this.clickSelector('a[href*=\'discover\']');
|
2017-05-31 18:29:08 +02:00
|
|
|
await PageObjects.common.waitForTopNavToBeVisible();
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async clickVisualize() {
|
|
|
|
log.debug('click Visualize tab');
|
|
|
|
await this.clickSelector('a[href*=\'visualize\']');
|
2017-05-31 18:29:08 +02:00
|
|
|
await PageObjects.common.waitForTopNavToBeVisible();
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async clickDashboard() {
|
|
|
|
log.debug('click Dashboard tab');
|
|
|
|
await this.clickSelector('a[href*=\'dashboard\']');
|
2017-05-31 18:29:08 +02:00
|
|
|
await PageObjects.common.waitForTopNavToBeVisible();
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 09:56:37 +01:00
|
|
|
async clickManagement() {
|
|
|
|
log.debug('click Management tab');
|
|
|
|
await this.clickSelector('a[href*=\'management\']');
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
|
|
|
}
|
|
|
|
|
2017-04-12 00:01:06 +02:00
|
|
|
async clickSettings() {
|
|
|
|
log.debug('click Settings tab');
|
|
|
|
await this.clickSelector('a[href*=\'settings\']');
|
|
|
|
}
|
|
|
|
|
|
|
|
async clickTimepicker() {
|
|
|
|
await testSubjects.click('globalTimepickerButton');
|
|
|
|
}
|
|
|
|
|
|
|
|
async clickQuickButton() {
|
|
|
|
await retry.try(async () => {
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
2017-12-19 01:43:32 +01:00
|
|
|
await testSubjects.click('timepicker-quick-button');
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async isTimepickerOpen() {
|
2017-11-20 15:55:28 +01:00
|
|
|
return await testSubjects.exists('timePicker');
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async isAbsoluteSectionShowing() {
|
|
|
|
log.debug('isAbsoluteSectionShowing');
|
|
|
|
return await PageObjects.common.doesCssSelectorExist('input[ng-model=\'absolute.from\']');
|
|
|
|
}
|
|
|
|
|
|
|
|
async showAbsoluteSection() {
|
|
|
|
log.debug('showAbsoluteSection');
|
|
|
|
const isAbsoluteSectionShowing = await this.isAbsoluteSectionShowing();
|
|
|
|
if (!isAbsoluteSectionShowing) {
|
|
|
|
await retry.try(async () => {
|
|
|
|
await remote.setFindTimeout(defaultFindTimeout);
|
2017-12-19 01:43:32 +01:00
|
|
|
await testSubjects.click('timepicker-absolute-button');
|
2017-04-12 00:01:06 +02:00
|
|
|
// Check to make sure one of the elements on the absolute section is showing.
|
|
|
|
await this.getFromTime();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async getFromTime() {
|
|
|
|
log.debug('getFromTime');
|
|
|
|
return await retry.try(async () => {
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
await this.showAbsoluteSection();
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
return await remote.findByCssSelector('input[ng-model=\'absolute.from\']')
|
2017-11-15 02:16:59 +01:00
|
|
|
.getProperty('value');
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getToTime() {
|
|
|
|
log.debug('getToTime');
|
|
|
|
return await retry.try(async () => {
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
await this.showAbsoluteSection();
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
return await remote.findByCssSelector('input[ng-model=\'absolute.to\']')
|
2017-11-15 02:16:59 +01:00
|
|
|
.getProperty('value');
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async setFromTime(timeString) {
|
|
|
|
log.debug(`setFromTime: ${timeString}`);
|
|
|
|
await retry.try(async () => {
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
await this.showAbsoluteSection();
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
await remote.findByCssSelector('input[ng-model=\'absolute.from\']')
|
2017-11-15 02:16:59 +01:00
|
|
|
.clearValue()
|
|
|
|
.type(timeString);
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async setToTime(timeString) {
|
|
|
|
log.debug(`setToTime: ${timeString}`);
|
|
|
|
await retry.try(async () => {
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
await this.showAbsoluteSection();
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
await remote.findByCssSelector('input[ng-model=\'absolute.to\']')
|
2017-11-15 02:16:59 +01:00
|
|
|
.clearValue()
|
|
|
|
.type(timeString);
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async clickGoButton() {
|
|
|
|
log.debug('clickGoButton');
|
|
|
|
await retry.try(async () => {
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
2017-04-25 01:35:58 +02:00
|
|
|
await testSubjects.click('timepickerGoButton');
|
2017-04-12 00:01:06 +02:00
|
|
|
await this.waitUntilLoadingHasFinished();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async ensureTimePickerIsOpen() {
|
2017-11-20 15:55:28 +01:00
|
|
|
log.debug('ensureTimePickerIsOpen');
|
2017-04-12 00:01:06 +02:00
|
|
|
const isOpen = await this.isTimepickerOpen();
|
|
|
|
if (!isOpen) {
|
2017-11-20 15:55:28 +01:00
|
|
|
await retry.try(async () => {
|
|
|
|
await this.clickTimepicker();
|
|
|
|
const isOpen = await this.isTimepickerOpen();
|
|
|
|
if (!isOpen) throw new Error('Time picker still not open, try again.');
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async setAbsoluteRange(fromTime, toTime) {
|
|
|
|
log.debug(`Setting absolute range to ${fromTime} to ${toTime}`);
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
log.debug('--Clicking Absolute button');
|
|
|
|
await this.showAbsoluteSection();
|
|
|
|
log.debug('--Setting From Time : ' + fromTime);
|
|
|
|
await this.setFromTime(fromTime);
|
|
|
|
log.debug('--Setting To Time : ' + toTime);
|
|
|
|
await this.setToTime(toTime);
|
|
|
|
await this.clickGoButton();
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
async setQuickTime(quickTime) {
|
|
|
|
await this.ensureTimePickerIsOpen();
|
|
|
|
log.debug('--Clicking Quick button');
|
|
|
|
await this.clickQuickButton();
|
|
|
|
await remote.setFindTimeout(defaultFindTimeout)
|
2017-11-15 02:16:59 +01:00
|
|
|
.findByLinkText(quickTime).click();
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2018-02-09 06:07:17 +01:00
|
|
|
async getAutoRefreshState() {
|
|
|
|
return testSubjects.getAttribute('globalTimepickerAutoRefreshButton', 'data-test-subj-state');
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the auto refresh state is active and to pause it
|
|
|
|
async pauseAutoRefresh() {
|
|
|
|
let result = false;
|
|
|
|
if (await this.getAutoRefreshState() === 'active') {
|
|
|
|
await testSubjects.click('globalTimepickerAutoRefreshButton');
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check if the auto refresh state is inactive and to resume it
|
|
|
|
async resumeAutoRefresh() {
|
|
|
|
let result = false;
|
|
|
|
if (await this.getAutoRefreshState() === 'inactive') {
|
|
|
|
await testSubjects.click('globalTimepickerAutoRefreshButton');
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-05-06 13:36:16 +02:00
|
|
|
async getToastMessage(findTimeout = defaultFindTimeout) {
|
|
|
|
const toastMessage =
|
|
|
|
await find.displayedByCssSelector('kbn-truncated.toast-message.ng-isolate-scope', findTimeout);
|
2017-08-30 15:42:04 +02:00
|
|
|
const messageText = await toastMessage.getVisibleText();
|
|
|
|
log.debug(`getToastMessage: ${messageText}`);
|
|
|
|
return messageText;
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async waitForToastMessageGone() {
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
await remote.waitForDeletedByCssSelector('kbn-truncated.toast-message');
|
|
|
|
}
|
|
|
|
|
|
|
|
async clickToastOK() {
|
|
|
|
log.debug('clickToastOK');
|
|
|
|
await retry.try(async () => {
|
|
|
|
remote.setFindTimeout(defaultFindTimeout);
|
|
|
|
await remote.findByCssSelector('button[ng-if="notif.accept"]')
|
2017-11-15 02:16:59 +01:00
|
|
|
.click();
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async waitUntilLoadingHasFinished() {
|
|
|
|
try {
|
|
|
|
await this.isGlobalLoadingIndicatorVisible();
|
|
|
|
} catch (exception) {
|
|
|
|
if (exception.name === 'ElementNotVisible') {
|
|
|
|
// selenium might just have been too slow to catch it
|
|
|
|
} else {
|
|
|
|
throw exception;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
await this.isGlobalLoadingIndicatorHidden();
|
|
|
|
}
|
|
|
|
|
|
|
|
async isGlobalLoadingIndicatorVisible() {
|
2017-07-27 21:26:09 +02:00
|
|
|
log.debug('isGlobalLoadingIndicatorVisible');
|
|
|
|
return await testSubjects.exists('globalLoadingIndicator');
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async isGlobalLoadingIndicatorHidden() {
|
2017-07-27 21:26:09 +02:00
|
|
|
log.debug('isGlobalLoadingIndicatorHidden');
|
|
|
|
return await find.byCssSelector('[data-test-subj="globalLoadingIndicator"].ng-hide', defaultFindTimeout * 10);
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async getPrettyDuration() {
|
2017-07-25 21:07:02 +02:00
|
|
|
return await testSubjects.getVisibleText('globalTimepickerRange');
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
async isSharedTimefilterEnabled() {
|
2017-07-25 21:07:02 +02:00
|
|
|
return await find.existsByCssSelector('[shared-timefilter=true]');
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return new HeaderPage();
|
|
|
|
}
|