|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 3 | + * you may not use this file except in compliance with the License. |
| 4 | + * You may obtain a copy of the License at |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * Unless required by applicable law or agreed to in writing, software |
| 7 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 8 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 9 | + * See the License for the specific language governing permissions and |
| 10 | + * limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import { Locator, Page } from '@playwright/test'; |
| 14 | +import { BasePage } from './base-page'; |
| 15 | + |
| 16 | +export class HeaderPage extends BasePage { |
| 17 | + readonly header: Locator; |
| 18 | + readonly brandLogo: Locator; |
| 19 | + readonly brandLink: Locator; |
| 20 | + readonly notebookMenuItem: Locator; |
| 21 | + readonly notebookDropdownTrigger: Locator; |
| 22 | + readonly notebookDropdown: Locator; |
| 23 | + readonly jobMenuItem: Locator; |
| 24 | + readonly userDropdownTrigger: Locator; |
| 25 | + readonly userBadge: Locator; |
| 26 | + readonly searchInput: Locator; |
| 27 | + readonly themeToggleButton: Locator; |
| 28 | + |
| 29 | + readonly userMenuItems: { |
| 30 | + aboutZeppelin: Locator; |
| 31 | + interpreter: Locator; |
| 32 | + notebookRepos: Locator; |
| 33 | + credential: Locator; |
| 34 | + configuration: Locator; |
| 35 | + logout: Locator; |
| 36 | + switchToClassicUI: Locator; |
| 37 | + }; |
| 38 | + |
| 39 | + constructor(page: Page) { |
| 40 | + super(page); |
| 41 | + this.header = page.locator('.header'); |
| 42 | + this.brandLogo = page.locator('.header .brand .logo'); |
| 43 | + this.brandLink = page.locator('.header .brand'); |
| 44 | + this.notebookMenuItem = page.locator('[nz-menu-item]').filter({ hasText: 'Notebook' }); |
| 45 | + this.notebookDropdownTrigger = page.locator('.node-list-trigger'); |
| 46 | + this.notebookDropdown = page.locator('zeppelin-node-list.ant-dropdown-menu'); |
| 47 | + this.jobMenuItem = page.getByRole('link', { name: 'Job' }); |
| 48 | + this.userDropdownTrigger = page.locator('.header .user .status'); |
| 49 | + this.userBadge = page.locator('.header .user nz-badge'); |
| 50 | + this.searchInput = page.locator('.header .search input[type="text"]'); |
| 51 | + this.themeToggleButton = page.locator('zeppelin-theme-toggle button'); |
| 52 | + |
| 53 | + this.userMenuItems = { |
| 54 | + aboutZeppelin: page.getByText('About Zeppelin', { exact: true }), |
| 55 | + interpreter: page.getByRole('link', { name: 'Interpreter' }), |
| 56 | + notebookRepos: page.getByRole('link', { name: 'Notebook Repos' }), |
| 57 | + credential: page.getByRole('link', { name: 'Credential' }), |
| 58 | + configuration: page.getByRole('link', { name: 'Configuration' }), |
| 59 | + logout: page.getByText('Logout', { exact: true }), |
| 60 | + switchToClassicUI: page.getByRole('link', { name: 'Switch to Classic UI' }) |
| 61 | + }; |
| 62 | + } |
| 63 | + |
| 64 | + async clickBrandLogo(): Promise<void> { |
| 65 | + await this.brandLink.waitFor({ state: 'visible', timeout: 10000 }); |
| 66 | + await this.brandLink.click(); |
| 67 | + } |
| 68 | + |
| 69 | + async clickNotebookMenu(): Promise<void> { |
| 70 | + await this.notebookDropdownTrigger.waitFor({ state: 'visible', timeout: 10000 }); |
| 71 | + await this.notebookDropdownTrigger.click(); |
| 72 | + } |
| 73 | + |
| 74 | + async clickJobMenu(): Promise<void> { |
| 75 | + await this.jobMenuItem.waitFor({ state: 'visible', timeout: 10000 }); |
| 76 | + await this.jobMenuItem.click(); |
| 77 | + } |
| 78 | + |
| 79 | + async clickUserDropdown(): Promise<void> { |
| 80 | + await this.userDropdownTrigger.waitFor({ state: 'visible', timeout: 10000 }); |
| 81 | + await this.userDropdownTrigger.click(); |
| 82 | + } |
| 83 | + |
| 84 | + async clickAboutZeppelin(): Promise<void> { |
| 85 | + await this.userMenuItems.aboutZeppelin.click(); |
| 86 | + } |
| 87 | + |
| 88 | + async clickInterpreter(): Promise<void> { |
| 89 | + await this.userMenuItems.interpreter.click(); |
| 90 | + } |
| 91 | + |
| 92 | + async clickNotebookRepos(): Promise<void> { |
| 93 | + await this.userMenuItems.notebookRepos.click(); |
| 94 | + } |
| 95 | + |
| 96 | + async clickCredential(): Promise<void> { |
| 97 | + await this.userMenuItems.credential.click(); |
| 98 | + } |
| 99 | + |
| 100 | + async clickConfiguration(): Promise<void> { |
| 101 | + await this.userMenuItems.configuration.click(); |
| 102 | + } |
| 103 | + |
| 104 | + async getUsernameText(): Promise<string> { |
| 105 | + return (await this.userBadge.textContent()) || ''; |
| 106 | + } |
| 107 | + |
| 108 | + async searchNote(query: string): Promise<void> { |
| 109 | + await this.searchInput.waitFor({ state: 'visible', timeout: 10000 }); |
| 110 | + await this.searchInput.fill(query); |
| 111 | + await this.page.keyboard.press('Enter'); |
| 112 | + } |
| 113 | +} |
0 commit comments