Skip to content

Commit d38fe91

Browse files
colinRawlingsColin Rawlingsodeimaiz
authored
Use jupyterlabs sim4life in the e2e (ITISFoundation#3068)
* Switch to the jupyterlab test * Update tests/e2e/tutorials/jupyterlabs.js Co-authored-by: Odei Maiz <[email protected]> * Update tests/e2e/tutorials/tutorialBase.js Co-authored-by: Odei Maiz <[email protected]> * Update tests/e2e/tutorials/tutorialBase.js Co-authored-by: Odei Maiz <[email protected]> * Respond to feedback on the PR- const n and timeout Co-authored-by: Colin Rawlings <[email protected]> Co-authored-by: Odei Maiz <[email protected]>
1 parent 1fd02f3 commit d38fe91

File tree

4 files changed

+108
-145
lines changed

4 files changed

+108
-145
lines changed

tests/e2e/jest-puppeteer.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const demo = false;
33
module.exports = {
44
launch: {
55
headless: !demo,
6-
slowMo: demo ? 60 : 0,
6+
slowMo: demo ? 10 : 0,
77
defaultViewport: {
88
width: 1440,
99
height: 900

tests/e2e/tutorials/jupyterlabs.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
startTimeout,
13+
enableDemoMode
14+
} = utils.parseCommandLineArguments(args)
15+
16+
const templateName = "JupyterLabs";
17+
18+
async function runTutorial() {
19+
const tutorial = new tutorialBase.TutorialBase(url, templateName, user, pass, newUser, enableDemoMode);
20+
let studyId
21+
try {
22+
await tutorial.start();
23+
const studyData = await tutorial.openTemplate(1000);
24+
studyId = studyData["data"]["uuid"];
25+
26+
const workbenchData = utils.extractWorkbenchData(studyData["data"]);
27+
await tutorial.waitForServices(
28+
workbenchData["studyId"],
29+
[workbenchData["nodeIds"][1], workbenchData["nodeIds"][2]],
30+
startTimeout,
31+
false
32+
);
33+
34+
await tutorial.waitFor(2000);
35+
36+
for (let j = 1; j < 3; j++) {
37+
// open JLab
38+
await tutorial.openNode(j);
39+
await tutorial.waitFor(35000);
40+
41+
42+
// Run the jlab nbook
43+
const iframeHandles = await tutorial.getIframe();
44+
let iframes2 = [];
45+
for (let i = 0; i < iframeHandles.length; i++) {
46+
const frame = await iframeHandles[i].contentFrame();
47+
iframes2.push(frame);
48+
}
49+
const jLabIframe = iframes2.find(iframe => iframe._url.includes(workbenchData["nodeIds"][j]));
50+
51+
const input2outputFileSelector = '[title~="jl_notebook.ipynb"]';
52+
await jLabIframe.waitForSelector(input2outputFileSelector);
53+
await jLabIframe.click(input2outputFileSelector, {
54+
clickCount: 2
55+
});
56+
await tutorial.waitFor(5000);
57+
// click Run Menu
58+
const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)'; // select the Run Menu
59+
await utils.waitAndClick(jLabIframe, mainRunMenuBtnSelector)
60+
61+
// click Run All Cells
62+
const mainRunAllBtnSelector = '#jp-mainmenu-run > ul > li:nth-child(12)'; // select the Run
63+
await utils.waitAndClick(jLabIframe, mainRunAllBtnSelector)
64+
65+
if (j === 2) {
66+
await tutorial.waitFor(40000); // we are solving an em problem
67+
}
68+
69+
70+
const outFiles = [
71+
"TheNumber.txt",
72+
"workspace.zip"
73+
];
74+
await tutorial.checkNodeOutputs(j, outFiles, true, false);
75+
}
76+
}
77+
catch (err) {
78+
tutorial.setTutorialFailed(true);
79+
console.log('Tutorial error: ' + err);
80+
}
81+
finally {
82+
await tutorial.toDashboard()
83+
await tutorial.removeStudy(studyId, 20000);
84+
await tutorial.logOut();
85+
await tutorial.close();
86+
}
87+
88+
if (tutorial.getTutorialFailed()) {
89+
throw "Tutorial Failed";
90+
}
91+
}
92+
93+
runTutorial()
94+
.catch(error => {
95+
console.log('Puppeteer error: ' + error);
96+
process.exit(1);
97+
});

tests/e2e/tutorials/jupyters.js

Lines changed: 0 additions & 139 deletions
This file was deleted.

tests/e2e/tutorials/tutorialBase.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class TutorialBase {
244244
return resp;
245245
}
246246

247-
async waitForServices(studyId, nodeIds, timeout = 40000) {
247+
async waitForServices(studyId, nodeIds, timeout = 40000, waitForConnected = true) {
248248
if (nodeIds.length < 1) {
249249
return;
250250
}
@@ -253,7 +253,12 @@ class TutorialBase {
253253
while ((new Date().getTime()) - start < timeout) {
254254
for (let i = nodeIds.length - 1; i >= 0; i--) {
255255
const nodeId = nodeIds[i];
256-
if (await utils.isServiceReady(this.__page, studyId, nodeId) && await utils.isServiceConnected(this.__page, studyId, nodeId)) {
256+
let isLoaded = await utils.isServiceReady(this.__page, studyId, nodeId);
257+
if (waitForConnected) {
258+
isLoaded = isLoaded && await utils.isServiceConnected(this.__page, studyId, nodeId);
259+
}
260+
261+
if (isLoaded) {
257262
nodeIds.splice(i, 1);
258263
}
259264
}
@@ -411,12 +416,12 @@ class TutorialBase {
411416
await this.takeScreenshot("closeStudy_after");
412417
}
413418

414-
async removeStudy(studyId) {
415-
await this.waitFor(5000, 'Wait to be unlocked');
419+
async removeStudy(studyId, timeout=5000) {
420+
await this.waitFor(timeout, 'Wait to be unlocked');
416421
await this.takeScreenshot("deleteFirstStudy_before");
417422
try {
418423
// await this.waitForStudyUnlocked(studyId);
419-
const nTries = 3;
424+
const nTries = 10;
420425
let i
421426
for (i = 0; i < nTries; i++) {
422427
const cardUnlocked = await auto.deleteFirstStudy(this.__page, this.__templateName);

0 commit comments

Comments
 (0)