Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e: SarValidation test #4193

Merged
merged 10 commits into from
May 5, 2023
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
64 changes: 64 additions & 0 deletions tests/e2e/publications/SarValidation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// node SarValidation.js [url_prefix] [template_uuid] [start_timeout] [--demo]

// master https://osparc-master.speag.com/study/2b7b88be-ea51-11ed-ade4-02420a000d13
// prod https://osparc.io/study/ff72c36a-df81-11ed-9c9e-02420a0b755a

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

const args = process.argv.slice(2);
const {
urlPrefix,
templateUuid,
startTimeout,
basicauthUsername,
basicauthPassword,
enableDemoMode
} = utils.parseCommandLineArgumentsAnonymous(args);

const anonURL = urlPrefix + templateUuid;
const screenshotPrefix = "SarValidation";


async function runTutorial () {
const tutorial = new tutorialBase.TutorialBase(anonURL, screenshotPrefix, null, null, null, basicauthUsername, basicauthPassword, enableDemoMode);

try {
const page = await tutorial.beforeScript();
const studyData = await tutorial.openStudyLink();

const workbenchData = utils.extractWorkbenchData(studyData["data"]);
console.log("Workbench Data:", workbenchData);
const sarIdViewer = workbenchData["nodeIds"][0];
await tutorial.waitForServices(
workbenchData["studyId"],
[sarIdViewer],
startTimeout,
false
);

await tutorial.waitFor(5000, 'Service started');
await utils.takeScreenshot(page, screenshotPrefix + 'service_started');

const sarIframe = await tutorial.getIframe(sarIdViewer);
await tutorial.testSARValidation(sarIframe);
}
catch(err) {
await tutorial.setTutorialFailed(true, false);
console.log('Tutorial error: ' + err);
}
finally {
await tutorial.logOut();
await tutorial.close();
}

if (tutorial.getTutorialFailed()) {
throw "Tutorial Failed";
}
}

runTutorial()
.catch(error => {
console.log('Puppeteer error: ' + error);
process.exit(1);
});
26 changes: 26 additions & 0 deletions tests/e2e/tutorials/tutorialBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,32 @@ class TutorialBase {
return false;
}

async testSARValidation(sarIframe) {
// SAR Validation service testing

this.__responsesQueue.addResponseListener("training-set-generation/generate");
this.__responsesQueue.addResponseListener("training-set-generation/data");
this.__responsesQueue.addResponseListener("training-set-generation/distribution", false);
try {
await this.waitAndClick("createTrainingSetBtn", sarIframe);
await this.__responsesQueue.waitUntilResponse("training-set-generation/generate");
await this.__responsesQueue.waitUntilResponse("training-set-generation/data");
await this.__responsesQueue.waitUntilResponse("training-set-generation/distribution");
}
catch (err) {
console.error(this.__templateName, "training-set can't be generated", err);
}

this.__responsesQueue.addResponseListener("training-set-generation/xport", false);
try {
await this.waitAndClick("exportTrainingSetBtn", sarIframe);
await this.__responsesQueue.waitUntilResponse("training-set-generation/xport");
}
catch (err) {
console.error(this.__templateName, "training-set can't be exported", err);
}
}

async takeScreenshot(screenshotTitle) {
// Generates an URL that points to the backend logs at this time
const snapshotUrl = utils.getGrayLogSnapshotUrl(this.__url, 30);
Expand Down
9 changes: 6 additions & 3 deletions tests/e2e/utils/responsesQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ResponsesQueue {
});
}

__addResponseListener(url) {
__addResponseListener(url, extractJsonResp = true) {
const that = this;
this.__page.on("response", function callback(resp) {
if (resp.url().includes(url)) {
Expand All @@ -48,6 +48,9 @@ class ResponsesQueue {
if (resp.status() === 204) {
that.removeResponseListener(url, "ok", callback);
}
else if (extractJsonResp === false && resp.status() === 200) {
that.removeResponseListener(url, "ok", callback);
}
else {
resp.json().then(data => {
that.removeResponseListener(url, data, callback);
Expand All @@ -57,9 +60,9 @@ class ResponsesQueue {
});
}

addResponseListener(url) {
addResponseListener(url, extractJsonResp = true) {
this.__addRequestListener(url);
this.__addResponseListener(url);
this.__addResponseListener(url, extractJsonResp);
}

removeResponseListener(url, resp, callback) {
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ async function isServiceConnected(page, studyId, nodeId) {
console.log("-- Is Service Connected", nodeId);
const serviceUrl = await getServiceUrl(page, studyId, nodeId);
const connected = await makePingRequest(page, serviceUrl);
console.log(connected ? ("service " + nodeId + " connected") : ("service" + nodeId + " connecting..."), "--")
console.log(connected ? ("service " + nodeId + " connected") : ("service " + nodeId + " connecting..."), "--")
return connected;
}

Expand Down