|
1 | 1 | import type {Locator, Page} from '@playwright/test';
|
2 | 2 |
|
3 |
| -import {VISIBILITY_TIMEOUT} from '../TenantPage'; |
| 3 | +import {VISIBILITY_TIMEOUT} from '../../TenantPage'; |
| 4 | + |
| 5 | +import {QueryTabsNavigation} from './QueryTabsNavigation'; |
| 6 | +import {PaneWrapper, ResultTable} from './ResultTable'; |
| 7 | +import {SavedQueriesTable} from './SavedQueriesTable'; |
| 8 | +import {SettingsDialog} from './SettingsDialog'; |
4 | 9 |
|
5 | 10 | export enum QueryMode {
|
6 | 11 | YQLScript = 'YQL Script',
|
@@ -35,175 +40,16 @@ export enum QueryTabs {
|
35 | 40 | Saved = 'Saved',
|
36 | 41 | }
|
37 | 42 |
|
38 |
| -export class QueryTabsNavigation { |
39 |
| - private tabsContainer: Locator; |
40 |
| - |
41 |
| - constructor(page: Page) { |
42 |
| - this.tabsContainer = page.locator('.ydb-query__tabs'); |
43 |
| - } |
44 |
| - |
45 |
| - async selectTab(tabName: QueryTabs) { |
46 |
| - const tab = this.tabsContainer.locator(`role=tab[name="${tabName}"]`); |
47 |
| - await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
48 |
| - await tab.click(); |
49 |
| - } |
50 |
| - |
51 |
| - async isTabSelected(tabName: QueryTabs): Promise<boolean> { |
52 |
| - const tab = this.tabsContainer.locator(`role=tab[name="${tabName}"]`); |
53 |
| - await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
54 |
| - const isSelected = await tab.getAttribute('aria-selected'); |
55 |
| - return isSelected === 'true'; |
56 |
| - } |
57 |
| - |
58 |
| - async getTabHref(tabName: QueryTabs): Promise<string | null> { |
59 |
| - const link = this.tabsContainer.locator(`a:has(div[role="tab"][title="${tabName}"])`); |
60 |
| - await link.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
61 |
| - return link.getAttribute('href'); |
62 |
| - } |
63 |
| -} |
64 |
| - |
65 |
| -export class SettingsDialog { |
66 |
| - private dialog: Locator; |
67 |
| - private page: Page; |
68 |
| - |
69 |
| - constructor(page: Page) { |
70 |
| - this.page = page; |
71 |
| - this.dialog = page.locator('.ydb-query-settings-dialog'); |
72 |
| - } |
73 |
| - |
74 |
| - async changeQueryMode(mode: QueryMode) { |
75 |
| - const dropdown = this.dialog.locator( |
76 |
| - '.ydb-query-settings-dialog__control-wrapper_queryMode', |
77 |
| - ); |
78 |
| - await dropdown.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
79 |
| - await dropdown.click(); |
80 |
| - const popup = this.page.locator('.ydb-query-settings-select__popup'); |
81 |
| - await popup.getByText(mode).first().click(); |
82 |
| - await this.page.waitForTimeout(1000); |
83 |
| - } |
84 |
| - |
85 |
| - async changeTransactionMode(level: string) { |
86 |
| - const dropdown = this.dialog.locator( |
87 |
| - '.ydb-query-settings-dialog__control-wrapper_transactionMode', |
88 |
| - ); |
89 |
| - await dropdown.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
90 |
| - await dropdown.click(); |
91 |
| - const popup = this.page.locator('.ydb-query-settings-select__popup'); |
92 |
| - await popup.getByText(level).first().click(); |
93 |
| - await this.page.waitForTimeout(1000); |
94 |
| - } |
95 |
| - |
96 |
| - async changeStatsLevel(mode: string) { |
97 |
| - const dropdown = this.dialog.locator( |
98 |
| - '.ydb-query-settings-dialog__control-wrapper_statisticsMode', |
99 |
| - ); |
100 |
| - await dropdown.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
101 |
| - await dropdown.click(); |
102 |
| - const popup = this.page.locator('.ydb-query-settings-select__popup'); |
103 |
| - await popup.getByText(mode).first().click(); |
104 |
| - await this.page.waitForTimeout(1000); |
105 |
| - } |
106 |
| - |
107 |
| - async changeLimitRows(limitRows: number) { |
108 |
| - const limitRowsInput = this.dialog.locator('.ydb-query-settings-dialog__limit-rows input'); |
109 |
| - await limitRowsInput.fill(limitRows.toString()); |
110 |
| - await this.page.waitForTimeout(1000); |
111 |
| - } |
112 |
| - |
113 |
| - async clickButton(buttonName: ButtonNames) { |
114 |
| - const button = this.dialog.getByRole('button', {name: buttonName}); |
115 |
| - await button.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
116 |
| - await button.click(); |
117 |
| - } |
118 |
| - |
119 |
| - async isVisible() { |
120 |
| - await this.dialog.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
121 |
| - return true; |
122 |
| - } |
123 |
| - |
124 |
| - async isHidden() { |
125 |
| - await this.dialog.waitFor({state: 'hidden', timeout: VISIBILITY_TIMEOUT}); |
126 |
| - return true; |
127 |
| - } |
128 |
| -} |
129 |
| - |
130 |
| -class PaneWrapper { |
131 |
| - paneWrapper: Locator; |
132 |
| - private radioButton: Locator; |
133 |
| - |
134 |
| - constructor(page: Page) { |
135 |
| - this.paneWrapper = page.locator('.query-editor__pane-wrapper'); |
136 |
| - this.radioButton = this.paneWrapper.locator('.g-radio-button'); |
137 |
| - } |
138 |
| - |
139 |
| - async selectTab(tabName: ResultTabNames) { |
140 |
| - const tab = this.radioButton.getByLabel(tabName); |
141 |
| - await tab.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
142 |
| - await tab.click(); |
143 |
| - } |
144 |
| -} |
145 |
| - |
146 |
| -export class ResultTable { |
147 |
| - private table: Locator; |
148 |
| - private preview: Locator; |
149 |
| - private resultHead: Locator; |
150 |
| - |
151 |
| - constructor(selector: Locator) { |
152 |
| - this.table = selector.locator('.ydb-query-execute-result__result'); |
153 |
| - this.preview = selector.locator('.kv-preview__result'); |
154 |
| - this.resultHead = selector.locator('.ydb-query-execute-result__result-head'); |
155 |
| - } |
156 |
| - |
157 |
| - async isVisible() { |
158 |
| - await this.table.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
159 |
| - return true; |
160 |
| - } |
161 |
| - |
162 |
| - async isHidden() { |
163 |
| - await this.table.waitFor({state: 'hidden', timeout: VISIBILITY_TIMEOUT}); |
164 |
| - return true; |
165 |
| - } |
166 |
| - |
167 |
| - async isPreviewVisible() { |
168 |
| - await this.preview.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
169 |
| - return true; |
170 |
| - } |
171 |
| - |
172 |
| - async isPreviewHidden() { |
173 |
| - await this.preview.waitFor({state: 'hidden', timeout: VISIBILITY_TIMEOUT}); |
174 |
| - return true; |
175 |
| - } |
176 |
| - |
177 |
| - async getRowCount() { |
178 |
| - const rows = this.table.locator('tr'); |
179 |
| - return rows.count(); |
180 |
| - } |
181 |
| - |
182 |
| - async getCellValue(row: number, col: number) { |
183 |
| - const cell = this.table.locator(`tr:nth-child(${row}) td:nth-child(${col})`); |
184 |
| - return cell.innerText(); |
185 |
| - } |
186 |
| - |
187 |
| - async isResultHeaderHidden() { |
188 |
| - await this.resultHead.waitFor({state: 'hidden', timeout: VISIBILITY_TIMEOUT}); |
189 |
| - return true; |
190 |
| - } |
191 |
| - |
192 |
| - async getResultHeadText() { |
193 |
| - await this.resultHead.waitFor({state: 'visible', timeout: VISIBILITY_TIMEOUT}); |
194 |
| - return this.resultHead.innerText(); |
195 |
| - } |
196 |
| -} |
197 |
| - |
198 | 43 | export class QueryEditor {
|
199 | 44 | settingsDialog: SettingsDialog;
|
200 | 45 | paneWrapper: PaneWrapper;
|
201 | 46 | queryTabs: QueryTabsNavigation;
|
202 | 47 | resultTable: ResultTable;
|
| 48 | + savedQueries: SavedQueriesTable; |
| 49 | + editorTextArea: Locator; |
203 | 50 |
|
204 | 51 | private page: Page;
|
205 | 52 | private selector: Locator;
|
206 |
| - private editorTextArea: Locator; |
207 | 53 | private runButton: Locator;
|
208 | 54 | private explainButton: Locator;
|
209 | 55 | private stopButton: Locator;
|
@@ -236,6 +82,7 @@ export class QueryEditor {
|
236 | 82 | this.resultTable = new ResultTable(this.selector);
|
237 | 83 | this.paneWrapper = new PaneWrapper(page);
|
238 | 84 | this.queryTabs = new QueryTabsNavigation(page);
|
| 85 | + this.savedQueries = new SavedQueriesTable(page); |
239 | 86 | }
|
240 | 87 |
|
241 | 88 | async run(query: string, mode: QueryMode) {
|
@@ -390,4 +237,20 @@ export class QueryEditor {
|
390 | 237 | await this.indicatorIcon.waitFor({state: 'hidden', timeout: VISIBILITY_TIMEOUT});
|
391 | 238 | return true;
|
392 | 239 | }
|
| 240 | + |
| 241 | + async waitForStatus(expectedStatus: string, timeout = VISIBILITY_TIMEOUT) { |
| 242 | + await this.executionStatus.waitFor({state: 'visible', timeout}); |
| 243 | + |
| 244 | + // Keep checking status until it matches or times out |
| 245 | + const startTime = Date.now(); |
| 246 | + while (Date.now() - startTime < timeout) { |
| 247 | + const status = await this.executionStatus.innerText(); |
| 248 | + if (status === expectedStatus) { |
| 249 | + return true; |
| 250 | + } |
| 251 | + await this.page.waitForTimeout(100); // Small delay between checks |
| 252 | + } |
| 253 | + |
| 254 | + throw new Error(`Status did not change to ${expectedStatus} within ${timeout}ms`); |
| 255 | + } |
393 | 256 | }
|
0 commit comments