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

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 05:45:05 -08:00 committed by GitHub
parent a3602f62bd
commit 7e57c107ab
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.
*/
async getTableVisData() {
const dataTable = await testSubjects.find('paginated-table-body');
return await dataTable.getVisibleText();
return await testSubjects.getVisibleText('paginated-table-body');
}
/**
@ -952,29 +951,31 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
* cell values into arrays. Please use this function for newer tests.
*/
async getTableVisContent({ stripEmptyRows = true } = { }) {
const container = await testSubjects.find('tableVis');
const allTables = await testSubjects.findAllDescendant('paginated-table-body', container);
return await retry.try(async () => {
const container = await testSubjects.find('tableVis');
const allTables = await testSubjects.findAllDescendant('paginated-table-body', container);
if (allTables.length === 0) {
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));
if (allTables.length === 0) {
return [];
}
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
// This prevents an unnecessary array around that single table, which
// is the case we have in most tests.
return allData[0];
}
return allData[0];
}
return allData;
return allData;
});
}
async getInspectorTableData() {
@ -1144,11 +1145,13 @@ export function VisualizePageProvider({ getService, getPageObjects }) {
}
async filterOnTableCell(column, row) {
const table = await testSubjects.find('tableVis');
const cell = await table.findByCssSelector(`tbody tr:nth-child(${row}) td:nth-child(${column})`);
await remote.moveMouseTo(cell);
const filterBtn = await testSubjects.findDescendant('filterForCellValue', cell);
await filterBtn.click();
await retry.try(async () => {
const table = await testSubjects.find('tableVis');
const cell = await table.findByCssSelector(`tbody tr:nth-child(${row}) td:nth-child(${column})`);
await remote.moveMouseTo(cell);
const filterBtn = await testSubjects.findDescendant('filterForCellValue', cell);
await filterBtn.click();
});
}
async toggleLegend(show = true) {