forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotebookUi.ts
More file actions
76 lines (65 loc) · 2.95 KB
/
notebookUi.ts
File metadata and controls
76 lines (65 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { assert } from 'chai';
import { ElementHandle } from 'playwright-chromium';
import { InteractiveWindowMessages } from '../../../client/datascience/interactive-common/interactiveWindowTypes';
import { BaseWebUI } from './helpers';
enum CellToolbarButton {
run = 0
}
enum MainToolbarButton {
clearOutput = 6
}
export class NotebookEditorUI extends BaseWebUI {
public async getCellCount(): Promise<number> {
const items = await this.page!.$$('.cell-wrapper');
return items.length;
}
public async clearOutput(): Promise<void> {
const runButton = await this.getMainToolbarButton(MainToolbarButton.clearOutput);
await runButton.click({ button: 'left', force: true });
}
public async executeCell(cellIndex: number): Promise<void> {
const renderedPromise = this.waitForMessage(InteractiveWindowMessages.ExecutionRendered);
const runButton = await this.getToolbarButton(cellIndex, CellToolbarButton.run);
await Promise.all([runButton.click({ button: 'left', force: true }), renderedPromise]);
}
public async cellHasOutput(cellIndex: number): Promise<boolean> {
const cell = await this.getCell(cellIndex);
const output = await cell.$$('.cell-output-wrapper');
return output.length > 0;
}
public async getCellOutputHTML(cellIndex: number): Promise<string> {
const output = await this.getCellOutput(cellIndex);
const outputHtml = await output.getProperty('innerHTML');
return outputHtml?.toString() || '';
}
public async getCellOutput(cellIndex: number): Promise<ElementHandle<Element>> {
const cell = await this.getCell(cellIndex);
const output = await cell.$$('.cell-output-wrapper');
if (output.length === 0) {
assert.fail('Cell does not have any output');
}
return output[0];
}
public async getCell(cellIndex: number): Promise<ElementHandle<Element>> {
const items = await this.page!.$$('.cell-wrapper');
return items[cellIndex];
}
private async getMainToolbarButton(button: MainToolbarButton): Promise<ElementHandle<Element>> {
const buttons = await this.page!.$$('.toolbar-menu-bar button[role=button]');
if (buttons.length === 0) {
assert.fail('Main toolbar Buttons not available');
}
return buttons[button];
}
private async getCellToolbar(cellIndex: number): Promise<ElementHandle<Element>> {
const cell = await this.getCell(cellIndex);
return cell.$$('.native-editor-celltoolbar-middle').then((items) => items[0]);
}
private async getToolbarButton(cellIndex: number, button: CellToolbarButton): Promise<ElementHandle<Element>> {
const toolbar = await this.getCellToolbar(cellIndex);
return toolbar.$$('button[role=button]').then((items) => items[button]);
}
}