Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions tests/e2e/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# end-to-end (e2e) testing


Presentation "[Understanding e2e testing](https://docs.google.com/presentation/d/1Kc2kz1e6Fl3XNDGXfPx_Aurqx29edGuke4rnIfHr5bI/edit?usp=sharing)" by @odeimaiz on Dec 2, 2020


**WARNING**: Be aware that running these tests in your host might risk changing some
configuration.
Expand Down Expand Up @@ -49,8 +54,21 @@ Add the following configuration to your local ``launch.json``:
```
Now you can run the tests by clicking on the Play button, using that configuration. It should allow you to insert breakpoints and inspect variables.

## To run the tutorials
```bash

## Run end-to-end

```cmd
cd tests/e2e
npm install --save
node tutorials/{{test.js}} {{deployment}} ({{user}}) ({{password}}) (--demo)
node tutorials/sleepers.js https://osparc-master.speag.com/ user@domain mypass --demo
```
## Run portal-to-end

```cmd
cd tests/e2e
node tutorials/<tutorial>.js [<user> <password>]
npm install --save
node portal/{{test.js}} {{deployment}}/study/ {{published_template_uuid}}
# example
node portal/2D_Plot.js https://osparc-master.speag.com/study/ 003aaf4a-524a-11ea-b061-02420a00070b
```
83 changes: 45 additions & 38 deletions tests/e2e/tutorials/tutorialBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const utils = require('../utils/utils');
const responses = require('../utils/responsesQueue');

class TutorialBase {
constructor(url, templateName, user, pass, newUser, enableDemoMode=false) {
constructor(url, templateName, user, pass, newUser, enableDemoMode = false) {
this.__demo = enableDemoMode;
this.__templateName = templateName;

Expand All @@ -28,12 +28,12 @@ class TutorialBase {
try {
utils.createScreenshotsDir();
}
catch(err) {
catch (err) {
console.error("Error creating screenshots directory", err);
throw(err);
throw (err);
}

this.__interval = setInterval(async() => {
this.__interval = setInterval(async () => {
await this.takeScreenshot();
}, 2000);
}
Expand All @@ -55,9 +55,9 @@ class TutorialBase {
try {
await this.__page.goto(this.__url);
}
catch(err) {
catch (err) {
console.error(this.__url, "can't be reached", err);
throw(err);
throw (err);
}
const domain = utils.getDomain(this.__url);
await this.takeScreenshot("landingPage_" + domain);
Expand All @@ -73,9 +73,9 @@ class TutorialBase {
await this.login();
}
}
catch(err) {
catch (err) {
console.error("Error starting", err);
throw(err);
throw (err);
}
}

Expand All @@ -87,9 +87,9 @@ class TutorialBase {
await this.__goTo();
resp = await this.__responsesQueue.waitUntilResponse("open", openStudyTimeout);
}
catch(err) {
catch (err) {
console.error(this.__templateName, "could not be started", err);
throw(err);
throw (err);
}
return resp;
}
Expand All @@ -109,9 +109,9 @@ class TutorialBase {
try {
await auto.logIn(this.__page, this.__user, this.__pass);
}
catch(err) {
catch (err) {
console.error("Failed logging in", err);
throw(err);
throw (err);
}

try {
Expand All @@ -122,19 +122,19 @@ class TutorialBase {
console.log(" - ", template.name);
});
}
catch(err) {
catch (err) {
console.error("Templates could not be fetched", err);
throw(err);
throw (err);
}

try {
const resp = await this.__responsesQueue.waitUntilResponse("catalog/services");
const services = resp["data"];
console.log("Services received:", services.length);
}
catch(err) {
catch (err) {
console.error("Services could not be fetched", err);
throw(err);
throw (err);
}
}

Expand All @@ -144,7 +144,7 @@ class TutorialBase {
try {
resp = await this.__responsesQueue.waitUntilResponse("open");
}
catch(err) {
catch (err) {
console.error(this.__templateName, "could not be started", err);
}
return resp;
Expand All @@ -161,9 +161,9 @@ class TutorialBase {
await this.__responsesQueue.waitUntilResponse("projects?from_template=");
resp = await this.__responsesQueue.waitUntilResponse("open");
}
catch(err) {
catch (err) {
console.error(`"${this.__templateName}" template could not be started:\n`, err);
throw(err);
throw (err);
}
await this.__page.waitFor(waitFor);
await this.takeScreenshot("dashboardOpenFirstTemplate_after");
Expand All @@ -179,9 +179,9 @@ class TutorialBase {
assert(serviceFound, "Expected service, got nothing. TIP: is it available??");
resp = await this.__responsesQueue.waitUntilResponse("open");
}
catch(err) {
catch (err) {
console.error(`"${this.__templateName}" service could not be started:\n`, err);
throw(err);
throw (err);
}
await this.__page.waitFor(waitFor);
await this.takeScreenshot("dashboardOpenFirstService_after");
Expand All @@ -194,46 +194,46 @@ class TutorialBase {
}

const start = new Date().getTime();
while ((new Date().getTime())-start < timeout) {
for (let i = nodeIds.length-1; i>=0; i--) {
while ((new Date().getTime()) - start < timeout) {
for (let i = nodeIds.length - 1; i >= 0; i--) {
const nodeId = nodeIds[i];
if (await utils.isServiceReady(this.__page, studyId, nodeId)) {
nodeIds.splice(i, 1);
}
}
await utils.sleep(2500);
if (nodeIds.length === 0) {
console.log("Services ready in", ((new Date().getTime())-start)/1000);
console.log("Services ready in", ((new Date().getTime()) - start) / 1000);
// after the service is responsive we need to wait a bit until the iframe is rendered
await utils.sleep(3000);
return;
}
}
console.log("Timeout reached waiting for services", ((new Date().getTime())-start)/1000);
console.log("Timeout reached waiting for services", ((new Date().getTime()) - start) / 1000);
return;
}

async waitForStudyRun(studyId, timeout = 60000) {
const start = new Date().getTime();
while ((new Date().getTime())-start < timeout) {
while ((new Date().getTime()) - start < timeout) {
await utils.sleep(5000);
if (await utils.isStudyDone(this.__page, studyId)) {
return;
}
}
console.log("Timeout reached waiting for study run", ((new Date().getTime())-start)/1000);
console.log("Timeout reached waiting for study run", ((new Date().getTime()) - start) / 1000);
return;
}

async waitForStudyUnlocked(studyId, timeout = 10000) {
const start = new Date().getTime();
while ((new Date().getTime())-start < timeout) {
await utils.sleep(timeout/10);
while ((new Date().getTime()) - start < timeout) {
await utils.sleep(timeout / 10);
if (await utils.isStudyUnlocked(this.__page, studyId)) {
return;
}
}
console.log("Timeout reached waiting for study unlock", ((new Date().getTime())-start)/1000);
console.log("Timeout reached waiting for study unlock", ((new Date().getTime()) - start) / 1000);
return;
}

Expand Down Expand Up @@ -270,9 +270,9 @@ class TutorialBase {
try {
await this.__responsesQueue.waitUntilResponse("storage/locations/0/files/metadata?uuid_filter=" + nodeId);
}
catch(err) {
catch (err) {
console.error(err);
throw(err);
throw (err);
}
}

Expand All @@ -294,9 +294,9 @@ class TutorialBase {
try {
await auto.checkDataProducedByNode(this.__page, expecedNFiles);
}
catch(err) {
catch (err) {
console.error("Failed checking Data Produced By Node", err);
throw(err);
throw (err);
}
await this.takeScreenshot("checkResults_after");
}
Expand All @@ -312,9 +312,9 @@ class TutorialBase {
await auto.toDashboard(this.__page);
await this.__responsesQueue.waitUntilResponse(":close");
}
catch(err) {
catch (err) {
console.error("Failed closing study", err);
throw(err);
throw (err);
}
await this.takeScreenshot("closeStudy_after");
}
Expand All @@ -325,9 +325,9 @@ class TutorialBase {
await this.waitForStudyUnlocked(studyId);
await auto.deleteFirstStudy(this.__page, this.__templateName);
}
catch(err) {
catch (err) {
console.error("Failed deleting study", err);
throw(err);
throw (err);
}
await this.takeScreenshot("deleteFirstStudy_after");
}
Expand All @@ -346,9 +346,16 @@ class TutorialBase {
}

async takeScreenshot(screenshotTitle) {
// Generates an URL that points to the backend logs at this time
const snapshotUrl = utils.getGrayLogSnapshotUrl(this.__url, 30);
if (snapshotUrl) {
console.log("Backend Snapshot: ", snapshotUrl)
}

if (this.__demo) {
return;
}

let title = this.__templateName;
if (screenshotTitle) {
title += '_' + screenshotTitle;
Expand Down
Loading