[pageObjects/visualize] use retry to avoid stale element references (#25973) (#26017)

Fixes https://github.com/elastic/kibana/issues/25892

This should address the flakiness observed in this issue by retrying if there is a stale element in the complex `PageObjects.visualize.filterOnTableCell()` method, and using `testSubjects.getVisibleText()` rather than calling `getVisibleText()` directly on the element without retrying.
This commit is contained in:
Spencer 2018-11-21 11:00:22 -08:00 committed by GitHub
parent 3b7cca2e2a
commit a24dc1543b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -942,8 +942,7 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
* If you are writing new tests, you should rather look into getTableVisContent method instead. * If you are writing new tests, you should rather look into getTableVisContent method instead.
*/ */
async getTableVisData() { async getTableVisData() {
const dataTable = await testSubjects.find('paginated-table-body'); return await testSubjects.getVisibleText('paginated-table-body');
return await dataTable.getVisibleText();
} }
/** /**
@ -952,29 +951,31 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
* cell values into arrays. Please use this function for newer tests. * cell values into arrays. Please use this function for newer tests.
*/ */
async getTableVisContent({ stripEmptyRows = true } = { }) { async getTableVisContent({ stripEmptyRows = true } = { }) {
const container = await testSubjects.find('tableVis'); return await retry.try(async () => {
const allTables = await testSubjects.findAllDescendant('paginated-table-body', container); const container = await testSubjects.find('tableVis');
const allTables = await testSubjects.findAllDescendant('paginated-table-body', container);
if (allTables.length === 0) { if (allTables.length === 0) {
return []; return [];
}
const allData = await Promise.all(allTables.map(async (t) => {
let data = await table.getDataFromElement(t);
if (stripEmptyRows) {
data = data.filter(row => row.length > 0 && row.some(cell => cell.trim().length > 0));
} }
return data;
}));
if (allTables.length === 1) { const allData = await Promise.all(allTables.map(async (t) => {
let data = await table.getDataFromElement(t);
if (stripEmptyRows) {
data = data.filter(row => row.length > 0 && row.some(cell => cell.trim().length > 0));
}
return data;
}));
if (allTables.length === 1) {
// If there was only one table we return only the data for that table // If there was only one table we return only the data for that table
// This prevents an unnecessary array around that single table, which // This prevents an unnecessary array around that single table, which
// is the case we have in most tests. // is the case we have in most tests.
return allData[0]; return allData[0];
} }
return allData; return allData;
});
} }
async getInspectorTableData() { async getInspectorTableData() {
@ -1144,11 +1145,13 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
} }
async filterOnTableCell(column, row) { async filterOnTableCell(column, row) {
const table = await testSubjects.find('tableVis'); await retry.try(async () => {
const cell = await table.findByCssSelector(`tbody tr:nth-child(${row}) td:nth-child(${column})`); const table = await testSubjects.find('tableVis');
await remote.moveMouseTo(cell); const cell = await table.findByCssSelector(`tbody tr:nth-child(${row}) td:nth-child(${column})`);
const filterBtn = await testSubjects.findDescendant('filterForCellValue', cell); await remote.moveMouseTo(cell);
await filterBtn.click(); const filterBtn = await testSubjects.findDescendant('filterForCellValue', cell);
await filterBtn.click();
});
} }
async toggleLegend(show = true) { async toggleLegend(show = true) {