|
1 | 1 | // Copyright 2023-2024 The MathWorks, Inc. |
2 | 2 |
|
3 | 3 | 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'; |
12 | 4 |
|
13 | 5 | test.describe('MATLAB code execution tests', () => { |
14 | 6 | 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); |
23 | 11 | }); |
24 | 12 |
|
25 | 13 | 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); |
29 | 17 |
|
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'); |
35 | 21 | }); |
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 | | - } |
71 | 22 | }); |
0 commit comments