fetch node labels via script execution (#93225)

This commit is contained in:
Joe Reuter 2021-03-04 17:08:26 +01:00 committed by GitHub
parent 3d374e2686
commit 1882b82531
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,6 +26,7 @@ export function GraphPageProvider({ getService, getPageObjects }: FtrProviderCon
const testSubjects = getService('testSubjects');
const PageObjects = getPageObjects(['common', 'header']);
const retry = getService('retry');
const browser = getService('browser');
class GraphPage {
async selectIndexPattern(pattern: string) {
@ -124,9 +125,12 @@ export function GraphPageProvider({ getService, getPageObjects }: FtrProviderCon
async getGraphObjects() {
await this.stopLayout();
const graphElements = await find.allByCssSelector(
'#graphSvg line, #graphSvg circle, #graphSvg text.gphNode__label'
);
// read node labels directly from DOM because getVisibleText is not reliable for the way the graph is rendered
const nodeNames: string[] = await browser.execute(`
const elements = document.querySelectorAll('#graphSvg text.gphNode__label');
return [...elements].map(element => element.innerHTML);
`);
const graphElements = await find.allByCssSelector('#graphSvg line, #graphSvg circle');
const nodes: Node[] = [];
const nodePositionMap: Record<string, number> = {};
const edges: Edge[] = [];
@ -136,15 +140,10 @@ export function GraphPageProvider({ getService, getPageObjects }: FtrProviderCon
const tagName: string = await element.getTagName();
// check the position of the circle element
if (tagName === 'circle') {
nodes.push({ circle: element, label: '' });
nodes.push({ circle: element, label: nodeNames[nodes.length] });
const position = await this.getCirclePosition(element);
nodePositionMap[position] = nodes.length - 1;
}
// get the label for the node from the text element
if (tagName === 'text') {
const text = await element.getVisibleText();
nodes[nodes.length - 1].label = text;
}
}
// find all edges