Skip to content

Commit c027086

Browse files
authored
p2e: guest study dispatcher (ITISFoundation#2362)
* vtk_file test added * checkIsOnScreen width and height * a bit of tolerance to deal with zooming factors
1 parent ed7c992 commit c027086

File tree

4 files changed

+117
-3
lines changed

4 files changed

+117
-3
lines changed

services/web/client/source/class/osparc/dashboard/StudyBrowserButtonLoadMore.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,13 @@ qx.Class.define("osparc.dashboard.StudyBrowserButtonLoadMore", {
4444
const rect = element.getBoundingClientRect();
4545
const html = document.documentElement;
4646
return (
47+
rect.width > 0 &&
48+
rect.height > 0 &&
4749
rect.top >= 0 &&
4850
rect.left >= 0 &&
49-
rect.bottom <= (window.innerHeight || html.clientHeight) &&
50-
rect.right <= (window.innerWidth || html.clientWidth)
51+
// a bit of tolerance to deal with zooming factors
52+
rect.bottom*0.95 <= (window.innerHeight || html.clientHeight) &&
53+
rect.right*0.95 <= (window.innerWidth || html.clientWidth)
5154
);
5255
}
5356
return false;

tests/e2e/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
"jest-puppeteer": "^4.4.0",
1212
"log-timestamp": "^0.3.0",
1313
"log4js": "^6.3.0",
14+
"node-fetch": "^2.6.1",
1415
"puppeteer": "^5.5.0"
1516
},
16-
"devDependencies": {},
1717
"scripts": {
1818
"test": "jest --debug --runInBand --colors",
1919
"demo": "node demo/puppeteerDemo.js",

tests/e2e/portal-files/VTK_file.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// node VTK_file.js [url] [download_link] [file_size] [--demo]
2+
3+
const fetch = require('node-fetch');
4+
const tutorialBase = require('../tutorials/tutorialBase');
5+
const utils = require('../utils/utils');
6+
7+
const args = process.argv.slice(2);
8+
const {
9+
urlPrefix,
10+
params,
11+
enableDemoMode
12+
} = utils.parseCommandLineArgumentsStudyDispatcherParams(args);
13+
14+
const fileType = "VTK"
15+
const screenshotPrefix = fileType + "_file_";
16+
17+
18+
async function runTutorial () {
19+
const urlViewers = urlPrefix + "/v0/viewers/default";
20+
const response = await fetch(urlViewers);
21+
const viewers = await response.json();
22+
const viewer = viewers["data"].find(viewer => viewer.file_type === fileType);
23+
24+
const url = new URL(viewer.view_url);
25+
26+
// append the command line arguments
27+
Object.entries(params).forEach(entry => {
28+
const [key, value] = entry;
29+
url.searchParams.append(key, value);
30+
});
31+
32+
const tutorial = new tutorialBase.TutorialBase(url.toString(), screenshotPrefix, null, null, null, enableDemoMode);
33+
34+
try {
35+
tutorial.startScreenshooter();
36+
const page = await tutorial.beforeScript();
37+
const studyData = await tutorial.openStudyLink();
38+
const studyId = studyData["data"]["uuid"];
39+
console.log("Study ID:", studyId);
40+
41+
const workbenchData = utils.extractWorkbenchData(studyData["data"]);
42+
const nodeIdViewer = workbenchData["nodeIds"][1];
43+
await tutorial.waitForServices(workbenchData["studyId"], [nodeIdViewer]);
44+
45+
// Some time for starting the service
46+
await utils.takeScreenshot(page, screenshotPrefix + 'service_started');
47+
48+
const iframeHandles = await page.$$("iframe");
49+
const iframes = [];
50+
for (let i=0; i<iframeHandles.length; i++) {
51+
const frame = await iframeHandles[i].contentFrame();
52+
iframes.push(frame);
53+
}
54+
// url/x/nodeIdViewer
55+
const frame = iframes.find(iframe => iframe._url.includes(nodeIdViewer));
56+
57+
// inside the iFrame, click on document icon on top
58+
const docSelector = '/html/body/div/div/div[1]/div[1]/div[2]/div[1]/div[1]/i[2]';
59+
const docElements = await frame.$x(docSelector);
60+
await docElements[0].click();
61+
62+
// then click on the file to render it
63+
const fileSelector = '/html/body/div/div/div[1]/div[1]/div[2]/div[2]/div/ul[2]';
64+
const fileElements = await frame.$x(fileSelector);
65+
await fileElements[0].click();
66+
67+
await tutorial.waitFor(2000);
68+
await utils.takeScreenshot(page, screenshotPrefix + 'teapot');
69+
}
70+
catch(err) {
71+
tutorial.setTutorialFailed(true);
72+
console.log('Tutorial error: ' + err);
73+
}
74+
finally {
75+
tutorial.stopScreenshooter();
76+
await tutorial.close();
77+
}
78+
79+
if (tutorial.getTutorialFailed()) {
80+
throw "Tutorial Failed";
81+
}
82+
}
83+
84+
runTutorial()
85+
.catch(error => {
86+
console.log('Puppeteer error: ' + error);
87+
process.exit(1);
88+
});

tests/e2e/utils/utils.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ function parseCommandLineArgumentsTemplate(args) {
4747
}
4848
}
4949

50+
function parseCommandLineArgumentsStudyDispatcherParams(args) {
51+
// [url] [download_link] [file_size] [--demo]
52+
53+
if (args.length < 3) {
54+
console.log('More arguments expected: [url] [download_link] [file_size] [--demo]');
55+
process.exit(1);
56+
}
57+
58+
const urlPrefix = args[0];
59+
const params = {};
60+
params["download_link"] = args[1];
61+
params["file_size"] = args[2];
62+
const enableDemoMode = args.includes("--demo");
63+
64+
return {
65+
urlPrefix,
66+
params,
67+
enableDemoMode
68+
}
69+
}
70+
5071
function getUserAndPass(args) {
5172
const userPass = {
5273
user: null,
@@ -238,6 +259,7 @@ async function makePingRequest(page, path) {
238259
// https://github.com/Netflix/pollyjs/issues/149#issuecomment-481108446
239260
await page.setBypassCSP(true);
240261
return await page.evaluate(async (path) => {
262+
// eslint-disable-next-line no-useless-escape
241263
const url = (path).replace(/\/\//g, "\/");
242264
console.log("makePingRequest", url);
243265
return fetch(url, {
@@ -451,6 +473,7 @@ module.exports = {
451473
extractWorkbenchData,
452474
parseCommandLineArguments,
453475
parseCommandLineArgumentsTemplate,
476+
parseCommandLineArgumentsStudyDispatcherParams,
454477
getGrayLogSnapshotUrl,
455478
typeInInputElement,
456479
isElementVisible,

0 commit comments

Comments
 (0)