【问题标题】:How to setup test cases for SAPUI5/OPENUI5 applications?如何为 SAPUI5/OPENUI5 应用程序设置测试用例?
【发布时间】:2015-07-08 16:44:39
【问题描述】:

我尝试对给定的 UI5 应用程序进行原子化测试。因此,我在 WebContent 下创建了一个名为 test-resources 的文件夹。在那个文件夹中,我放置了两个文件用于第一次测试。

第一个文件:experimental.qunit.html,其中包含一些第一个工作单元测试代码。

第二个文件:experimental.opa.html,其中包含文档中的示例代码。

测试部分如下所示:

opaTest("Should find a Button with a matching property", function(Given, When, Then) {
    // Act
    Given.iStartMyAppInAFrame("index.html");

    When.waitFor({
        viewName : "view.master.Master",
        controlType : "sap.m.Button",
        matchers : new sap.ui.test.matchers.PropertyStrictEquals({
            name : "icon",
            value : "sap-icon://show"
        }),
        success : function (aButtons) {
            debugger;
            ok(true, "Found the button: " + aButtons[0]);
        },
        errorMessage : "No button with property icon equal to sap-icon://show"
    });
    Then.waitFor({
        // not implemented
    });
    Then.iTeardownMyAppFrame();
});

首先我假设我也可以搜索带有图标属性的按钮。 第二个假设是,viewName 是视图文件的名称和文件夹?在应用中,视图是拆分应用的主视图。

我这样开始测试: * 在 Eclipse 中标记项目并选择运行为“Web App Preview” * 当然,我看到我的正常应用程序 * 我将 index.html 部分替换为 test-resoruces/experimental.opa.html * 现在我可以看到测试并且我的应用显示在 iframe 中

但是: 1.按钮选择不起作用,有人知道怎么了吗? 2.如果我更改了html代码,我必须一直重新启动“Web App Preview”,重新加载似乎不起作用。更新测试代码后是否有“更好”的方式来运行测试?

应用程序本身被定义为一个组件,主视图是一个SplitApp xml文件,其中包含以下内容:

<mvc:View
    xmlns:mvc="sap.ui.core.mvc"
    displayBlock="true"
    xmlns="sap.m">
    <SplitApp id="idAppControl" />
</mvc:View>

与此同时,我发现了问题并修复了它。我的PropertyStrictEquals 语法错误。

(Web App Preview 的)重启问题依然存在。

我还发现了一个有用的示例: https://openui5beta.hana.ondemand.com/test-resources/sap/m/demokit/cart/test/BuyProductJourney.qunit.html

这里提到: http://scn.sap.com/community/developer-center/front-end/blog/2014/10/16/javascript-based-integration-tests-for-sapui5-apps-with-opa

【问题讨论】:

    标签: unit-testing automated-tests sapui5


    【解决方案1】:

    (查看developper guide 中的测试教程)

    首先,在您的示例中,您混合了抽象级别。直接在您的 jurney(测试步骤的顺序)中不应有任何代码,如 waitFor(),因为这是特定于页面的代码。因此,您应该创建页面,在您的实际安排、行动和断言发生的地方。在陪审员中,您只给他们打电话。像这样(source)

            opaTest("Should see the post page when a user clicks on an entry of the list", function (Given, When, Then) {
            // Arrangements
            Given.iStartMyApp();
    
            //Actions
            When.onTheWorklistPage.iPressOnTheItemWithTheID("PostID_15");
    
            // Assertions
            Then.onThePostPage.theTitleShouldDisplayTheName("Jeans");
        });
    

    这些对象onTheWorklistPageonThePostPage 是您的实际测试步骤,当您搜索对象并触发点击或检查您创建它们的显示文本时:

        Opa5.createPageObjects({
            onTheWorklistPage: {
                baseClass: Common,
                actions: {...},
                assertions: {...}
            }
        })
    

    现在,在这些操作和断言中,您可以使用 waitFor() 获取元素并对其进行处理。这个函数在API中有描述

    PS:您的问题非常不结构化,我不知道是否回答了您的问题,如果没有,请发表评论。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多