2018-05-29 05:06:30 +02:00
|
|
|
/*
|
|
|
|
* Licensed to Elasticsearch B.V. under one or more contributor
|
|
|
|
* license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright
|
|
|
|
* ownership. Elasticsearch B.V. licenses this file to you under
|
|
|
|
* the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
|
|
|
|
2017-05-11 21:07:23 +02:00
|
|
|
import { delay } from 'bluebird';
|
2018-06-19 06:05:21 +02:00
|
|
|
import expect from 'expect.js';
|
2017-04-12 00:01:06 +02:00
|
|
|
|
2017-05-18 03:53:45 +02:00
|
|
|
import getUrl from '../../../src/test_utils/get_url';
|
2017-04-12 00:01:06 +02:00
|
|
|
|
2017-06-05 23:18:30 +02:00
|
|
|
export function CommonPageProvider({ getService, getPageObjects }) {
|
2017-04-12 00:01:06 +02:00
|
|
|
const log = getService('log');
|
|
|
|
const config = getService('config');
|
2018-11-29 23:30:47 +01:00
|
|
|
const browser = getService('browser');
|
2017-04-12 00:01:06 +02:00
|
|
|
const retry = getService('retry');
|
2017-07-27 21:26:09 +02:00
|
|
|
const find = getService('find');
|
2019-01-18 21:39:01 +01:00
|
|
|
const globalNav = getService('globalNav');
|
2017-04-12 00:01:06 +02:00
|
|
|
const testSubjects = getService('testSubjects');
|
|
|
|
const kibanaServer = getService('kibanaServer');
|
|
|
|
const PageObjects = getPageObjects(['shield']);
|
|
|
|
|
|
|
|
const defaultTryTimeout = config.get('timeouts.try');
|
|
|
|
const defaultFindTimeout = config.get('timeouts.find');
|
|
|
|
|
|
|
|
class CommonPage {
|
|
|
|
getHostPort() {
|
|
|
|
return getUrl.baseUrl(config.get('servers.kibana'));
|
|
|
|
}
|
|
|
|
|
|
|
|
getEsHostPort() {
|
|
|
|
return getUrl.baseUrl(config.get('servers.elasticsearch'));
|
|
|
|
}
|
|
|
|
|
2017-05-15 23:04:16 +02:00
|
|
|
/**
|
2017-05-18 03:53:45 +02:00
|
|
|
* @param {string} appName As defined in the apps config
|
2017-05-15 23:04:16 +02:00
|
|
|
* @param {string} subUrl The route after the hash (#)
|
|
|
|
*/
|
2018-07-12 15:31:43 +02:00
|
|
|
async navigateToUrl(appName, subUrl) {
|
2017-10-10 14:50:56 +02:00
|
|
|
const appConfig = {
|
|
|
|
...config.get(['apps', appName]),
|
2017-04-12 00:01:06 +02:00
|
|
|
// Overwrite the default hash with the URL we really want.
|
|
|
|
hash: `${appName}/${subUrl}`,
|
2017-10-10 14:50:56 +02:00
|
|
|
};
|
2017-04-12 00:01:06 +02:00
|
|
|
|
|
|
|
const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig);
|
2018-09-11 17:46:10 +02:00
|
|
|
await retry.try(async () => {
|
|
|
|
log.debug(`navigateToUrl ${appUrl}`);
|
2018-11-29 23:30:47 +01:00
|
|
|
await browser.get(appUrl);
|
2018-09-11 17:46:10 +02:00
|
|
|
const currentUrl = await this.loginIfPrompted(appUrl);
|
|
|
|
if (!currentUrl.includes(appUrl)) {
|
|
|
|
throw new Error(`expected ${currentUrl}.includes(${appUrl})`);
|
|
|
|
}
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 15:31:43 +02:00
|
|
|
|
|
|
|
async loginIfPrompted(appUrl) {
|
2018-11-29 23:30:47 +01:00
|
|
|
let currentUrl = await browser.getCurrentUrl();
|
2018-07-12 15:31:43 +02:00
|
|
|
log.debug(`currentUrl = ${currentUrl}\n appUrl = ${appUrl}`);
|
2018-11-29 23:30:47 +01:00
|
|
|
await find.byCssSelector('[data-test-subj="kibanaChrome"]', defaultTryTimeout * 2);
|
2018-07-12 15:31:43 +02:00
|
|
|
const loginPage = currentUrl.includes('/login');
|
|
|
|
const wantedLoginPage = appUrl.includes('/login') || appUrl.includes('/logout');
|
|
|
|
|
|
|
|
if (loginPage && !wantedLoginPage) {
|
|
|
|
log.debug(`Found login page. Logging in with username = ${config.get('servers.kibana.username')}`);
|
|
|
|
await PageObjects.shield.login(
|
|
|
|
config.get('servers.kibana.username'),
|
|
|
|
config.get('servers.kibana.password')
|
|
|
|
);
|
2018-11-29 23:30:47 +01:00
|
|
|
await find.byCssSelector('[data-test-subj="kibanaChrome"] nav:not(.ng-hide)', 20000);
|
|
|
|
await browser.get(appUrl);
|
|
|
|
currentUrl = await browser.getCurrentUrl();
|
2018-07-12 15:31:43 +02:00
|
|
|
log.debug(`Finished login process currentUrl = ${currentUrl}`);
|
|
|
|
}
|
|
|
|
return currentUrl;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-31 17:44:23 +01:00
|
|
|
/**
|
|
|
|
* @param {string} appName - name of the app
|
|
|
|
* @param {object} [opts] - optional options object
|
|
|
|
* @param {object} [opts.appConfig] - overrides for appConfig, e.g. { pathname, hash }
|
|
|
|
*/
|
|
|
|
navigateToApp(appName, opts = { appConfig: {} }) {
|
2017-04-12 00:01:06 +02:00
|
|
|
const self = this;
|
2019-01-31 17:44:23 +01:00
|
|
|
const appUrl = getUrl.noAuth(config.get('servers.kibana'), {
|
|
|
|
...config.get(['apps', appName]),
|
|
|
|
...opts.appConfig,
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
log.debug('navigating to ' + appName + ' url: ' + appUrl);
|
|
|
|
|
|
|
|
function navigateTo(url) {
|
|
|
|
return retry.try(function () {
|
|
|
|
// since we're using hash URLs, always reload first to force re-render
|
|
|
|
return kibanaServer.uiSettings.getDefaultIndex()
|
2017-11-15 02:16:59 +01:00
|
|
|
.then(function (defaultIndex) {
|
|
|
|
if (appName === 'discover' || appName === 'visualize' || appName === 'dashboard') {
|
|
|
|
if (!defaultIndex) {
|
2018-05-29 18:58:36 +02:00
|
|
|
// https://github.com/elastic/kibana/issues/7496
|
|
|
|
// Even though most tests are using esClient to set the default index, sometimes Kibana clobbers
|
|
|
|
// that change. If we got here, fix it.
|
2017-11-15 02:16:59 +01:00
|
|
|
log.debug(' >>>>>>>> WARNING Navigating to [' + appName + '] with defaultIndex=' + defaultIndex);
|
|
|
|
log.debug(' >>>>>>>> Setting defaultIndex to "logstash-*""');
|
|
|
|
return kibanaServer.uiSettings.update({
|
2018-07-12 15:31:43 +02:00
|
|
|
'defaultIndex': 'logstash-*',
|
2017-11-15 02:16:59 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
log.debug('navigate to: ' + url);
|
2018-11-29 23:30:47 +01:00
|
|
|
return browser.get(url);
|
2017-11-15 02:16:59 +01:00
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
return self.sleep(700);
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
log.debug('returned from get, calling refresh');
|
2018-11-29 23:30:47 +01:00
|
|
|
return browser.refresh();
|
2017-11-15 02:16:59 +01:00
|
|
|
})
|
|
|
|
.then(async function () {
|
2018-07-12 15:31:43 +02:00
|
|
|
const currentUrl = await self.loginIfPrompted(appUrl);
|
2017-05-19 04:33:53 +02:00
|
|
|
|
2017-11-15 02:16:59 +01:00
|
|
|
if (currentUrl.includes('app/kibana')) {
|
|
|
|
await testSubjects.find('kibanaChrome');
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.then(async function () {
|
2018-11-29 23:30:47 +01:00
|
|
|
const currentUrl = (await browser.getCurrentUrl()).replace(/\/\/\w+:\w+@/, '//');
|
2017-11-15 02:16:59 +01:00
|
|
|
const maxAdditionalLengthOnNavUrl = 230;
|
|
|
|
// On several test failures at the end of the TileMap test we try to navigate back to
|
|
|
|
// Visualize so we can create the next Vertical Bar Chart, but we can see from the
|
|
|
|
// logging and the screenshot that it's still on the TileMap page. Why didn't the "get"
|
|
|
|
// with a new timestamped URL go? I thought that sleep(700) between the get and the
|
|
|
|
// refresh would solve the problem but didn't seem to always work.
|
|
|
|
// So this hack fails the navSuccessful check if the currentUrl doesn't match the
|
|
|
|
// appUrl plus up to 230 other chars.
|
|
|
|
// Navigating to Settings when there is a default index pattern has a URL length of 196
|
|
|
|
// (from debug output). Some other tabs may also be long. But a rather simple configured
|
|
|
|
// visualization is about 1000 chars long. So at least we catch that case.
|
|
|
|
|
|
|
|
// Browsers don't show the ':port' if it's 80 or 443 so we have to
|
|
|
|
// remove that part so we can get a match in the tests.
|
2019-01-18 23:46:15 +01:00
|
|
|
const navSuccessful = new RegExp(appUrl.replace(':80/', '/').replace(':443/', '/')
|
2018-05-29 18:58:36 +02:00
|
|
|
+ '.{0,' + maxAdditionalLengthOnNavUrl + '}$')
|
2017-11-15 02:16:59 +01:00
|
|
|
.test(currentUrl);
|
2017-04-12 00:01:06 +02:00
|
|
|
|
2017-11-15 02:16:59 +01:00
|
|
|
if (!navSuccessful) {
|
|
|
|
const msg = 'App failed to load: ' + appName +
|
2018-05-29 18:58:36 +02:00
|
|
|
' in ' + defaultFindTimeout + 'ms' +
|
|
|
|
' appUrl = ' + appUrl +
|
|
|
|
' currentUrl = ' + currentUrl;
|
2017-11-15 02:16:59 +01:00
|
|
|
log.debug(msg);
|
|
|
|
throw new Error(msg);
|
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
|
2017-11-15 02:16:59 +01:00
|
|
|
return currentUrl;
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return retry.tryForTime(defaultTryTimeout * 3, () => {
|
|
|
|
return navigateTo(appUrl)
|
2017-11-15 02:16:59 +01:00
|
|
|
.then(function (currentUrl) {
|
|
|
|
let lastUrl = currentUrl;
|
|
|
|
return retry.try(function () {
|
2018-05-29 18:58:36 +02:00
|
|
|
// give the app time to update the URL
|
2017-11-15 02:16:59 +01:00
|
|
|
return self.sleep(501)
|
|
|
|
.then(function () {
|
2018-11-29 23:30:47 +01:00
|
|
|
return browser.getCurrentUrl();
|
2017-11-15 02:16:59 +01:00
|
|
|
})
|
|
|
|
.then(function (currentUrl) {
|
|
|
|
log.debug('in navigateTo url = ' + currentUrl);
|
|
|
|
if (lastUrl !== currentUrl) {
|
|
|
|
lastUrl = currentUrl;
|
|
|
|
throw new Error('URL changed, waiting for it to settle');
|
|
|
|
}
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
2017-11-15 02:16:59 +01:00
|
|
|
})
|
|
|
|
.then(async () => {
|
|
|
|
if (appName === 'status_page') return;
|
|
|
|
if (await testSubjects.exists('statusPageContainer')) {
|
|
|
|
throw new Error('Navigation ended up at the status page.');
|
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async sleep(sleepMilliseconds) {
|
|
|
|
log.debug('... sleep(' + sleepMilliseconds + ') start');
|
|
|
|
await delay(sleepMilliseconds);
|
|
|
|
log.debug('... sleep(' + sleepMilliseconds + ') end');
|
|
|
|
}
|
|
|
|
|
|
|
|
createErrorHandler(testObj) {
|
|
|
|
const testName = (testObj.parent) ? [testObj.parent.name, testObj.name].join('_') : testObj.name;
|
|
|
|
return error => {
|
|
|
|
const now = Date.now();
|
|
|
|
const fileName = `failure_${now}_${testName}`;
|
|
|
|
|
|
|
|
return this.saveScreenshot(fileName, true)
|
2017-11-15 02:16:59 +01:00
|
|
|
.then(function () {
|
|
|
|
throw error;
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async waitUntilUrlIncludes(path) {
|
|
|
|
await retry.try(async () => {
|
2018-11-29 23:30:47 +01:00
|
|
|
const url = await browser.getCurrentUrl();
|
2017-04-12 00:01:06 +02:00
|
|
|
if (!url.includes(path)) {
|
|
|
|
throw new Error('Url not found');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async getSharedItemTitleAndDescription() {
|
2017-07-27 21:26:09 +02:00
|
|
|
const element = await find.byCssSelector('[data-shared-item]');
|
2017-04-12 00:01:06 +02:00
|
|
|
return {
|
|
|
|
title: await element.getAttribute('data-title'),
|
|
|
|
description: await element.getAttribute('data-description')
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes sure the modal overlay is not showing, tries a few times in case it is in the process of hiding.
|
|
|
|
*/
|
|
|
|
async ensureModalOverlayHidden() {
|
|
|
|
return retry.try(async () => {
|
|
|
|
const shown = await testSubjects.exists('modalOverlay');
|
|
|
|
if (shown) {
|
|
|
|
throw new Error('Modal overlay is showing');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async clickConfirmOnModal() {
|
|
|
|
log.debug('Clicking modal confirm');
|
|
|
|
await testSubjects.click('confirmModalConfirmButton');
|
|
|
|
await this.ensureModalOverlayHidden();
|
|
|
|
}
|
|
|
|
|
2017-05-17 15:48:26 +02:00
|
|
|
async pressEnterKey() {
|
2019-01-14 17:15:03 +01:00
|
|
|
await browser.pressKeys(browser.keys.ENTER);
|
2017-05-17 15:48:26 +02:00
|
|
|
}
|
|
|
|
|
2017-10-05 02:42:07 +02:00
|
|
|
// pass in true if your test will show multiple modals
|
|
|
|
// in succession
|
|
|
|
async clickCancelOnModal(overlayWillStay = false) {
|
2017-04-12 00:01:06 +02:00
|
|
|
log.debug('Clicking modal cancel');
|
|
|
|
await testSubjects.click('confirmModalCancelButton');
|
2017-10-05 02:42:07 +02:00
|
|
|
if (!overlayWillStay) {
|
|
|
|
await this.ensureModalOverlayHidden();
|
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2018-06-19 06:05:21 +02:00
|
|
|
async expectConfirmModalOpenState(state) {
|
|
|
|
if (typeof state !== 'boolean') {
|
|
|
|
throw new Error('pass true or false to expectConfirmModalOpenState()');
|
|
|
|
}
|
|
|
|
|
|
|
|
log.debug(`expectConfirmModalOpenState(${state})`);
|
|
|
|
|
|
|
|
// we use retry here instead of a simple .exists() check because the modal
|
|
|
|
// fades in/out, which takes time, and we really only care that at some point
|
|
|
|
// the modal is either open or closed
|
|
|
|
await retry.try(async () => {
|
|
|
|
const actualState = await testSubjects.exists('confirmModalCancelButton');
|
|
|
|
expect(actualState).to.be(state);
|
|
|
|
});
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
2017-05-23 16:09:04 +02:00
|
|
|
async isChromeVisible() {
|
2019-01-18 21:39:01 +01:00
|
|
|
const globalNavShown = await globalNav.exists();
|
2017-08-03 17:25:38 +02:00
|
|
|
const topNavShown = await testSubjects.exists('top-nav');
|
|
|
|
return globalNavShown && topNavShown;
|
2017-05-23 16:09:04 +02:00
|
|
|
}
|
2017-05-31 18:29:08 +02:00
|
|
|
|
|
|
|
async waitForTopNavToBeVisible() {
|
|
|
|
await retry.try(async () => {
|
|
|
|
const isNavVisible = await testSubjects.exists('top-nav');
|
|
|
|
if (!isNavVisible) {
|
|
|
|
throw new Error('Local nav not visible yet');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2018-05-24 19:05:52 +02:00
|
|
|
|
2018-05-29 18:58:36 +02:00
|
|
|
async closeToast() {
|
|
|
|
const toast = await find.byCssSelector('.euiToast');
|
2018-11-29 23:30:47 +01:00
|
|
|
await browser.moveMouseTo(toast);
|
2018-08-30 05:13:40 +02:00
|
|
|
const title = await (await find.byCssSelector('.euiToastHeader__title')).getVisibleText();
|
|
|
|
log.debug(title);
|
2018-05-29 18:58:36 +02:00
|
|
|
await find.clickByCssSelector('.euiToast__closeButton');
|
2018-08-30 05:13:40 +02:00
|
|
|
return title;
|
2018-05-29 18:58:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-24 19:05:52 +02:00
|
|
|
async clearAllToasts() {
|
|
|
|
const toasts = await find.allByCssSelector('.euiToast');
|
|
|
|
for (const toastElement of toasts) {
|
|
|
|
try {
|
2018-11-29 23:30:47 +01:00
|
|
|
await browser.moveMouseTo(toastElement);
|
2018-05-29 18:58:36 +02:00
|
|
|
const closeBtn = await toastElement.findByCssSelector('.euiToast__closeButton');
|
2018-05-24 19:05:52 +02:00
|
|
|
await closeBtn.click();
|
|
|
|
} catch (err) {
|
|
|
|
// ignore errors, toast clear themselves after timeout
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-04-12 00:01:06 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return new CommonPage();
|
|
|
|
}
|