Skip to content

Commit

Permalink
e2e: JupyterNB + JupyterLab (#1689)
Browse files Browse the repository at this point in the history
e2e: JupyterNB + JupyterLab
  • Loading branch information
odeimaiz authored Aug 11, 2020
1 parent deed000 commit e23b47d
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 7 deletions.
120 changes: 120 additions & 0 deletions tests/e2e/tutorials/jupyters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// node jupyters.js [url] [user] [password] [--demo]

const utils = require('../utils/utils');
const tutorialBase = require('./tutorialBase');

const args = process.argv.slice(2);
const {
url,
user,
pass,
newUser,
enableDemoMode
} = utils.parseCommandLineArguments(args)

const templateName = "Jupyters";

async function runTutorial() {
const tutorial = new tutorialBase.TutorialBase(url, user, pass, newUser, templateName, enableDemoMode);

tutorial.init();
await tutorial.beforeScript();
await tutorial.goTo();

const needsRegister = await tutorial.registerIfNeeded();
if (!needsRegister) {
await tutorial.login();
}
await tutorial.openTemplate(5000);

// Some time for loading notebook and jupyter lab
await tutorial.waitFor(30000);


// open notebook
await tutorial.openNode(1);

const iframeHandles = await tutorial.getIframe();
// expected two iframes = loading + jupyterNB
const nbIframe = await iframeHandles[1].contentFrame();

// inside the iFrame, open the first notebook
const notebookCBSelector = '#notebook_list > div:nth-child(2) > div > input[type=checkbox]';
await nbIframe.waitForSelector(notebookCBSelector);
await nbIframe.click(notebookCBSelector);
await tutorial.waitFor(2000);
const notebookViewSelector = "#notebook_toolbar > div.col-sm-8.no-padding > div.dynamic-buttons > button.view-button.btn.btn-default.btn-xs"
await nbIframe.waitForSelector(notebookViewSelector);
await nbIframe.click(notebookViewSelector);
await tutorial.waitFor(2000);
await tutorial.takeScreenshot("openNotebook");

// inside the first notebook, click Run button 4 times
const runNBBtnSelector = '#run_int > button:nth-child(1)';
const runNotebookTimes = 5;
for (let i=0; i<runNotebookTimes; i++) {
await nbIframe.waitForSelector(runNBBtnSelector);
await nbIframe.click(runNBBtnSelector);
await tutorial.waitFor(3000);
await tutorial.takeScreenshot("pressRunNB_" + i+1);
}

await tutorial.retrieve();

console.log('Checking results for the notebook:');
await tutorial.openNodeFiles(1);
const outFiles = [
"TheNumberNumber.txt",
"notebooks.zip"
];
await tutorial.checkResults(outFiles.length);


// open jupyter lab
await tutorial.openNode(2);

await tutorial.retrieve();

const iframeHandles2 = await tutorial.getIframe();
// expected three iframes = loading + jupyterNB + jupyterLab
const jLabIframe = await iframeHandles2[2].contentFrame();

// inside the iFrame, open the first notebook
const workFolderSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(3)';
await jLabIframe.waitForSelector(workFolderSelector);
await jLabIframe.click(workFolderSelector, {
clickCount: 2
});
await tutorial.waitFor(2000);

const input2outputFileSelector = '#filebrowser > div.lm-Widget.p-Widget.jp-DirListing.jp-FileBrowser-listing.jp-DirListing-narrow > ul > li:nth-child(1)';
await jLabIframe.waitForSelector(input2outputFileSelector);
await jLabIframe.click(input2outputFileSelector, {
clickCount: 2
});
await tutorial.waitFor(2000);

// click Run Menu
const mainRunMenuBtnSelector = '#jp-MainMenu > ul > li:nth-child(4)';
await jLabIframe.waitForSelector(mainRunMenuBtnSelector);
await jLabIframe.click(mainRunMenuBtnSelector);
await tutorial.waitFor(1000);

// click Run All Cells
const mainRunAllBtnSelector = ' body > div.lm-Widget.p-Widget.lm-Menu.p-Menu.lm-MenuBar-menu.p-MenuBar-menu > ul > li:nth-child(17)';
await jLabIframe.waitForSelector(mainRunAllBtnSelector);
await jLabIframe.click(mainRunAllBtnSelector);
await tutorial.waitFor(6000);
await tutorial.takeScreenshot("pressRunJLab");


await tutorial.removeStudy();
await tutorial.logOut();
await tutorial.close();
}

runTutorial()
.catch(error => {
console.log('Puppeteer error: ' + error);
process.exit(1);
});
25 changes: 21 additions & 4 deletions tests/e2e/tutorials/tutorialBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class TutorialBase {

init() {
const dir = 'screenshots';
if (!fs.existsSync(dir)){
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}
Expand Down Expand Up @@ -161,6 +161,15 @@ class TutorialBase {
await utils.takeScreenshot(this.__page, this.__templateName + "_runStudy_after");
}

async openNode(nodePosInTree = 0) {
await auto.openNode(this.__page, nodePosInTree);
await utils.takeScreenshot(this.__page, this.__templateName + '_openNode_' + nodePosInTree);
}

async getIframe() {
return await this.__page.$$("iframe");
}

async openNodeFiles(nodePosInTree = 0) {
const nodeId = await auto.openNode(this.__page, nodePosInTree);
this.__responsesQueue.addResponseListener("storage/locations/0/files/metadata?uuid_filter=" + nodeId);
Expand All @@ -173,11 +182,15 @@ class TutorialBase {
}
}

async openNodeRetrieveAndRestart(nodePosInTree = 0, waitAfterRetrieve = 5000) {
await utils.takeScreenshot(this.__page, "openNodeRetrieveAndRestart_before");
await auto.openNode(this.__page, nodePosInTree);
async retrieve(waitAfterRetrieve = 5000) {
await auto.clickRetrieve(this.__page);
await this.__page.waitFor(waitAfterRetrieve);
}

async openNodeRetrieveAndRestart(nodePosInTree = 0) {
await utils.takeScreenshot(this.__page, "openNodeRetrieveAndRestart_before");
await auto.openNode(this.__page, nodePosInTree);
await this.retrieve();
await auto.clickRestart(this.__page);
await utils.takeScreenshot("openNodeRetrieveAndRestart_after");
}
Expand Down Expand Up @@ -218,6 +231,10 @@ class TutorialBase {
async waitFor(waitFor) {
await this.__page.waitFor(waitFor);
}

async takeScreenshot(screenshotTitle) {
await utils.takeScreenshot(this.__page, this.__templateName + '_' + screenshotTitle);
}
}

module.exports = {
Expand Down
10 changes: 7 additions & 3 deletions tests/e2e/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ function parseCommandLineArguments(args) {
}

const url = args[0];
const enableDemoMode = args.length > 1 ? args[1] === "--demo" : false;
const enableDemoMode = args.includes("--demo");
const {
user,
pass,
newUser
} = getUserAndPass(args);

return {
url, user, pass, newUser, enableDemoMode
url,
user,
pass,
newUser,
enableDemoMode
}
}

Expand All @@ -30,7 +34,7 @@ function getUserAndPass(args) {
pass: null,
newUser: true
};
if (args && args.length === 3) {
if (args && args.length > 2) {
userPass.user = args[1];
userPass.pass = args[2];
userPass.newUser = false;
Expand Down

0 comments on commit e23b47d

Please sign in to comment.