1. 程式人生 > 其它 >SAPUI5 Walkthrough Step 29: Integration Test with OPA

SAPUI5 Walkthrough Step 29: Integration Test with OPA

Step 29: Integration Test with OPA

整合測試

測試Step 16中,開啟Hello對話方塊功能。

新建檔案webapp/test/integration/NavigationJourney.js

/*global QUnit, opaTest*/
sap.ui.define([
    "sap/ui/demo/walkthrough/localService/mockserver",
    "sap/ui/test/opaQunit",
    "./pages/App"
], function (mockserver) {
    "use strict";
    QUnit.module(
"Navigation"); opaTest("Should open the Hello dialog", function (Given, When, Then) { // initialize the mock server mockserver.init(); // Arrangements Given.iStartMyUIComponent({ componentConfig: { name: "sap.ui.demo.walkthrough" } });
//Actions When.onTheAppPage.iPressTheSayHelloWithDialogButton(); // Assertions Then.onTheAppPage.iShouldSeeTheHelloDialog(); // Cleanup Then.iTeardownMyApp(); }); });

新建檔案webapp/test/integration/pages/App.js

sap.ui.define([
    "sap/ui/test/Opa5",
    "sap/ui/test/actions/Press"
], 
function(Opa5, Press) { "use strict"; var sViewName = "sap.ui.demo.walkthrough.view.HelloPanel"; Opa5.createPageObjects({ onTheAppPage: { actions: { iPressTheSayHelloWithDialogButton: function() { return this.waitFor({ id: "helloDialogButton", viewName: sViewName, actions: new Press(), errorMessage: "Did not find the 'Say Hello With Dialog' button on the HelloPanel view" }); } }, assertions: { iShouldSeeTheHelloDialog: function() { return this.waitFor({ controlType: "sap.m.Dialog", success: function() { // we set the view busy, so we need to query the parent of the app Opa5.assert.ok(true, "The dialog is open"); }, errorMessage: "Did not find the dialog control" }); } } } }); });


新建檔案webapp/test/integration/opaTests.qunit.html

<!DOCTYPE html>
<html>
<head>
    <title>Integration tests for SAPUI5 Walkthrough</title>
    <meta charset="utf-8">
    <script
        id="sap-ui-bootstrap"
        src="https://sapui5.hana.ondemand.com/1.92.1/resources/sap-ui-core.js"
        data-sap-ui-theme="sap_belize"
        data-sap-ui-resourceroots='{
            "sap.ui.demo.walkthrough": "../../"
        }'
        data-sap-ui-animation="false"
        data-sap-ui-compatVersion="edge"
        data-sap-ui-async="true">
    </script>
    <link rel="stylesheet" type="text/css" href="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/qunit-2.css">
    <script src="https://openui5.hana.ondemand.com/resources/sap/ui/thirdparty/qunit-2.js"></script>
    <script src="https://openui5.hana.ondemand.com/resources/sap/ui/qunit/qunit-junit.js"></script>
    <script src="opaTests.qunit.js"></script>
</head>
<body>
    <div id="qunit"></div>
    <div id="qunit-fixture"></div>
</body>
</html>


新建檔案webapp/test/integration/opaTests.qunit.js

/* global QUnit */
QUnit.config.autostart = false;

sap.ui.getCore().attachInit(function () {
    "use strict";
    sap.ui.require([
        "sap/ui/demo/walkthrough/test/integration/NavigationJourney"
    ], function () {
        QUnit.start();
    });
});

執行結果