diff --git a/test/support/page_objects/common.js b/test/support/page_objects/common.js index 661ff8f865d35..bb32358ee3a9e 100644 --- a/test/support/page_objects/common.js +++ b/test/support/page_objects/common.js @@ -15,17 +15,19 @@ import { import util from 'util'; import getUrl from '../../utils/get_url'; + import { config, defaultTryTimeout, defaultFindTimeout, remote, - shieldPage + shieldPage, + esClient } from '../index'; import { Log, - Try, + Try } from '../utils'; const mkdirpAsync = promisify(mkdirp); @@ -83,8 +85,21 @@ export default class Common { function navigateTo(url) { return self.try(function () { // since we're using hash URLs, always reload first to force re-render - self.debug('navigate to: ' + url); - return self.remote.get(url) + return esClient.getDefaultIndex() + .then(function (defaultIndex) { + if (appName === 'discover' || appName === 'visualize' || appName === 'dashboard') { + if (!defaultIndex) { + // 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. + self.debug(' >>>>>>>> WARNING Navigating to [' + appName + '] with defaultIndex=' + defaultIndex); + self.debug(' >>>>>>>> Setting defaultIndex to "logstash-*""'); + esClient.updateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'}); + } + } + self.debug('navigate to: ' + url); + return self.remote.get(url); + }) .then(function () { return self.sleep(700); }) diff --git a/test/support/utils/es_client.js b/test/support/utils/es_client.js index 10a85f9fcec39..1edbaefe0a27d 100644 --- a/test/support/utils/es_client.js +++ b/test/support/utils/es_client.js @@ -68,12 +68,39 @@ export default (function () { ); } else { configId = response.hits.hits[0]._id; - Log.debug('config._id =' + configId); + Log.debug('config._id = ' + configId); return configId; } }); }, + /* + ** Gets defaultIndex from the config doc. + */ + getDefaultIndex: function () { + var defaultIndex; + + return this.client.search({ + index: '.kibana', + type: 'config' + }) + .then(function (response) { + if (response.errors) { + throw new Error( + 'get config failed\n' + + response.items + .map(i => i[Object.keys(i)[0]].error) + .filter(Boolean) + .map(err => ' ' + JSON.stringify(err)) + .join('\n') + ); + } else { + defaultIndex = response.hits.hits[0]._source.defaultIndex; + Log.debug('config.defaultIndex = ' + defaultIndex); + return defaultIndex; + } + }); + }, /** * Add fields to the config doc (like setting timezone and defaultIndex)