Skip to content

Commit

Permalink
Merge pull request elastic#7536 from cjcenizal/refactor/functional-te…
Browse files Browse the repository at this point in the history
…st-page-objects

Refactor functional tests, particularly support/index.js.
  • Loading branch information
spalger authored Jun 23, 2016
2 parents 22103a5 + 64828f1 commit 5ca4ea1
Show file tree
Hide file tree
Showing 25 changed files with 776 additions and 647 deletions.
113 changes: 55 additions & 58 deletions test/functional/apps/discover/_discover.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@

import expect from 'expect.js';

import {
bdd,
scenarioManager,
common,
discoverPage,
settingsPage,
headerPage,
esClient,
elasticDump
} from '../../../support';

var expect = require('expect.js');
import PageObjects from '../../../support/page_objects';

bdd.describe('discover app', function describeIndexTests() {
bdd.before(function () {
Expand All @@ -19,20 +18,20 @@ bdd.describe('discover app', function describeIndexTests() {
// delete .kibana index and update configDoc
return esClient.deleteAndUpdateConfigDoc({'dateFormat:tz':'UTC', 'defaultIndex':'logstash-*'})
.then(function loadkibanaIndexPattern() {
common.debug('load kibana index with default index pattern');
PageObjects.common.debug('load kibana index with default index pattern');
return elasticDump.elasticLoad('visualize','.kibana');
})
// and load a set of makelogs data
.then(function loadIfEmptyMakelogs() {
return scenarioManager.loadIfEmpty('logstashFunctional');
})
.then(function () {
common.debug('discover');
return common.navigateToApp('discover');
PageObjects.common.debug('discover');
return PageObjects.common.navigateToApp('discover');
})
.then(function () {
common.debug('setAbsoluteRange');
return headerPage.setAbsoluteRange(fromTime, toTime);
PageObjects.common.debug('setAbsoluteRange');
return PageObjects.header.setAbsoluteRange(fromTime, toTime);
});
});

Expand All @@ -44,52 +43,51 @@ bdd.describe('discover app', function describeIndexTests() {

bdd.it('should show correct time range string by timepicker', function () {
var expectedTimeRangeString = fromTimeString + ' to ' + toTimeString;
return discoverPage.getTimespanText()
return PageObjects.discover.getTimespanText()
.then(function (actualTimeString) {
expect(actualTimeString).to.be(expectedTimeRangeString);
});
});


bdd.it('save query should show toast message and display query name', function () {
var expectedSavedQueryMessage = 'Discover: Saved Data Source "' + queryName1 + '"';
return discoverPage.saveSearch(queryName1)
return PageObjects.discover.saveSearch(queryName1)
.then(function () {
return headerPage.getToastMessage();
return PageObjects.header.getToastMessage();
})
.then(function (toastMessage) {
common.saveScreenshot('Discover-save-query-toast');
PageObjects.common.saveScreenshot('Discover-save-query-toast');
expect(toastMessage).to.be(expectedSavedQueryMessage);
})
.then(function () {
return headerPage.waitForToastMessageGone();
return PageObjects.header.waitForToastMessageGone();
})
.then(function () {
return discoverPage.getCurrentQueryName();
return PageObjects.discover.getCurrentQueryName();
})
.then(function (actualQueryNameString) {
expect(actualQueryNameString).to.be(queryName1);
});
});

bdd.it('load query should show query name', function () {
return discoverPage.loadSavedSearch(queryName1)
return PageObjects.discover.loadSavedSearch(queryName1)
.then(function () {
return common.sleep(3000);
return PageObjects.common.sleep(3000);
})
.then(function () {
return discoverPage.getCurrentQueryName();
return PageObjects.discover.getCurrentQueryName();
})
.then(function (actualQueryNameString) {
common.saveScreenshot('Discover-load-query');
PageObjects.common.saveScreenshot('Discover-load-query');
expect(actualQueryNameString).to.be(queryName1);
});
});

bdd.it('should show the correct hit count', function () {
var expectedHitCount = '14,004';
return common.try(function tryingForTime() {
return discoverPage.getHitCount()
return PageObjects.common.try(function tryingForTime() {
return PageObjects.discover.getHitCount()
.then(function compareData(hitCount) {
expect(hitCount).to.be(expectedHitCount);
});
Expand All @@ -103,23 +101,23 @@ bdd.describe('discover app', function describeIndexTests() {
'61.862', '15.487', '2.362', '2.800', '15.312', '61.862', '123.2',
'118.562', '63.524', '17.587', '2.537'
];
return common.sleep(4000)
return PageObjects.common.sleep(4000)
.then(function () {
return verifyChartData(expectedBarChartData);
});
});

bdd.it('should show correct time range string in chart', function () {
var expectedTimeRangeString = fromTimeString + ' - ' + toTimeString;
return discoverPage.getChartTimespan()
return PageObjects.discover.getChartTimespan()
.then(function (actualTimeString) {
expect(actualTimeString).to.be(expectedTimeRangeString);
});
});

bdd.it('should show correct initial chart interval of 3 hours', function () {
var expectedChartInterval = 'by 3 hours';
return discoverPage.getChartInterval()
return PageObjects.discover.getChartInterval()
.then(function (actualInterval) {
expect(actualInterval).to.be(expectedChartInterval);
});
Expand All @@ -140,9 +138,9 @@ bdd.describe('discover app', function describeIndexTests() {
'120.4', '96.472', '74.581', '70.509', '39.709', '25.199', '13.490',
'12.472', '4.072', '2.290', '1.018'
];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(4000);
return PageObjects.common.sleep(4000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -154,9 +152,9 @@ bdd.describe('discover app', function describeIndexTests() {
var expectedBarChartData = [
'133.196', '129.192', '129.724'
];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(4000);
return PageObjects.common.sleep(4000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -166,9 +164,9 @@ bdd.describe('discover app', function describeIndexTests() {
bdd.it('should show correct data for chart interval Weekly', function () {
var chartInterval = 'Weekly';
var expectedBarChartData = [ '66.598', '129.458'];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(2000);
return PageObjects.common.sleep(2000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -182,8 +180,8 @@ bdd.describe('discover app', function describeIndexTests() {
];
return this.remote.goBack()
.then(function () {
return common.try(function tryingForTime() {
return discoverPage.getChartInterval()
return PageObjects.common.try(function tryingForTime() {
return PageObjects.discover.getChartInterval()
.then(function (actualInterval) {
expect(actualInterval).to.be(expectedChartInterval);
});
Expand All @@ -197,9 +195,9 @@ bdd.describe('discover app', function describeIndexTests() {
bdd.it('should show correct data for chart interval Monthly', function () {
var chartInterval = 'Monthly';
var expectedBarChartData = [ '122.535'];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(2000);
return PageObjects.common.sleep(2000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -209,9 +207,9 @@ bdd.describe('discover app', function describeIndexTests() {
bdd.it('should show correct data for chart interval Yearly', function () {
var chartInterval = 'Yearly';
var expectedBarChartData = [ '122.535'];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(2000);
return PageObjects.common.sleep(2000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -226,9 +224,9 @@ bdd.describe('discover app', function describeIndexTests() {
'61.862', '15.487', '2.362', '2.800', '15.312', '61.862', '123.2',
'118.562', '63.524', '17.587', '2.537'
];
return discoverPage.setChartInterval(chartInterval)
return PageObjects.discover.setChartInterval(chartInterval)
.then(function () {
return common.sleep(4000);
return PageObjects.common.sleep(4000);
})
.then(function () {
return verifyChartData(expectedBarChartData);
Expand All @@ -237,21 +235,21 @@ bdd.describe('discover app', function describeIndexTests() {

bdd.it('should show Auto chart interval of 3 hours', function () {
var expectedChartInterval = 'by 3 hours';
return discoverPage.getChartInterval()
return PageObjects.discover.getChartInterval()
.then(function (actualInterval) {
expect(actualInterval).to.be(expectedChartInterval);
});
});

bdd.it('should not show "no results"', () => {
return discoverPage.hasNoResults().then(visible => {
return PageObjects.discover.hasNoResults().then(visible => {
expect(visible).to.be(false);
});
});

function verifyChartData(expectedBarChartData) {
return common.try(function tryingForTime() {
return discoverPage.getBarChartData()
return PageObjects.common.try(function tryingForTime() {
return PageObjects.discover.getBarChartData()
.then(function compareData(paths) {
// the largest bars are over 100 pixels high so this is less than 1% tolerance
var barHeightTolerance = 1;
Expand All @@ -265,8 +263,8 @@ bdd.describe('discover app', function describeIndexTests() {
};
};
if (hasFailure) {
common.log(stringResults);
common.log(paths);
PageObjects.common.log(stringResults);
PageObjects.common.log(paths);
}
for (var x = 0; x < expectedBarChartData.length; x++) {
expect(Math.abs(expectedBarChartData[x] - paths[x]) < barHeightTolerance).to.be.ok();
Expand All @@ -278,26 +276,25 @@ bdd.describe('discover app', function describeIndexTests() {

});


bdd.describe('query #2, which has an empty time range', function () {
var fromTime = '1999-06-11 09:22:11.000';
var toTime = '1999-06-12 11:21:04.000';

bdd.before(() => {
common.debug('setAbsoluteRangeForAnotherQuery');
return headerPage
PageObjects.common.debug('setAbsoluteRangeForAnotherQuery');
return PageObjects.header
.setAbsoluteRange(fromTime, toTime);
});

bdd.it('should show "no results"', () => {
return discoverPage.hasNoResults().then(visible => {
common.saveScreenshot('Discover-no-results');
return PageObjects.discover.hasNoResults().then(visible => {
PageObjects.common.saveScreenshot('Discover-no-results');
expect(visible).to.be(true);
});
});

bdd.it('should suggest a new time range is picked', () => {
return discoverPage.hasNoResultsTimepicker().then(visible => {
return PageObjects.discover.hasNoResultsTimepicker().then(visible => {
expect(visible).to.be(true);
});
});
Expand All @@ -311,25 +308,25 @@ bdd.describe('discover app', function describeIndexTests() {
.then(() => isTimepickerOpen(true))
.then(el => el.click()) // close
.then(() => isTimepickerOpen(false))
.catch(common.handleError(this))
.catch(PageObjects.common.createErrorHandler(this))
);

function closeTimepicker() {
return headerPage.isTimepickerOpen().then(shown => {
return PageObjects.header.isTimepickerOpen().then(shown => {
if (!shown) {
return;
}
return discoverPage
return PageObjects.discover
.getNoResultsTimepicker()
.click(); // close
});
}

function isTimepickerOpen(expected) {
return headerPage.isTimepickerOpen().then(shown => {
common.debug(`expect (#${++i}) timepicker to be ${peek(expected)} (is ${peek(shown)}).`);
return PageObjects.header.isTimepickerOpen().then(shown => {
PageObjects.common.debug(`expect (#${++i}) timepicker to be ${peek(expected)} (is ${peek(shown)}).`);
expect(shown).to.be(expected);
return discoverPage.getNoResultsTimepicker();
return PageObjects.discover.getNoResultsTimepicker();
function peek(state) {
return state ? 'open' : 'closed';
}
Expand Down
4 changes: 3 additions & 1 deletion test/functional/apps/discover/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { bdd, remote, scenarioManager, defaultTimeout } from '../../../support';

import PageObjects from '../../../support/page_objects';

bdd.describe('discover app', function () {
this.timeout = defaultTimeout;

bdd.before(function () {
return remote.setWindowSize(1200,800);
return PageObjects.remote.setWindowSize(1200,800);
});

bdd.after(function unloadMakelogs() {
Expand Down
2 changes: 1 addition & 1 deletion test/functional/apps/management/_creation_form_changes.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bdd.describe('user input reactions', function () {
.then(function () {
common.saveScreenshot('Settings-indices-hide-time-based-index-pattern');
// we expect the promise above to fail
var handler = common.handleError(self);
var handler = common.createErrorHandler(self);
var msg = 'Found time based index pattern checkbox';
handler(msg);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ bdd.describe('index result field sort', function describeIndexTests() {
});
}, Promise.resolve());

return chain.catch(common.handleError(this));
return chain.catch(common.createErrorHandler(this));
});
}); // end describe pagination
}); // end index result field sort
25 changes: 14 additions & 11 deletions test/functional/index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
'use strict'; // eslint-disable-line

define(function (require) {
require('intern/dojo/node!../support/env_setup');

const bdd = require('intern!bdd');
const intern = require('intern');
const initCallbacks = [];

function onInit(callback) {
initCallbacks.push(callback);
}

global.__kibana__intern__ = { intern, bdd, onInit };
global.__kibana__intern__ = { intern, bdd };

bdd.describe('kibana', function () {
let PageObjects;
let support;

bdd.before(function () {
initCallbacks.forEach(callback => {
callback.call(this);
});
PageObjects.init(this.remote);
support.init(this.remote);
});

require([
'intern/dojo/node!../support/index',
'intern/dojo/node!../support/page_objects',
'intern/dojo/node!../support',
'intern/dojo/node!./apps/discover',
'intern/dojo/node!./status_page',
'intern/dojo/node!./apps/management',
'intern/dojo/node!./apps/visualize',
'intern/dojo/node!./apps/console',
'intern/dojo/node!./apps/dashboard'
], function () {});
], (loadedPageObjects, loadedSupport) => {
PageObjects = loadedPageObjects;
support = loadedSupport;
});
});
});
Loading

0 comments on commit 5ca4ea1

Please sign in to comment.