Skip to content

Commit 035236c

Browse files
pauldruceprabhakk-mw
authored andcommitted
Update e2e tests & testing frameworks.
# Main Changes * Update NodeJS packages to use a version greater or equal to 5.3.0 of @jupyterlab/galata * Update the tests to leverage the Galata tools for interacting with notebooks. * Remove all unused utility functions.
1 parent 9ca5408 commit 035236c

File tree

7 files changed

+1845
-1815
lines changed

7 files changed

+1845
-1815
lines changed

.github/workflows/run-e2e-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ jobs:
7171
run: |
7272
python3 -m pip install --upgrade pip
7373
python3 -m pip install pytest-playwright
74-
python3 -m playwright install --with-deps
75-
(cd tests/utils && mkdir licensing-logs && python3 -c "from licensing import *; license_with_online_licensing(log_dir=\"./licensing-logs\")")
74+
python3 -m playwright install chromium --with-deps
75+
(cd tests/utils && python3 -c "from licensing import *; license_with_online_licensing(log_dir=\"./licensing-logs\")")
7676
7777
- name: Run playwright tests
7878
env:

tests/e2e/package-lock.json

Lines changed: 1827 additions & 1517 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/e2e/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
"stop":"npm run stop-jlab",
1212
"start-jlab": "nohup python3 -m jupyter lab --config ./jupyter_server_test_config.py > ./jupyterlab.log 2>&1 & echo $! > ./jlab.pid",
1313
"stop-jlab": "kill $(cat ./jlab.pid) && rm -rf ./jlab.pid",
14-
"print-jlab-url": "echo \"JupyterLab URLs:\"; sleep 1; grep -oP 'ServerApp]\\s*http[s]?://[^ ]+' ./jupyterlab.log || echo \"Error: No JupyterLab url found, please check log file ./jupyterlab.log\""
14+
"print-jlab-url": "echo \"JupyterLab URLs:\"; sleep 2; grep -oP 'ServerApp]\\s*http[s]?://[^ ]+' ./jupyterlab.log || echo \"Error: No JupyterLab url found, please check log file ./jupyterlab.log\""
1515
},
1616
"devDependencies": {
17-
"@jupyterlab/galata": "^5.0.0",
17+
"@jupyterlab/galata": "^5.3.0",
1818
"@playwright/test": "^1.34.0",
1919
"@types/node": "^20.0.0",
2020
"@typescript-eslint/eslint-plugin": "^6.0.0",
Lines changed: 10 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,22 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

33
import { expect, test } from '@jupyterlab/galata';
4-
import { Locator, Page } from '@playwright/test';
5-
import config from '../playwright.config';
6-
7-
import {
8-
openMatlabKernelFromLauncher,
9-
waitForKernelToBeIdle,
10-
waitUntilEditorReady
11-
} from './utils/matlab_notebook';
124

135
test.describe('MATLAB code execution tests', () => {
146
test.beforeEach(async ({ page }) => {
15-
// Open MATLAB Kernel from Jupyter Lab Launcher
16-
await openMatlabKernelFromLauncher(page);
17-
18-
// Wait for kernel to be idle
19-
await waitForKernelToBeIdle(page);
20-
21-
// Wait until the editor is ready to be filled.
22-
await waitUntilEditorReady(page);
7+
const notebookName = 'matlab-code-execution.ipynb';
8+
await page.notebook.createNew(notebookName, { kernel: 'jupyter_matlab_kernel' });
9+
await page.notebook.isOpen(notebookName);
10+
await page.notebook.isActive(notebookName);
2311
});
2412

2513
test('Calling "ver" produces correct output', async ({ page }) => {
26-
await enterInputInCell(page, ['ver']);
27-
// wait for kernel to be idle
28-
await waitForKernelToBeIdle(page);
14+
test.setTimeout(90 * 1000);
15+
await page.notebook.setCell(0, 'code', 'ver');
16+
await page.notebook.runCell(0);
2917

30-
const assertTimeout = 90 * 1000; // 90 seconds
31-
await assertCellOutputContainsText(
32-
page,
33-
'MATLAB License Number',
34-
assertTimeout);
18+
const cellOutput = await page.notebook.getCellTextOutput(0) ?? [''];
19+
expect(cellOutput.length).toBeGreaterThan(0);
20+
expect(cellOutput[0]).toContain('MATLAB License Number');
3521
});
36-
37-
async function enterInputInCell (page: Page, inputArray: Array<string>) {
38-
const cellTextbox = await getCellTextBox(page);
39-
for (const input of inputArray) {
40-
await cellTextbox.fill(input);
41-
await cellTextbox.press('Enter');
42-
}
43-
await cellTextbox.press('Shift+Enter');
44-
}
45-
46-
async function getCellTextBox (page: Page): Promise<Locator> {
47-
// Get the text box area to interact with.
48-
const notebookContent = page.getByRole(
49-
'region',
50-
{ name: 'notebook content' });
51-
await expect(notebookContent).toBeVisible();
52-
53-
const cellTextbox = notebookContent.getByRole('textbox').nth(0);
54-
await expect(cellTextbox).toBeEditable();
55-
await expect(cellTextbox).toBeVisible();
56-
return cellTextbox;
57-
}
58-
59-
// Use only for Text Outputs
60-
async function assertCellOutputContainsText (
61-
page: Page,
62-
outputString: string,
63-
timeout: number = config.expect.timeout) {
64-
const outputArea = page.locator('.jp-OutputArea').nth(0);
65-
const outputAreaOutput = outputArea
66-
.locator('.jp-OutputArea-output')
67-
.first();
68-
await expect(outputAreaOutput).toBeVisible();
69-
await expect(outputAreaOutput).toContainText(outputString, { timeout });
70-
}
7122
});

tests/e2e/tests/ui_tests.test.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
// Copyright 2023-2024 The MathWorks, Inc.
22

33
import { expect, test } from '@jupyterlab/galata';
4+
import { Locator } from '@playwright/test';
45

56
test.describe('MATLAB File button', () => {
7+
let MATLABFileButton: Locator;
68
test.beforeEach(async ({ page }) => {
7-
await page.waitForLoadState();
9+
await page.launcher.waitFor({ state: 'visible' });
10+
MATLABFileButton = page.getByText('MATLAB File', { exact: true });
811
});
912

1013
test('is visible on Launcher', async ({ page }) => {
11-
const MATLABFileButton = page.getByRole(
12-
'region',
13-
{ name: 'notebook content' })
14-
.getByText('MATLAB File');
1514
await expect(MATLABFileButton).toBeVisible();
1615
});
1716

1817
test('takes you to .m file', async ({ page }) => {
19-
const MATLABFileButton = page.getByRole(
20-
'region',
21-
{ name: 'notebook content' })
22-
.getByText('MATLAB File');
2318
await MATLABFileButton.click();
2419

2520
// Expect a new untitled file ending in .m to be made, with optional

tests/e2e/tests/utils/licensing.ts

Lines changed: 0 additions & 176 deletions
This file was deleted.

tests/e2e/tests/utils/matlab_notebook.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)