-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Playwright API for Notebooks #14098
Conversation
4360985
to
cf61513
Compare
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? |
b26e767
to
3bf21ae
Compare
5bd36ce
to
a55c115
Compare
Rebased on master and squashed commits. |
There was a problem hiding this 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?
There was a problem hiding this 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.
.github/workflows/playwright.yml
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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); | ||
} |
There was a problem hiding this comment.
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.
const line = await this.editor.lineByLineNumber(lineNumber); | ||
await line?.click(); | ||
await this.page.keyboard.type(text); |
There was a problem hiding this comment.
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... |
There was a problem hiding this comment.
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... |
There was a problem hiding this comment.
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>[]> { |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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'> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
075c257
to
44db665
Compare
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 |
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 |
There was a problem hiding this 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!
@JonasHelming @msujew |
e861cb3
to
0d24d30
Compare
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
Co-authored-by: Philip Langer <[email protected]>
0d24d30
to
d266322
Compare
@msujew |
@dhuebner Great, thank you! |
What it does
Adds Playwright page objects to interact with a notebook Editor and its cells.
Following actions are supported:
All of the above listed functionalities are tested in theia-notebook-editor.test.ts playwright test.
Additional note:
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