cancel
Showing results for 
Search instead for 
Did you mean: 

OPA - Mockserver

Former Member
0 Kudos

Hi guys,

right now I am starting to write OPA tests. This is working quite good.

But now I would like to mock the responses from the server.

In a normal qunit test, I use sap.ui.core.util.MockServer without trouble.

But if I try to integrate it into a OPA test, it fails. I guess because the requests from the

iframe are routed a different way than the requests fired inside the normal page.

Anybody luck doing it? Or could give me a hint how to mock in a OPA test?

Best regards

Benjamin

0 Kudos

Hi,

I have OPA5 Tests and trying to run OPA5 Tests with Azure DevOps Pipeline.

Using grunt tasks for Qunit and OPA5 Tests.

grunt.loadNpmTasks("@sap/grunt-sapui5-bestpractice-test"); grunt.registerTask("unit_and_integration_tests", ["test"]);

Sinon.Js is used for mocking

getting the below error.

03 05 2020 15:32:10.479:WARN [web-server]: 404: /mockserver.html Chrome Headless 62.0.3198.0 (Linux x86_64) ERROR Uncaught TypeError: Cannot read property 'push' of undefined at /__w/1/s//node_modules/karma-qunit/lib/adapter.js:94

I cannot comment line in /karma-qunit/lib/adapter.js as the library is downloaded at installed at build time.

Thanks,

Rajesh

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Benjamin,

Is your app using scaffolding? If so, start the app in the opa test with the url parameter:

this.iStartMyAppInAFrame("./index.html?responderOn=true");

It will start the app in mock mode.



former_member190457
Contributor
0 Kudos

Hi Gal,

I'm replying to your question as I'm in the same situation. Personally, I'm just using plain javascript/OPA/UI5 in WebIDE (but also on premise NWDS would be the same).

Do you have any idea how to achieve the same behavior without scaffolding?

Thanks, regards

Vincenzo

Former Member
0 Kudos

Hi Vincenzo,

Running OPA test in mock mode requires starting the tested app in mock mode. When no scaffolding is involved you should currently code it manually. You have to call the mockserver code from the application and not using the Web IDE mock feature.

former_member190457
Contributor
0 Kudos

Hi Gal, thanks for your help.

I am thinking of a different option.

Could I start the opaText.html file with Run > Run with mock data?

that way the WebIDE would step in providing the mock server.

Then, OPA would take care of testing data.

Do you think that's supported?

Thanks, Vincenzo

Former Member
0 Kudos

I found out that you can "inject" code using

sap.ui.test.Opa5.getWindow().jQuery.sap.globalEval

Now the mock server is working, but the next problem arises.

If you directly request data at startup, you can not inject the code fast enough, that the mock server will be used...

former_member182372
Active Contributor
0 Kudos

well, 'delay" the code 😉

jQuery.sap.delayedCall(1000, this, function() { //1 second delay

});

Former Member
0 Kudos

Thanks for your answer.

But I think this will not help.

So what is happening:

1. The app, that needs to be tested, is started:

return this.iStartMyAppInAFrame("./index.html");

2. Now the app will be started. One view has a afterRendering method, which calls the server.

3. Date will be shown...

Now the OPA test should not work with the real server. So we need a mock server...

The mock server can be injected as said in my previous post.

But before I start the app, as in point 1, I can not inject, because the SAP framework in the iframe is not initiated (I am too early).

The promise used to start the app in the iFrame will be resolved after point 2 (I am too late).

So I have no clue how to do that properly. I could of course try to delay it, that I come right into the spot between 1&2, but this depends on the load and so on.

So I do not think that a fixed delay would work.

Maybe I could try do defer the code until the "sap.ui.test.Opa5.getWindow().jQuery.sap"-object is resolved...

former_member190457
Contributor
0 Kudos

Hi all,

I'm attempting to do exact the same thing as Benjamin and the mock server does not intercept the HTTP calls also in my case.

I'm using WebIDE and don't really have a clue about how to start the mock server the proper way, without coupling the application with test-oriented code.

Anyone managed to get this working?

Thanks, regards

Vincenzo

Former Member
0 Kudos

I am "happy" that someone else has the same problem. I already thought that I want to do something strange.

So just to clarify do you have a timing issue as well?

Or do you trigger the sever call with a button? If you use a button, you can inject the mock server..

Otherwise I think you are screwed.

I solved it that I have unit test, that run in total isolation. And the hole site tests (OPA) I run in an enviroment where SOAP GUI is mocking the sever. That is clearly not perfect, but I found no other way.