Skip to content

Commit

Permalink
E2E test: rework notebook functions not to use MS functionality (#5835)
Browse files Browse the repository at this point in the history
Rewrite the notebook functions our tests use not to leverage the MS base
functionality

### QA Notes

All tests should pass.
  • Loading branch information
testlabauto authored Dec 19, 2024
1 parent b73bb15 commit 5f41203
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 19 deletions.
65 changes: 60 additions & 5 deletions test/automation/src/positron/positronNotebooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
*--------------------------------------------------------------------------------------------*/

import { Code } from '../code';
import { Notebook } from '../notebook';
import { PositronQuickInput } from './positronQuickInput';
import { PositronQuickAccess } from './positronQuickaccess';
import { basename } from 'path';
Expand Down Expand Up @@ -35,7 +34,7 @@ export class PositronNotebooks {
notebookProgressBar = this.code.driver.page.locator('[id="workbench\\.parts\\.editor"]').getByRole('progressbar');


constructor(private code: Code, private quickinput: PositronQuickInput, private quickaccess: PositronQuickAccess, private notebook: Notebook) { }
constructor(private code: Code, private quickinput: PositronQuickInput, private quickaccess: PositronQuickAccess) { }

async selectInterpreter(kernelGroup: string, desiredKernel: string) {
await expect(this.notebookProgressBar).not.toBeVisible({ timeout: 30000 });
Expand Down Expand Up @@ -68,13 +67,13 @@ export class PositronNotebooks {
await this.quickinput.selectQuickInputElement(0);

await this.code.waitForElement(ACTIVE_ROW_SELECTOR);
await this.notebook.focusFirstCell();
await this.focusFirstCell();
}

async addCodeToFirstCell(code: string) {
await this.code.driver.page.locator(CELL_LINE).first().click();
await this.notebook.waitForTypeInEditor(code);
await this.notebook.waitForActiveCellEditorContents(code);
await this.waitForTypeInEditor(code);
await this.waitForActiveCellEditorContents(code);
}

async executeCodeInCell() {
Expand Down Expand Up @@ -102,4 +101,60 @@ export class PositronNotebooks {
await expect(stopExecutionLocator).toBeVisible();
await expect(stopExecutionLocator).not.toBeVisible({ timeout: timeout });
}

async focusFirstCell() {
await this.quickaccess.runCommand('notebook.focusTop');
}

async waitForTypeInEditor(text: string): Promise<any> {
const editor = `${ACTIVE_ROW_SELECTOR} .monaco-editor`;

await this.code.driver.page.locator(editor).isVisible();

const textarea = `${editor} textarea`;
await expect(this.code.driver.page.locator(textarea)).toBeFocused();

await this.code.driver.page.locator(textarea).fill(text);

await this._waitForActiveCellEditorContents(c => c.indexOf(text) > -1);
}

private async _waitForActiveCellEditorContents(accept: (contents: string) => boolean): Promise<string> {
const selector = `${ACTIVE_ROW_SELECTOR} .monaco-editor .view-lines`;
const locator = this.code.driver.page.locator(selector);

let content = '';
await expect(async () => {
content = (await locator.textContent())?.replace(/\u00a0/g, ' ') || '';
if (!accept(content)) {
throw new Error(`Content did not match condition: ${content}`);
}
}).toPass();

return content;
}

async waitForActiveCellEditorContents(contents: string): Promise<string> {
return this._waitForActiveCellEditorContents(content => content === contents);
}

async insertNotebookCell(kind: 'markdown' | 'code'): Promise<void> {
if (kind === 'markdown') {
await this.quickaccess.runCommand('notebook.cell.insertMarkdownCellBelow');
} else {
await this.quickaccess.runCommand('notebook.cell.insertCodeCellBelow');
}
}

async stopEditingCell() {
await this.quickaccess.runCommand('notebook.cell.quitEdit');
}

async executeActiveCell(): Promise<void> {
await this.quickaccess.runCommand('notebook.cell.execute');
}

async focusNextCell() {
await this.code.driver.page.keyboard.press('ArrowDown');
}
}
2 changes: 1 addition & 1 deletion test/automation/src/workbench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export class Workbench {
this.positronNewProjectWizard = new PositronNewProjectWizard(code, this.positronQuickaccess);
this.positronOutput = new PositronOutput(code, this.positronQuickaccess, this.positronQuickInput);
this.positronConsole = new PositronConsole(code, this.positronQuickaccess, this.positronQuickInput);
this.positronNotebooks = new PositronNotebooks(code, this.positronQuickInput, this.positronQuickaccess, this.notebook);
this.positronNotebooks = new PositronNotebooks(code, this.positronQuickInput, this.positronQuickaccess);
this.positronWelcome = new PositronWelcome(code);
this.positronTerminal = new PositronTerminal(code);
this.positronViewer = new PositronViewer(code);
Expand Down
12 changes: 6 additions & 6 deletions test/e2e/areas/data-explorer/data-explorer-python-pandas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ df2 = pd.DataFrame(data)`;
const filename = 'pandas-update-dataframe.ipynb';
await app.workbench.positronNotebooks.openNotebook(join(app.workspacePathOrFolder, 'workspaces', 'data-explorer-update-datasets', filename));
await app.workbench.positronNotebooks.selectInterpreter('Python Environments', process.env.POSITRON_PY_VER_SEL!);
await app.workbench.notebook.focusFirstCell();
await app.workbench.notebook.executeActiveCell();
await app.workbench.positronNotebooks.focusFirstCell();
await app.workbench.positronNotebooks.executeActiveCell();

await expect(async () => {
await app.workbench.positronVariables.doubleClickVariableRow('df');
Expand All @@ -151,8 +151,8 @@ df2 = pd.DataFrame(data)`;
}).toPass({ timeout: 60000 });

await app.code.driver.page.locator('.tabs .label-name:has-text("pandas-update-dataframe.ipynb")').click();
await app.workbench.notebook.focusNextCell();
await app.workbench.notebook.executeActiveCell();
await app.workbench.positronNotebooks.focusNextCell();
await app.workbench.positronNotebooks.executeActiveCell();
await app.code.driver.page.locator('.label-name:has-text("Data: df")').click();

await expect(async () => {
Expand All @@ -161,8 +161,8 @@ df2 = pd.DataFrame(data)`;
}).toPass({ timeout: 60000 });

await app.code.driver.page.locator('.tabs .label-name:has-text("pandas-update-dataframe.ipynb")').click();
await app.workbench.notebook.focusNextCell();
await app.workbench.notebook.executeActiveCell();
await app.workbench.positronNotebooks.focusNextCell();
await app.workbench.positronNotebooks.executeActiveCell();
await app.code.driver.page.locator('.label-name:has-text("Data: df")').click();
await app.workbench.positronDataExplorer.selectColumnMenuItem(1, 'Sort Descending');

Expand Down
12 changes: 6 additions & 6 deletions test/e2e/areas/notebook/notebook-create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ test.describe('Notebooks', {
test('Python - Basic notebook creation and execution (markdown) [C628632]', async function ({ app }) {
const randomText = Math.random().toString(36).substring(7);

await app.workbench.notebook.insertNotebookCell('markdown');
await app.workbench.notebook.waitForTypeInEditor(`## ${randomText} `);
await app.workbench.notebook.stopEditingCell();
await app.workbench.positronNotebooks.insertNotebookCell('markdown');
await app.workbench.positronNotebooks.waitForTypeInEditor(`## ${randomText} `);
await app.workbench.positronNotebooks.stopEditingCell();
await app.workbench.positronNotebooks.assertMarkdownText('h2', randomText);
});
});
Expand All @@ -59,9 +59,9 @@ test.describe('Notebooks', {
test('R - Basic notebook creation and execution (markdown) [C628630]', async function ({ app }) {
const randomText = Math.random().toString(36).substring(7);

await app.workbench.notebook.insertNotebookCell('markdown');
await app.workbench.notebook.waitForTypeInEditor(`## ${randomText} `);
await app.workbench.notebook.stopEditingCell();
await app.workbench.positronNotebooks.insertNotebookCell('markdown');
await app.workbench.positronNotebooks.waitForTypeInEditor(`## ${randomText} `);
await app.workbench.positronNotebooks.stopEditingCell();
await app.workbench.positronNotebooks.assertMarkdownText('h2', randomText);
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"license": "MIT",
"scripts": {
"compile": "npm run --prefix ../automation compile && node ../../node_modules/typescript/bin/tsc",
"watch-automation": "yarn --cwd ../automation watch",
"watch-automation": "npm run --prefix ../automation watch",
"watch-e2e": "node ../../node_modules/typescript/bin/tsc --watch --preserveWatchOutput",
"watch": "npm-run-all -lp watch-automation watch-e2e"
},
Expand Down

0 comments on commit 5f41203

Please sign in to comment.