Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 3184

One Page Acceptance Tests - View Type Problem

$
0
0

Hi everybody,

 

I'm facing a little problem while using the built-in OPA5 feature.

 

All documentations I've found are based on XML Views but I'm using the JS Views of UI5.

This leads - at least in my case to a serious problem: The defined tests simply won't work.

 

I've created a simple application like in this document:

http://help.sap.com/saphelp_scm700_ehp03/helpdata/en/22/f175e7084247bc896c15280af9d1dc/content.htm

 

The only differences are: the view is called mainView and the application name differs.

 

The opa code looks like this:

jQuery.sap.require("sap.ui.thirdparty.qunit");  jQuery.sap.require("sap.ui.test.Opa5");  jQuery.sap.require("sap.ui.test.opaQunit");  jQuery.sap.require("sap.ui.qunit.qunit-css");  jQuery.sap.require("sap.ui.qunit.qunit-junit");  jQuery.sap.require("sap.ui.qunit.qunit-coverage");  var Opa = sap.ui.test.Opa;  var Opa5 = sap.ui.test.Opa5;  opaTest("Should press a Button", function(Given, When, Then) {    // Arrangements    Given.iStartMyAppInAFrame("../index.html");    //Action    When.waitFor({      viewName : "opa_test.mainView",      id : "pressMeButton",      success : function(oButton) {        oButton.$().trigger("tap");      },      errorMessage : "Button not found -_-"    });    // Assertion    Then.waitFor({      viewName : "opa_test.mainView",      id : "pressMeButton",      matchers : new sap.ui.test.matchers.PropertyStrictEquals({        name : "text",        value : "pressed!"      }),      success : function(oButton) {        ok(true, "The button's text changed to: " + oButton.getText());      },      errorMessage : "did not change the Button's text"    });  });

If I'm running the test with the xml view the result is as expected: everything works.

 

If I'm running the test with the JavaScript view, the result is an error at the "action" part I'm receiving the message: "Button not found -_-"

 

After trying several things I've begun to analyze the generated code and I've found a quite big difference:

 

In the XML-View the Button which is created appears in the DOM in the following way:

 

<button id="idmainView1--pressMeButton" data-sap-ui="idmainView1--pressMeButton" ... </button>

In the Javascript View the generated Button looks like this:

<button id="pressMeButton" data-sap-ui="pressMeButton" ... </button>

So for whatever reason the UI5 framework seems to generate the element ids in different ways, since in the view code it looks this:

 

JavaScript:

return new sap.m.Page({      title : "Title",      content : [ new sap.m.Button({        id : "pressMeButton", // sap.ui.core.ID        text : "Press me", // string        press : [ function(oEvent) {          oController.onButtonPress();        }, this ]      }) ]    });

XML:

<App>    <Page>      <content>        <Button id="pressMeButton" text="Press me" press="onPress"/>      </content>    </Page>  </App>

 

As a workaround (at least to get the example to work) I've tried changing the JavaScript coding to this:

new sap.m.Button({        id : "idmainView1--pressMeButton", // sap.ui.core.ID        text : "Press me", // string

and now the OPA5 test is running like it should.

 

So the questions in short are:

* Why is the id generation different for the XML and the JavaScrit view?

* Is there any way, to use the OPA5 framework with JavaScript views without using the mentioned workaround?


Viewing all articles
Browse latest Browse all 3184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>