Skip to content

Commit e23b47d

Browse files
authored
e2e: JupyterNB + JupyterLab (#1689)
e2e: JupyterNB + JupyterLab
1 parent deed000 commit e23b47d

File tree

3 files changed

+148
-7
lines changed

3 files changed

+148
-7
lines changed

tests/e2e/tutorials/jupyters.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
// node jupyters.js [url] [user] [password] [--demo]
2+
3+
const utils = require('../utils/utils');
4+
const tutorialBase = require('./tutorialBase');
5+
6+
const args = process.argv.slice(2);
7+
const {
8+
url,
9+
user,
10+
pass,
11+
newUser,
12+
enableDemoMode
13+
} = utils.parseCommandLineArguments(args)
14+
15+
const templateName = "Jupyters";
16+
17+
async function runTutorial() {
18+
const tutorial = new tutorialBase.TutorialBase(url, user, pass, newUser, templateName, enableDemoMode);
19+
20+
tutorial.init();
21+
await tutorial.beforeScript();
22+
await tutorial.goTo();
23+
24+
const needsRegister = await tutorial.registerIfNeeded();
25+
if (!needsRegister) {
26+
await tutorial.login();
27+
}
28+
await tutorial.openTemplate(5000);
29+
30+
// Some time for loading notebook and jupyter lab
31+
await tutorial.waitFor(30000);
32+
33+
34+
// open notebook
35+
await tutorial.openNode(1);
36+
37+
const iframeHandles = await tutorial.getIframe();
38+
// expected two iframes = loading + jupyterNB
39+
const nbIframe = await iframeHandles[1].contentFrame();
40+
41+
// inside the iFrame, open the first notebook
42+
const notebookCBSelector = '#notebook_list > div:nth-child(2) > div > input[type=checkbox]';
43+
await nbIframe.waitForSelector(notebookCBSelector);
44+
await nbIframe.click(notebookCBSelector);
45+
await tutorial.waitFor(2000);
46+
const notebookViewSelector = "#notebook_toolbar > div.col-sm-8.no-padding > div.dynamic-buttons > button.view-button.btn.btn-default.btn-xs"
47+
await nbIframe.waitForSelector(notebookViewSelector);
48+
await nbIframe.click(notebookViewSelector);
49+
await tutorial.waitFor(2000);
50+
await tutorial.takeScreenshot("openNotebook");
51+
52+
// inside the first notebook, click Run button 4 times
53+
const runNBBtnSelector = '#run_int > button:nth-child(1)';
54+
const runNotebookTimes = 5;
55+
for (let i=0; i<runNotebookTimes; i++) {
56+
await nbIframe.waitForSelector(runNBBtnSelector);
57+
await nbIframe.click(runNBBtnSelector);
58+
await tutorial.waitFor(3000);
59+
await tutorial.takeScreenshot("pressRunNB_" + i+1);
60+
}
61+
62+
await tutorial.retrieve();
63+
64+
console.log('Checking results for the notebook:');
65+
await tutorial.openNodeFiles(1);
66+
const outFiles = [
67+
"TheNumberNumber.txt",
68+
"notebooks.zip"
69+
];
70+
await tutorial.checkResults(outFiles.length);
71+
72+
73+
// open jupyter lab
74+
await tutorial.openNode(2);
75+
76+
await tutorial.retrieve();
77+
78+
const iframeHandles2 = await tutorial.getIframe();
79+
// expected three iframes = loading + jupyterNB + jupyterLab
80+
const jLabIframe = await iframeHandles2[2].contentFrame();
81+
82+
// inside the iFrame, open the first notebook
83+
const workFolderSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(3)';
84+
await jLabIframe.waitForSelector(workFolderSelector);
85+
await jLabIframe.click(workFolderSelector, {
86+
clickCount: 2
87+
});
88+
await tutorial.waitFor(2000);
89+
90+
const input2outputFileSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(1)';
91+
await jLabIframe.waitForSelector(input2outputFileSelector);
92+
await jLabIframe.click(input2outputFileSelector, {
93+
clickCount: 2
94+
});
95+
await tutorial.waitFor(2000);
96+
97+
// click Run Menu
98+
const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)';
99+
await jLabIframe.waitForSelector(mainRunMenuBtnSelector);
100+
await jLabIframe.click(mainRunMenuBtnSelector);
101+
await tutorial.waitFor(1000);
102+
103+
// click Run All Cells
104+
const mainRunAllBtnSelector = ' body > div.lm-Widget.p-Widget.lm-Menu.p-Menu.lm-MenuBar-menu.p-MenuBar-menu > ul > li:nth-child(17)';
105+
await jLabIframe.waitForSelector(mainRunAllBtnSelector);
106+
await jLabIframe.click(mainRunAllBtnSelector);
107+
await tutorial.waitFor(6000);
108+
await tutorial.takeScreenshot("pressRunJLab");
109+
110+
111+
await tutorial.removeStudy();
112+
await tutorial.logOut();
113+
await tutorial.close();
114+
}
115+
116+
runTutorial()
117+
.catch(error => {
118+
console.log('Puppeteer error: ' + error);
119+
process.exit(1);
120+
});

tests/e2e/tutorials/tutorialBase.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TutorialBase {
2323

2424
init() {
2525
const dir = 'screenshots';
26-
if (!fs.existsSync(dir)){
26+
if (!fs.existsSync(dir)) {
2727
fs.mkdirSync(dir);
2828
}
2929
}
@@ -161,6 +161,15 @@ class TutorialBase {
161161
await utils.takeScreenshot(this.__page, this.__templateName + "_runStudy_after");
162162
}
163163

164+
async openNode(nodePosInTree = 0) {
165+
await auto.openNode(this.__page, nodePosInTree);
166+
await utils.takeScreenshot(this.__page, this.__templateName + '_openNode_' + nodePosInTree);
167+
}
168+
169+
async getIframe() {
170+
return await this.__page.$$("iframe");
171+
}
172+
164173
async openNodeFiles(nodePosInTree = 0) {
165174
const nodeId = await auto.openNode(this.__page, nodePosInTree);
166175
this.__responsesQueue.addResponseListener("storage/locations/0/files/metadata?uuid_filter=" + nodeId);
@@ -173,11 +182,15 @@ class TutorialBase {
173182
}
174183
}
175184

176-
async openNodeRetrieveAndRestart(nodePosInTree = 0, waitAfterRetrieve = 5000) {
177-
await utils.takeScreenshot(this.__page, "openNodeRetrieveAndRestart_before");
178-
await auto.openNode(this.__page, nodePosInTree);
185+
async retrieve(waitAfterRetrieve = 5000) {
179186
await auto.clickRetrieve(this.__page);
180187
await this.__page.waitFor(waitAfterRetrieve);
188+
}
189+
190+
async openNodeRetrieveAndRestart(nodePosInTree = 0) {
191+
await utils.takeScreenshot(this.__page, "openNodeRetrieveAndRestart_before");
192+
await auto.openNode(this.__page, nodePosInTree);
193+
await this.retrieve();
181194
await auto.clickRestart(this.__page);
182195
await utils.takeScreenshot("openNodeRetrieveAndRestart_after");
183196
}
@@ -218,6 +231,10 @@ class TutorialBase {
218231
async waitFor(waitFor) {
219232
await this.__page.waitFor(waitFor);
220233
}
234+
235+
async takeScreenshot(screenshotTitle) {
236+
await utils.takeScreenshot(this.__page, this.__templateName + '_' + screenshotTitle);
237+
}
221238
}
222239

223240
module.exports = {

tests/e2e/utils/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ function parseCommandLineArguments(args) {
1212
}
1313

1414
const url = args[0];
15-
const enableDemoMode = args.length > 1 ? args[1] === "--demo" : false;
15+
const enableDemoMode = args.includes("--demo");
1616
const {
1717
user,
1818
pass,
1919
newUser
2020
} = getUserAndPass(args);
2121

2222
return {
23-
url, user, pass, newUser, enableDemoMode
23+
url,
24+
user,
25+
pass,
26+
newUser,
27+
enableDemoMode
2428
}
2529
}
2630

@@ -30,7 +34,7 @@ function getUserAndPass(args) {
3034
pass: null,
3135
newUser: true
3236
};
33-
if (args && args.length === 3) {
37+
if (args && args.length > 2) {
3438
userPass.user = args[1];
3539
userPass.pass = args[2];
3640
userPass.newUser = false;

0 commit comments

Comments
 (0)