Skip to content

Commit

Permalink
Use find service instead of remote which doesn't have built in safety…
Browse files Browse the repository at this point in the history
… checks for stale elements
  • Loading branch information
stacey-gammon committed Aug 3, 2017
1 parent 0aa4206 commit 937186d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 99 deletions.
137 changes: 42 additions & 95 deletions test/functional/page_objects/dashboard_page.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
const find = getService('find');
const retry = getService('retry');
const config = getService('config');
const remote = getService('remote');
const esArchiver = getService('esArchiver');
const kibanaServer = getService('kibanaServer');
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'header']);

const defaultFindTimeout = config.get('timeouts.find');

const getRemote = () => (
getService('remote')
.setFindTimeout(config.get('timeouts.find'))
);

class DashboardPage {
async initTests() {
const logstash = esArchiver.loadIfNeeded('logstash_functional');
Expand Down Expand Up @@ -45,7 +41,7 @@ export function DashboardPageProvider({ getService, getPageObjects }) {

async clickDashboardBreadcrumbLink() {
log.debug('clickDashboardBreadcrumbLink');
await retry.try(() => getRemote().findByCssSelector(`a[href="#${DashboardConstants.LANDING_PAGE_PATH}"]`).click());
await find.clickByCssSelector(`a[href="#${DashboardConstants.LANDING_PAGE_PATH}"]`);
}

async gotoDashboardLandingPage() {
Expand Down Expand Up @@ -173,24 +169,19 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
}
}

filterVizNames(vizName) {
return retry.try(() => getRemote()
.findByCssSelector('input[placeholder="Visualizations Filter..."]')
.click()
.pressKeys(vizName));
async filterVizNames(vizName) {
const visFilter = await find.byCssSelector('input[placeholder="Visualizations Filter..."]');
await visFilter.click();
await remote.pressKeys(vizName);
}

clickVizNameLink(vizName) {
return retry.try(() => getRemote()
.findByPartialLinkText(vizName)
.click());
async clickVizNameLink(vizName) {
await find.clickByPartialLinkText(vizName);
}

closeAddVizualizationPanel() {
async closeAddVizualizationPanel() {
log.debug('closeAddVizualizationPanel');
return retry.try(() => getRemote()
.findByCssSelector('i.fa fa-chevron-up')
.click());
await find.clickByCssSelector('i.fa fa-chevron-up');
}

async gotoDashboardEditMode(dashboardName) {
Expand Down Expand Up @@ -219,7 +210,7 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
async renameDashboard(dashName) {
log.debug(`Naming dashboard ` + dashName);
await testSubjects.click('dashboardRenameButton');
await getRemote().findById('dashboardTitle').type(dashName);
await testSubjects.setValue('dashboardTitle', dashName);
}

/**
Expand Down Expand Up @@ -248,7 +239,7 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
await PageObjects.header.waitUntilLoadingHasFinished();

log.debug('entering new title');
await getRemote().findById('dashboardTitle').type(dashboardTitle);
await testSubjects.setValue('dashboardTitle', dashboardTitle);

if (saveOptions.storeTimeWithDashboard !== undefined) {
await this.setStoreTimeWithDashboard(saveOptions.storeTimeWithDashboard);
Expand All @@ -264,10 +255,8 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
});
}

clickDashboardByLinkText(dashName) {
return getRemote()
.findByLinkText(dashName)
.click();
async clickDashboardByLinkText(dashName) {
await find.clickByLinkText(dashName);
}

async clearSearchValue() {
Expand Down Expand Up @@ -306,7 +295,7 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
log.debug(`getDashboardCountWithName: ${dashName}`);

await this.searchForDashboardWithName(dashName);
const links = await getRemote().findAllByLinkText(dashName);
const links = await find.allByLinkText(dashName);
return links.length;
}

Expand Down Expand Up @@ -342,54 +331,19 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
return await testSubjects.findAll('dashboardPanel');
}

getPanelSizeData() {
return getRemote()
.findAllByCssSelector('li.gs-w') // These are gridster-defined elements and classes
.then(function (titleObjects) {

function getTitles(chart) {
let obj = {};
return chart.getAttribute('data-col')
.then(theData => {
obj = { dataCol:theData };
return chart;
})
.then(chart => {
return chart.getAttribute('data-row')
.then(theData => {
obj.dataRow = theData;
return chart;
});
})
.then(chart => {
return chart.getAttribute('data-sizex')
.then(theData => {
obj.dataSizeX = theData;
return chart;
});
})
.then(chart => {
return chart.getAttribute('data-sizey')
.then(theData => {
obj.dataSizeY = theData;
return chart;
});
})
.then(chart => {
return chart.findByCssSelector('[data-test-subj="dashboardPanelTitle"]')
.then(function (titleElement) {
return titleElement.getVisibleText();
})
.then(theData => {
obj.title = theData;
return obj;
});
});
}
async getPanelSizeData() {
const titleObjects = find.allByCssSelector('li.gs-w'); // These are gridster-defined elements and classes
async function getTitles(chart) {
const dataCol = await chart.getAttribute('data-col');
const dataRow = await chart.getAttribute('data-row');
const dataSizeX = await chart.getAttribute('data-sizex');
const dataSizeY = await chart.getAttribute('data-sizey');
const title = await testSubjects.getVisibleText('dashboardPanelTitle');
return { dataCol, dataRow, dataSizeX, dataSizeY, title };
}

const getTitlePromises = titleObjects.map(getTitles);
return Promise.all(getTitlePromises);
});
const getTitlePromises = titleObjects.map(getTitles);
return await Promise.all(getTitlePromises);
}

getTestVisualizations() {
Expand Down Expand Up @@ -464,7 +418,7 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
log.debug('toggleExpandPanel');
const expandShown = await testSubjects.exists('dashboardPanelExpandIcon');
if (!expandShown) {
const panelElements = await getRemote().findAllByCssSelector('span.panel-title');
const panelElements = await find.allByCssSelector('span.panel-title');
log.debug('click title');
await retry.try(() => panelElements[0].click()); // Click to simulate hover.
}
Expand All @@ -473,33 +427,26 @@ export function DashboardPageProvider({ getService, getPageObjects }) {
await retry.try(() => expandButton.click());
}

getSharedItemsCount() {
async getSharedItemsCount() {
log.debug('in getSharedItemsCount');
const attributeName = 'data-shared-items-count';
return getRemote()
.findByCssSelector(`[${attributeName}]`)
.then(function (element) {
if (element) {
return element.getAttribute(attributeName);
}
const element = find.byCssSelector(`[${attributeName}]`);
if (element) {
return await element.getAttribute(attributeName);
}

throw new Error('no element');
});
throw new Error('no element');
}

getPanelSharedItemData() {
async getPanelSharedItemData() {
log.debug('in getPanelSharedItemData');
return getRemote()
.findAllByCssSelector('li.gs-w')
.then(function (elements) {
return Promise.all(elements.map(async element => {
const sharedItem = await element.findByCssSelector('[data-shared-item]');
return {
title: await sharedItem.getAttribute('data-title'),
description: await sharedItem.getAttribute('data-description')
};
}));
});
const sharedItems = await find.allByCssSelector('[data-shared-item]');
return await Promise.all(sharedItems.map(async sharedItem => {
return {
title: await sharedItem.getAttribute('data-title'),
description: await sharedItem.getAttribute('data-description')
};
}));
}
}

Expand Down
16 changes: 12 additions & 4 deletions test/functional/services/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ export function FindProvider({ getService }) {
});
}

async allByCssSelector(selector, timeout = defaultFindTimeout) {
log.debug('in findAllByCssSelector: ' + selector);
async allByCustom(findAllFunction, timeout = defaultFindTimeout) {
return await this.withTimeout(timeout, async remote => {
return await retry.try(async () => {
let elements = await remote.findAllByCssSelector(selector);
let elements = await findAllFunction(remote);
if (!elements) elements = [];
// Force isStale checks for all the retrieved elements.
await Promise.all(elements.map(async element => await element.isEnabled()));
log.debug(`Found ${elements.length} for selector ${selector}`);
return elements;
});
});
}

async allByLinkText(selector, timeout = defaultFindTimeout) {
log.debug('find.allByLinkText: ' + selector);
return await this.allByCustom(remote => remote.findAllByLinkText(selector), timeout);
}

async allByCssSelector(selector, timeout = defaultFindTimeout) {
log.debug('in findAllByCssSelector: ' + selector);
return await this.allByCustom(remote => remote.findAllByCssSelector(selector), timeout);
}

async displayedByCssSelector(selector, timeout = defaultFindTimeout) {
log.debug('in displayedByCssSelector: ' + selector);
return await this.ensureElementWithTimeout(timeout, async remote => {
Expand Down

0 comments on commit 937186d

Please sign in to comment.