cancel
Showing results for 
Search instead for 
Did you mean: 

OPA testing: View to be tested is embedded in App.view.xml

former_member190457
Contributor
0 Kudos

Hi all,

I'm trying to test the behavior of my UI5 application.

The structure is pretty common:


> component.js

> view (folder)

     > App.view.xml

     > Data.view.xml

     > Data.controller.js

> test (folder)

     > myOPATest.html

The Data view is embedded in the App view.

I'd like to test the behavior of a control in Data.

Should I look it up like:


When.waitFor({

            viewNamespace : "view",

            viewName : "Data",

            controlType : "sap.m.List",

            id: "list",

      //other stuff here

          });

or somehow differently?

The console only says: found no control with the id list

I don't really know if the view is resolved or if the app is started at all

Any suggestion would be highly welcome

Thanks, regards

Vincenzo

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

It would really help if you could also post your Data.view.xml and myOPATest.html, otherwise I and possibly others can only make assumptions:

Assumptions:

  • You should be calling viewNamespace as "view." with the period.
  • You can omit the viewNamespace in the waitFor by setting it correctly in your qunit.html. See the first link I posted below, the extendConfig function will take care of it.
  • What is the scope of the sap.m.List control in your view, is it within other controls?, as with my own OPA5 tests, I have noticed that sometimes when the targeted control is deeper in hierarchy can cause the waitFor with id not to work correctly. In a case like this, it may be best to fetch the top control by id and dig your way through using getters to get to your target control.

Some really useful links:

former_member190457
Contributor
0 Kudos

Thanks Armin for your insight, I'll try to elaborate a bit more with a simpler test case, with no nested UI control.

I'm working in web IDE, trying to test a UI5 Helium application I've developed there.

The root view is: [project root]/view/App.xml

The test html page with OPA unit tests is located at [project root]/test/opa1.html

The App.view.xml is as follows:


<mvc:View xmlns:core="sap.ui.core" xmlns:mvc="sap.ui.core.mvc"

  xmlns="sap.m" xmlns:l="sap.ui.layout" xmlns:t="sap.ui.table" xmlns:ux="sap.ui.ux3"

  xmlns:html="http://www.w3.org/1999/xhtml">

  <App id="idAppControl">

  <pages>

  <mvc:XMLView viewName="sap.sls.inbox.view.TaskList" id="idViewMaster" />

  </pages>

   </App>

</mvc:View>

The test code is trying to grab the App (id="idAppControl") and check that at least one page is there


// Act

          Given.iStartMyAppInAFrame("../index.html");

          When.waitFor({

            viewNamespace: "view.",

            viewName : "App",

            id: "idAppControl",

            matchers : new sap.ui.test.matchers.AggregationFilled({name : "pages"}),

            success : function (aButtons) {

              ok(true, "View found");

            },

            errorMessage : "The list did not contain any item"

          });

Also, the whole application of course involves a Component.js, where App.view.xml is specified as root view.

Still, also in this case, the framework seems unable to get hold of the App control, even though it's not nested.

when the test page is run, the application under test is showed successfully, so I guess there's some problem with control resolution

Please note that I managed to get the OPA framework to work with WebIDE, for the sample case taken from the UI5 Explored page.

In that case, the root view is created through the createContent method in Component.js, not the rootView property.

Can this make the difference?

Any insight would be greatly appreciated

Thanks, regards

Vincenzo

Former Member
0 Kudos

Hello Vincenzo,


If you are trying to access the view TaskList, why not set that as your viewName? Are you using any routing in your Component.js, as a routing pattern might be directing your app to a different view.

It is worth noting that with routing in your Component.js, you can have the App.view.xml to just initialize the application and the routing will handle any redirects from the routing pattern including the initial state (index.html) as pattern: "" if you already don't have that.


<mvc:View xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m" displayBlock="true">

<App id="idAppControl"/>

</mvc:View>

Best Application Practices - Navigation and Routing

Regards,

Armin

former_member190457
Contributor
0 Kudos

Thanks a lot Armin, this is solved now.

The problem was that the root view was defined both in the rootView parameter but also returned by the createContent method in Component.js, result of previous attempts.

Message was edited by: Michael Appleby

Answers (0)