Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playwright API for Notebooks #14098

Merged
merged 7 commits into from
Oct 9, 2024

Conversation

dhuebner
Copy link
Member

@dhuebner dhuebner commented Aug 30, 2024

What it does

Adds Playwright page objects to interact with a notebook Editor and its cells.
Following actions are supported:

  • Open a Notebook Editor
  • Select a Kernel and read selected kernel name.
  • Adding a new Code/Markdown Cell
  • Read Cell mode (e.g. python, markdown etc.)
  • Getting cell editor text and adding text to the cell editor
  • Execute a cell
  • Read cell execution count
  • Read cell output

All of the above listed functionalities are tested in theia-notebook-editor.test.ts playwright test.

Additional note:

  • Playwright job now stores (for 2 days) test failure screenshots on failure. Results are in the zip called playwright-test-results and can be found in the action output.

How to test

Run theia-notebook-editor.test.ts mentioned above.

Follow-ups

Planned is to add other handy features like e.g. interaction with cell's toolbar or asserting error output.

Review checklist

Reminder for reviewers

@dhuebner
Copy link
Member Author

The failing CI tests might indicates that a kernel installation is missing. I can check the Python setup for the corresponding GH action. Or maybe some expert could help faster?

@dhuebner dhuebner force-pushed the dhuebner/notebook-ui-tests branch 3 times, most recently from b26e767 to 3bf21ae Compare September 3, 2024 14:50
@dhuebner dhuebner force-pushed the dhuebner/notebook-ui-tests branch 2 times, most recently from 5bd36ce to a55c115 Compare September 4, 2024 11:57
@dhuebner
Copy link
Member Author

dhuebner commented Sep 4, 2024

Rebased on master and squashed commits.

@dhuebner dhuebner requested a review from msujew September 4, 2024 11:59
Copy link
Member

@msujew msujew left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty good to me. However, I would like to get a review from someone more familiar with Playwright before merging this @JonasHelming do you think someone from ES could spare some time to review this?

Copy link
Contributor

@planger planger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much! This looks great. 👍
I just added a few inline uncritical comments.

@@ -51,3 +58,11 @@ jobs:
- name: Test (playwright)
shell: bash
run: yarn --cwd examples/playwright ui-tests-ci

- name: Archive test results
uses: actions/upload-artifact@v4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we try to pin actions to concrete git commit hashes for security reason. I think v4 resolves to 50769540e7f4bd5e21e526ee35c689e35e0d6874 at the moment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will change that, security first!

@@ -21,6 +21,7 @@ const ciConfig: PlaywrightTestConfig = {
...baseConfig,
workers: 1,
retries: 2,
timeout: 30 * 1000,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that the default timeout? I'm not against adding it anyway, but I'm wondering why it was added.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove it again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, I know why it is explicitly listed. CI config extends the baseConfig where the time out is 60sec which is way too much IMHO.


test('kernels are installed', async () => {
editor = await app.openEditor('sample.ipynb', TheiaNotebookEditor);
await editor.tabLocator().click(); // force activate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might be better to move that into the TheiaNotebookEditor page object, if this is really necessary. Otherwise every test would have to be aware that this needs to be called before subsequent interactions.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was an attempt to fix flakiness on first run. I didn't found out why, but right after the start and opening an editor the focus jumps to the browser address field. Now I think it was because the "Workspace trust" message dialog was popping-up. It should no longer be necessary as the check is disabled in the example project package.json. I will remove this lines, let's see if the tests are passing in CI.

examples/playwright/src/theia-notebook-cell.ts Outdated Show resolved Hide resolved
Comment on lines 71 to 82
const lines: string[] = [];
const linesCount = await this.monacoEditor.numberOfLines();
if (linesCount === undefined) {
return undefined;
}
for (let line = 1; line <= linesCount; line++) {
const lineText = await this.monacoEditor.textContentOfLineByLineNumber(line);
if (lineText === undefined) {
break;
}
lines.push(lineText);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to move this into the TheiaMonacoEditor? I guess this functionality could be useful in general for the text editor and would then be easier to test and maintain, if it is at a single place.

Comment on lines 92 to 94
const line = await this.editor.lineByLineNumber(lineNumber);
await line?.click();
await this.page.keyboard.type(text);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I think it could make sense to move this behavior into the TheiaMonacoEditor.

* @param kernelName The name of the kernel to select.
*/
async selectKernel(kernelName: string): Promise<void> {
// TODO should we use NotebookCommands.SELECT_KERNEL_COMMAND.id? Need a dependency...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, I think I tend to avoid this dependency but rather introduce a namespace with constants here in the Playwright page object library.

}

async availableKernels(): Promise<string[]> {
// TODO should we use NotebookCommands.SELECT_KERNEL_COMMAND.id? Need a dependency...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, I'd have a slight preference to introduce a namespace with constants in this page object file.

@@ -78,4 +78,14 @@ export class TheiaQuickCommandPalette extends TheiaPageObject {
}
return command.$('.monaco-list-row.focused .monaco-highlighted-label');
}

async visibleItems(): Promise<ElementHandle<SVGElement | HTMLElement>[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, we should add a dedicated test for that new method in examples/playwright/src/tests/theia-quick-command.test.ts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test is added

@@ -152,17 +152,17 @@ export class NotebookMainToolbar extends React.Component<NotebookMainToolbarProp

override render(): React.ReactNode {
const menuItems = this.getMenuItems();
return <div className='theia-notebook-main-toolbar'>
return <div className='theia-notebook-main-toolbar' id='notebook-main-toolbar'>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it save to use a static id here? Couldn't there be more than one toolbars in the DOM, eventually leading to non-unique IDs in the DOM? If yes, it might be better to use data-<xyz> attributes and locate them in the context of a parent?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is okay to use a static id for the main toolbar. Should be only one, right? In case there are other sibling toolbars with the same id it can be handled as a list. For react one will need to adjust the key property.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is one toolbar per editor, meaning that it's not unique. I.e. if you have two notebook editors side by side, it will no longer be unique.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will be unique if using locator API instead of selector, what I do in notebook editor page object. Locator gives you the Notebook editor element under test, hence all subsequent queries are applied on the editor element and not the whole page.

@dhuebner dhuebner force-pushed the dhuebner/notebook-ui-tests branch 2 times, most recently from 075c257 to 44db665 Compare September 19, 2024 12:09
@dhuebner
Copy link
Member Author

I have no idea why it started to fail now.
test-failed-1

@dhuebner
Copy link
Member Author

Tests are running now. The cause was that a wrong Python 3.10 version was picked by default, where it should be Python 3.11. Fixed it now by requesting 3.11.* explicitly.

@planger
Thanks for your detailed feedback!
I've applied all of your suggestions except the one with the id for the main toolbar. I think it is not necessary and having a dynamic id will make the querying by ID inside the test more complex. Could you please review the current state?

@dhuebner
Copy link
Member Author

Btw. the playwright reports are now created also on successful job run and are stored in job's Artifacts for two days. See for example: https://github.com/eclipse-theia/theia/actions/runs/10943260523?pr=14098

Copy link
Contributor

@planger planger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the revision. Looks great to me!

@dhuebner
Copy link
Member Author

@JonasHelming @msujew
Then this PR can be merged. I'm looking forward to see it in the upcoming .next release.

@msujew
Copy link
Member

msujew commented Oct 7, 2024

@dhuebner @planger FYI I would wait to merge this after #14234 has been merged. Just so we can fix unanticipated breakage in the playwright tests in this PR already.

@msujew
Copy link
Member

msujew commented Oct 8, 2024

@dhuebner Do you mind rebasing? #14234 has been merged.

dhuebner and others added 6 commits October 9, 2024 13:45
Interact with monaco editor inside a cell

Cell execute and get output functionality

Fixed linting errors

Cell Execution count access and test

Install IPython kernel for the playwright job

Download required plug-ins

Fixed failing cell execution count test

Move notebook related plugins to the root package.json

Some clean-ups
@dhuebner
Copy link
Member Author

dhuebner commented Oct 9, 2024

@msujew
PR is ready to merge now. I've added an additional test to cover the new "split cell" action.

@msujew
Copy link
Member

msujew commented Oct 9, 2024

@dhuebner Great, thank you!

@msujew msujew merged commit 6b7ceb7 into eclipse-theia:master Oct 9, 2024
11 checks passed
@dhuebner dhuebner deleted the dhuebner/notebook-ui-tests branch October 9, 2024 13:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants