Skip to content

Commit

Permalink
E2E test: remove MS dependencies from positronDataExplorer (#5804)
Browse files Browse the repository at this point in the history
Removing MS dependencies in positronDataExplorer so its pure Playwright.

@:data-explorer

### QA Notes

All tests should pass.
  • Loading branch information
testlabauto authored Dec 18, 2024
1 parent 5613cdc commit 1f8a3f7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 32 deletions.
56 changes: 29 additions & 27 deletions test/automation/src/positron/positronDataExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,27 @@ export class PositronDataExplorer {
*/
async getDataExplorerTableData(): Promise<object[]> {

// unreliable:
//await this.code.waitForElement(IDLE_STATUS);
await this.code.driver.getLocator(IDLE_STATUS).waitFor({ state: 'visible', timeout: 60000 });
await this.code.driver.page.locator(IDLE_STATUS).waitFor({ state: 'visible', timeout: 60000 });

// we have seen intermittent failures where the data explorer is not fully loaded
// even though the status bar is idle. This wait is to ensure the data explorer is fully loaded
// chosing 1000ms as a safe wait time because waitForElement polls at 100ms
// need a brief additional wait
await this.code.wait(1000);

const headers = await this.code.waitForElements(`${COLUMN_HEADERS} ${HEADER_TITLES}`, false);
const rows = await this.code.waitForElements(`${DATA_GRID_ROWS} ${DATA_GRID_ROW}`, true);
const headerNames = headers.map((header) => header.textContent);
const headers = await this.code.driver.page.locator(`${COLUMN_HEADERS} ${HEADER_TITLES}`).all();
const rows = await this.code.driver.page.locator(`${DATA_GRID_ROWS} ${DATA_GRID_ROW}`).all();
const headerNames = await Promise.all(headers.map(async (header) => await header.textContent()));

const tableData: object[] = [];
for (const row of rows) {
const rowData: CellData = {};
let columnIndex = 0;
for (const cell of row.children) {
const innerText = cell.textContent;
for (const cell of await row.locator('> *').all()) {
const innerText = await cell.textContent();
const headerName = headerNames[columnIndex];
// workaround for extra offscreen cells
if (!headerName) {
continue;
}
rowData[headerName] = innerText;
rowData[headerName] = innerText ?? '';
columnIndex++;
}
tableData.push(rowData);
Expand Down Expand Up @@ -115,12 +111,12 @@ export class PositronDataExplorer {
try {
await this.code.driver.page.locator(COLUMN_SELECTOR).click();
const columnText = `${columnName}\n`;
await this.code.waitForSetValue(COLUMN_INPUT, columnText);
await this.code.driver.page.locator(COLUMN_INPUT).fill(columnText);
await this.code.driver.page.locator(COLUMN_SELECTOR_CELL).click();
const checkValue = (await this.code.waitForElement(COLUMN_SELECTOR)).textContent;
const checkValue = await this.code.driver.page.locator(COLUMN_SELECTOR).textContent();
expect(checkValue).toBe(columnName);
} catch (e) {
await this.code.driver.getKeyboard().press('Escape');
await this.code.driver.page.keyboard.press('Escape');
throw e;
}
}).toPass({ timeout: 30000 });
Expand All @@ -129,17 +125,18 @@ export class PositronDataExplorer {
await this.code.driver.page.locator(FUNCTION_SELECTOR).click();

// note that base Microsoft funtionality does not work with "has text" type selection
const equalTo = this.code.driver.getLocator(`${OVERLAY_BUTTON} div:has-text("${functionText}")`);
const equalTo = this.code.driver.page.locator(`${OVERLAY_BUTTON} div:has-text("${functionText}")`);
await equalTo.click();

const filterValueText = `${filterValue}\n`;
await this.code.waitForSetValue(FILTER_SELECTOR, filterValueText);
await this.code.driver.page.locator(FILTER_SELECTOR).fill(filterValueText);

await this.code.driver.page.locator(APPLY_FILTER).click();
}

async getDataExplorerStatusBar() {
return await this.code.waitForElement(STATUS_BAR, (e) => e!.textContent.includes('Showing'));
async getDataExplorerStatusBarText(): Promise<String> {
await expect(this.code.driver.page.locator(STATUS_BAR)).toHaveText(/Showing/, { timeout: 60000 });
return (await this.code.driver.page.locator(STATUS_BAR).textContent()) ?? '';
}

async selectColumnMenuItem(columnIndex: number, menuItem: string) {
Expand Down Expand Up @@ -179,13 +176,13 @@ export class PositronDataExplorer {
}

async getColumnMissingPercent(rowNumber: number): Promise<string> {
const row = this.code.driver.getLocator(MISSING_PERCENT(rowNumber));
const row = this.code.driver.page.locator(MISSING_PERCENT(rowNumber));
return await row.innerText();
}

async getColumnProfileInfo(rowNumber: number): Promise<ColumnProfile> {

const expandCollapseLocator = this.code.driver.getLocator(EXPAND_COLLAPSE_PROFILE(rowNumber));
const expandCollapseLocator = this.code.driver.page.locator(EXPAND_COLLAPSE_PROFILE(rowNumber));

await expandCollapseLocator.scrollIntoViewIfNeeded();
await expandCollapseLocator.click();
Expand All @@ -194,19 +191,24 @@ export class PositronDataExplorer {

const profileData: { [key: string]: string } = {};

const labels = await this.code.waitForElements(PROFILE_LABELS(rowNumber), false, (elements) => elements.length > 2);
const values = await this.code.waitForElements(PROFILE_VALUES(rowNumber), false, (elements) => elements.length > 2);
const labelsLocator = this.code.driver.page.locator(PROFILE_LABELS(rowNumber));
await expect.poll(async () => (await labelsLocator.all()).length).toBeGreaterThan(2);
const labels = await labelsLocator.all();

const valuesLocator = this.code.driver.page.locator(PROFILE_VALUES(rowNumber));
await expect.poll(async () => (await valuesLocator.all()).length).toBeGreaterThan(2);
const values = await valuesLocator.all();

for (let i = 0; i < labels.length; i++) {
const label = labels[i].textContent;
const value = values[i].textContent;
const label = await labels[i].textContent();
const value = await values[i].textContent();
if (label && value) {
profileData[label] = value; // Assign label as key and value as value
}
}

// some rects have "count" class, some have "bin-count" class, some have "count other" class
const rects = await this.code.driver.getLocator('.column-profile-sparkline').locator('[class*="count"]').all();
const rects = await this.code.driver.page.locator('.column-profile-sparkline').locator('[class*="count"]').all();
const profileSparklineHeights: string[] = [];
for (let i = 0; i < rects.length; i++) {
const height = await rects[i].getAttribute('height');
Expand All @@ -231,7 +233,7 @@ export class PositronDataExplorer {
}

async expandColumnProfile(rowNumber = 0): Promise<void> {
await this.code.driver.getLocator(EXPAND_COLLASPE_ICON).nth(rowNumber).click();
await this.code.driver.page.locator(EXPAND_COLLASPE_ICON).nth(rowNumber).click();
}

async maximizeDataExplorer(collapseSummary: boolean = false): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion test/automation/src/positron/positronPopups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class PositronPopups {
this.code.logger.log(`Closing ${count} toasts`);
for (let i = 0; i < count; i++) {
await this.toastLocator.nth(i).hover();
await this.code.driver.page.locator(`${NOTIFICATION_TOAST} .codicon-notifications-clear`).click();
await this.code.driver.page.locator(`${NOTIFICATION_TOAST} .codicon-notifications-clear`).nth(i).click();
}
}

Expand Down
8 changes: 4 additions & 4 deletions test/e2e/areas/data-explorer/large-data-frame.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ test.describe('Data Explorer - Large Data Frame', {
await app.workbench.positronDataExplorer.clickUpperLeftCorner();
await app.workbench.positronDataExplorer.addFilter(...FILTER_PARAMS as [string, string, string]);

const statusBar = await app.workbench.positronDataExplorer.getDataExplorerStatusBar();
expect(statusBar.textContent).toBe(POST_FILTER_DATA_SUMMARY);
const statusBarText = await app.workbench.positronDataExplorer.getDataExplorerStatusBarText();
expect(statusBarText).toBe(POST_FILTER_DATA_SUMMARY);
}).toPass();

});
Expand Down Expand Up @@ -84,8 +84,8 @@ test.describe('Data Explorer - Large Data Frame', {
// Filter data set
await app.workbench.positronDataExplorer.clickUpperLeftCorner();
await app.workbench.positronDataExplorer.addFilter(...FILTER_PARAMS as [string, string, string]);
const statusBar = await app.workbench.positronDataExplorer.getDataExplorerStatusBar();
expect(statusBar.textContent).toBe(POST_FILTER_DATA_SUMMARY);
const statusBarText = await app.workbench.positronDataExplorer.getDataExplorerStatusBarText();
expect(statusBarText).toBe(POST_FILTER_DATA_SUMMARY);
}).toPass();

});
Expand Down

0 comments on commit 1f8a3f7

Please sign in to comment.