|
| 1 | +/* |
| 2 | + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one |
| 3 | + * or more contributor license agreements. Licensed under the Elastic License |
| 4 | + * 2.0 and the Server Side Public License, v 1; you may not use this file except |
| 5 | + * in compliance with, at your election, the Elastic License 2.0 or the Server |
| 6 | + * Side Public License, v 1. |
| 7 | + */ |
| 8 | + |
| 9 | +import { test, expect } from '@playwright/test'; |
| 10 | + |
| 11 | +import { common, CommonPage } from '../page_objects'; |
| 12 | + |
| 13 | +test.describe('Performance', () => { |
| 14 | + for (let i = 0; i < 10; i++) { |
| 15 | + test(`Get performance metrics ${i}`, async ({ page }) => { |
| 16 | + const url = CommonPage.parseUrl('http://localhost:9001/?path=/story/test-cases--lens-stress-test'); |
| 17 | + await page.goto(url); |
| 18 | + await common.waitForElement(page)(common.chartWaitSelector); |
| 19 | + await page.evaluate(() => window.performance.measure('overall', 'Perf:Started', 'Perf:Ended')); |
| 20 | + // eslint-disable-next-line no-console |
| 21 | + console.log('=============Performance Metrics==============='); |
| 22 | + const getAllMarksJson = await page.evaluate(() => JSON.stringify(window.performance.getEntriesByType('mark'))); |
| 23 | + const getAllMarks = await JSON.parse(getAllMarksJson); |
| 24 | + // eslint-disable-next-line no-console |
| 25 | + console.log('window.performance.getEntriesByType("mark")', getAllMarks); |
| 26 | + const getAllMeasuresJson = await page.evaluate(() => |
| 27 | + JSON.stringify(window.performance.getEntriesByType('measure')), |
| 28 | + ); |
| 29 | + const getAllMeasures = await JSON.parse(getAllMeasuresJson); |
| 30 | + // eslint-disable-next-line no-console |
| 31 | + console.log('window.performance.getEntriesByType("measure")', getAllMeasures); |
| 32 | + // using these two values as min/max to understand if we are increasing or decreasing the rendering speed. |
| 33 | + expect(getAllMeasures[0].duration).toBeGreaterThan(1500); |
| 34 | + expect(getAllMeasures[0].duration).toBeLessThan(1800); |
| 35 | + }); |
| 36 | + } |
| 37 | +}); |
0 commit comments