|
17 | 17 | import { ElementHandle } from '@playwright/test'; |
18 | 18 | import { TheiaPageObject } from './theia-page-object'; |
19 | 19 |
|
20 | | -export class TheiaStatusIndicator extends TheiaPageObject { |
| 20 | +export abstract class TheiaStatusIndicator extends TheiaPageObject { |
| 21 | + protected abstract id: string; |
21 | 22 |
|
22 | | - protected elementSpanSelector = '#theia-statusBar .element span'; |
| 23 | + protected statusBarElementSelector = '#theia-statusBar div.element'; |
23 | 24 |
|
24 | | - protected async getElementHandle(): Promise<ElementHandle<SVGElement | HTMLElement> | null> { |
25 | | - return this.page.$(this.elementSpanSelector); |
| 25 | + protected getSelectorForId(id: string): string { |
| 26 | + return `${this.statusBarElementSelector}#status-bar-${id}`; |
26 | 27 | } |
27 | 28 |
|
28 | | - async waitForVisible(): Promise<void> { |
29 | | - await this.page.waitForSelector(this.elementSpanSelector); |
| 29 | + async waitForVisible(waitForDetached = false): Promise<void> { |
| 30 | + await this.page.waitForSelector(this.getSelectorForId(this.id), waitForDetached ? { state: 'detached' } : {}); |
30 | 31 | } |
31 | 32 |
|
32 | | - protected getSelectorByTitle(title: string): string { |
33 | | - return `.element[title="${title}"]`; |
34 | | - } |
35 | | - |
36 | | - async getElementHandleByTitle(title: string): Promise<ElementHandle<SVGElement | HTMLElement> | null> { |
37 | | - // Fetch element via title in case status elements exist without a dedicated Codicon icon |
38 | | - return this.page.$(this.getSelectorByTitle(title)); |
39 | | - } |
40 | | - |
41 | | - protected getSelectorByIcon(icon: string): string { |
42 | | - return `${this.elementSpanSelector}.codicon.${icon}`; |
43 | | - } |
44 | | - |
45 | | - async getElementHandleByIcon(iconClass: string | string[], titleContain = ''): Promise<ElementHandle<SVGElement | HTMLElement> | null> { |
46 | | - const icons = Array.isArray(iconClass) ? iconClass : [iconClass]; |
47 | | - for (const icon of icons) { |
48 | | - const span = await this.page.$(this.getSelectorByIcon(icon)); |
49 | | - if (span) { |
50 | | - const parent = await span.$('..'); |
51 | | - if (titleContain === '') { |
52 | | - return parent; |
53 | | - } else { |
54 | | - const parentTitle = await parent?.getAttribute('title'); |
55 | | - if (parentTitle?.includes(titleContain)) { return parent; } |
56 | | - } |
57 | | - } |
| 33 | + async getElementHandle(): Promise<ElementHandle<SVGElement | HTMLElement>> { |
| 34 | + const element = await this.page.$(this.getSelectorForId(this.id)); |
| 35 | + if (element) { |
| 36 | + return element; |
58 | 37 | } |
59 | | - throw new Error('Cannot find indicator'); |
60 | | - } |
61 | | - |
62 | | - async waitForVisibleByTitle(title: string, waitForDetached = false): Promise<void> { |
63 | | - await this.page.waitForSelector(this.getSelectorByTitle(title), waitForDetached ? { state: 'detached' } : {}); |
64 | | - } |
65 | | - |
66 | | - async waitForVisibleByIcon(icon: string, waitForDetached = false): Promise<void> { |
67 | | - await this.page.waitForSelector(this.getSelectorByIcon(icon), waitForDetached ? { state: 'detached' } : {}); |
| 38 | + throw new Error('Could not find status bar element with ID ' + this.id); |
68 | 39 | } |
69 | 40 |
|
70 | | - async isVisible(icon: string | string[], titleContain = ''): Promise<boolean> { |
| 41 | + async isVisible(): Promise<boolean> { |
71 | 42 | try { |
72 | | - const element = await this.getElementHandleByIcon(icon, titleContain); |
73 | | - return !!element && element.isVisible(); |
| 43 | + const element = await this.getElementHandle(); |
| 44 | + return element.isVisible(); |
74 | 45 | } catch (err) { |
75 | 46 | return false; |
76 | 47 | } |
|
0 commit comments