Conversation
e2e_tests/pages/navigation.page.ts
Outdated
| mouseHoverOnPmmLogo = async () => { | ||
| const pmmLogo = this.elements.sidebar.locator('rect'); | ||
|
|
||
| const rectBox = await pmmLogo.boundingBox(); | ||
| if (rectBox) { | ||
| await this.page.mouse.move( | ||
| rectBox.x + rectBox.width / 2, | ||
| rectBox.y + rectBox.height / 2 | ||
| ); | ||
| } | ||
| }; |
There was a problem hiding this comment.
Have you tried just using pmmLogo.hover()?
You can even pass coordinates if really needed (but I don't think it's needed)
https://playwright.dev/docs/api/class-locator#locator-hover
There was a problem hiding this comment.
I tried pmmlogo.hover(), it did not work.
e2e_tests/tests/navigation.test.ts
Outdated
|
|
||
| await leftNavigation.elements.openLeftNavigationButton.click(); | ||
| await expect(leftNavigation.elements.closeLeftNavigationButton).toBeVisible(); | ||
| await expect(leftNavigation.elements.openLeftNavigationButton).not.toBeVisible(); |
There was a problem hiding this comment.
prefer toBeHidden instead of not toBeVisible as it's more readable
@peterSirotnak Do you think we should enable it as a eslint plugin?
e2e_tests/tests/navigation.test.ts
Outdated
| await leftNavigation.elements.openLeftNavigationButton.click(); | ||
| } | ||
|
|
||
| await leftNavigation.traverseAllMenuItems(); |
There was a problem hiding this comment.
What is this test, testing?
We don't have any assertions/expects anywhere in the method or the test
There was a problem hiding this comment.
Agree with @travagliad . There is no need to create a method which is not used anywhere else. Same applies to other methods in the leftNavigation class
@kiranvuyurru lets move the code into the test and wrap with test.step annotations for code readability
pls use test.step everywhere possible
e2e_tests/fixtures/pmmTest.ts
Outdated
| leftNavigation: LeftNavigation; | ||
| }>({ | ||
| cliHelper: async ({}, use) => { | ||
| cliHelper: async ({ }, use) => { |
There was a problem hiding this comment.
We shouldn't be changing formatting of code on PRs otherwise we end up on a review hell anytime we push, if it's auto formatting try to change your rules so it doesn't happen or push without autoformatting on existing files
e2e_tests/tests/navigation.test.ts
Outdated
| await leftNavigation.elements.home.click(); | ||
| await leftNavigation.elements.timePickerOpenButton.click(); | ||
| await leftNavigation.getTimeRangeOption(selectedTimeRange).click(); | ||
| await page.waitForLoadState('domcontentloaded'); |
There was a problem hiding this comment.
prefer web assertions instead of load states as this is flaky
https://playwright.dev/docs/best-practices#use-web-first-assertions
|
I see many playwright methods like Also, not having expects in a test isn't ideal, the reason being that all test are supposed to be asserting something, or expecting for something, so for better understanding of a test we should have: steps coming from the pages objects (So the methods should have a descriptive name) and expects in the end to understand what is being tested If you need help refactoring it let me know |
e2e_tests/pages/navigation.page.ts
Outdated
| public get elements() { | ||
| return { | ||
| // parent menu items | ||
| home: this.page.locator('//*[@data-testid="navitem-home-page"]'), |
There was a problem hiding this comment.
please use this.page.getByTestId() everywhere
e2e_tests/pages/navigation.page.ts
Outdated
| export default class LeftNavigation { | ||
|
|
||
| public readonly simpleMenuItems = ['home', 'qan', 'help'] as const; | ||
|
|
There was a problem hiding this comment.
No need for so many empty lines.
e2e_tests/pages/navigation.page.ts
Outdated
|
|
||
| const grafanaIframe = '#grafana-iframe'; | ||
|
|
||
| export default class LeftNavigation { |
There was a problem hiding this comment.
| export default class LeftNavigation { | |
| export default class LeftNavigation extends BasePage { |
e2e_tests/pages/navigation.page.ts
Outdated
|
|
||
| export type MenuItem = Locator | (() => Locator) | { [key: string]: MenuItem }; | ||
|
|
||
| const grafanaIframe = '#grafana-iframe'; |
e2e_tests/pages/navigation.page.ts
Outdated
| return this.page.frameLocator(grafanaIframe); | ||
| } | ||
|
|
||
| selectMenuItem = async (item: string): Promise<void> => { |
There was a problem hiding this comment.
| selectMenuItem = async (item: string): Promise<void> => { | |
| selectMenuItem = async (item: SomeInteface with defined object): Promise<void> => { |
Do this so we have specific options.
e2e_tests/tests/navigation.test.ts
Outdated
| } | ||
| }; | ||
|
|
||
| const traverseAllMenuItems = async () => { |
There was a problem hiding this comment.
Move this to page object.
e2e_tests/pages/navigation.page.ts
Outdated
| return newPage; | ||
| } | ||
|
|
||
| switchPage = (page: Page) => { |
There was a problem hiding this comment.
Move this to base page.
e2e_tests/pages/navigation.page.ts
Outdated
| } | ||
| } | ||
|
|
||
| newTab = async (): Promise<Page> => { |
There was a problem hiding this comment.
Move this to base page
e2e_tests/pages/navigation.page.ts
Outdated
| oldLeftMenu: () => this.page.getByTestId('data-testid navigation mega-menu'), | ||
| }; | ||
|
|
||
| iframe(): FrameLocator { |
There was a problem hiding this comment.
Already in base page, remove.
8aa1241 to
ed701a1
Compare
e2e_tests/pages/navigation.page.ts
Outdated
| constructor(page: Page) { super(page); } | ||
| public elements = { | ||
| // parent menu items | ||
| home: () => this.page.getByTestId('navitem-home-page'), |
There was a problem hiding this comment.
why all locators are functions?
e2e_tests/tests/navigation.test.ts
Outdated
| await leftNavigation.selectMenuItem({ path: 'mysql' }); | ||
| const selectedNode = await leftNavigation.selectNode(4, /client_container_\d+/); | ||
| await leftNavigation.grafanaIframe().getByText(selectedNode).waitFor({ state: 'visible', timeout: 10000 }); | ||
| await expect(leftNavigation.grafanaIframe().getByText(selectedNode)).toBeVisible(); |
There was a problem hiding this comment.
can we have this locator in the page object? to not have .grafanaIframe() everywhere?
78bf848 to
63ce711
Compare
e2e_tests/tests/navigation.test.ts
Outdated
| await expect(leftNavigation.buttons.oldLeftMenu).toBeHidden(); | ||
| }); | ||
| await pmmTest.step('Verify iframe hidden on Help page', async () => { | ||
| // await leftNavigation.selectMenuItem({ path: 'help' }); |
There was a problem hiding this comment.
Remove commented text
e2e_tests/helpers/grafana.helper.ts
Outdated
| } | ||
|
|
||
|
|
||
| // creates non admin user |
e2e_tests/pages/navigation.page.ts
Outdated
| this.buttons = { | ||
| // parent menu items | ||
| home: this.page.getByTestId('navitem-home-page'), | ||
| mysql: this.page.getByTestId('navitem-mysql'), |
There was a problem hiding this comment.
| this.buttons = { | |
| // parent menu items | |
| home: this.page.getByTestId('navitem-home-page'), | |
| mysql: this.page.getByTestId('navitem-mysql'), | |
| this.buttons = { | |
| home: this.page.getByTestId('navitem-home-page'), | |
| mysql: { | |
| locator: this.page.getByTestId('navitem-mysql'), | |
| elements: { | |
| overview: this.page.getByTestId('navitem-mysql-overview'), | |
| summary: this.page.getByTestId('navitem-mysql-summary'), | |
| highAvailability: this.page.getByTestId('navitem-mysql-high-availability'), | |
| ha: { | |
| groupReplication: this.page.getByTestId('navitem-mysql-group-replication-summary'), | |
| replication: this.page.getByTestId('navitem-mysql-replication-summary'), | |
| pxcGaleraCluster: this.page.getByTestId('navitem-pxc-cluster-summary'), | |
| pxcGaleraNode: this.page.getByTestId('navitem-pxc-node-summary'), | |
| pxcGaleraNodes: this.page.getByTestId('navitem-pxc-nodes-compare'), | |
| commandHandler: this.page.getByTestId('navitem-mysql-command-handler-counters-compare'), | |
| innodbDetails: this.page.getByTestId('navitem-mysql-innodb-details'), | |
| innodbCompression: this.page.getByTestId('navitem-mysql-innodb-compression-details'), | |
| performanceSchema: this.page.getByTestId('navitem-mysql-performance-schema-details'), | |
| queryResponseTime: this.page.getByTestId('navitem-mysql-query-response-time-details'), | |
| tableDetails: this.page.getByTestId('navitem-mysql-table-details'), | |
| tokudbDetails: this.page.getByTestId('navitem-mysql-tokudb-details'), | |
| otherDashboards: this.page.getByTestId('navitem-mysql-other-dashboards'), | |
| } | |
| } |
Do this for each database type and all menus with submenus. Also remove comments.
e2e_tests/pages/navigation.page.ts
Outdated
| public readonly elements; | ||
|
|
||
| public readonly simpleMenuItems = ['home', 'qan', 'help'] as const; | ||
| public readonly menuWithChildren = [ |
There was a problem hiding this comment.
Replace with method that finds menu with children maybe also with variable timerange: true also for simpleMenuItems dashboardsToVerifyTimeRange
e2e_tests/pages/navigation.page.ts
Outdated
| }); | ||
| }; | ||
|
|
||
| public selectTimeRange = async (timeRange: string): Promise<void> => { |
There was a problem hiding this comment.
move this to base page
e2e_tests/pages/navigation.page.ts
Outdated
| return this.selectVariableValue(dashboardIndex); | ||
| }; | ||
|
|
||
| public selectNode = async (dashboardIndex: number): Promise<string> => { |
There was a problem hiding this comment.
move selecting methods to base page
e2e_tests/tests/navigation.test.ts
Outdated
| async ({ page, leftNavigation }) => { | ||
| pmmTest.slow(); | ||
| const ignore404 = (url: string) => url.includes('/settings') || url.includes('/admin_config'); | ||
| const responseAfterClick = async (locator: Locator, name: string) => { |
There was a problem hiding this comment.
Why is this method in the test? Not in the page object?
There was a problem hiding this comment.
this has assertions
1. verify the collapse and expand of the left menu 2. Traverse all menu and check no 404 response 3. non admin RBAC 4. Time range persists on various dashboards 5. old navigation menu not visible and iframe visibility test
Refactored e2e test files and page objects for improved readability and consistency, including formatting, arrow function usage, and type improvements. Updated the IPageObject interface to support nested locators. No functional changes were made to test logic.
d94fbda to
f11db83
Compare
* create traverse test as a new file * Update navigation.page.ts * Update leftMenutravese.test.ts * Update navigation.page.ts
Uh oh!
There was an error while loading. Please reload this page.