本文介绍了如何为SAPUI5/OPENUI5应用程序设置测试用例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to atomize my tests for a given UI5 application. Therefore I created a folder under WebContent called test-resources. In that folder I placed two files for first tests.

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

First file: experimental.qunit.html that contains some first working unit test code.

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

Second file: experimental.opa.html which contains an example code from the documentation.

测试部分如下:

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();
});

首先,我假设我也可以使用icon属性来搜索按钮.第二个假设是,viewName是视图文件的名称和文件夹吗?在应用程序中,该视图是拆分应用程序的主视图.

First of all I assume that I can search a button also with icon property.Second assumption is, that viewName is the name and folder of the view file? In the app, the view is the master view of a split app.

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

I start the test like this:* In Eclipse mark the project and choose run as "Web App Preview"* Than of course I see my normal app* I replace the index.html part with test-resoruces/experimental.opa.html* Now I can see the test and my app is shown in an iframe

但是:1.按钮选择不起作用,有人知道这是怎么回事吗?2.如果更改html代码,必须一直重新启动"Web App Preview",则重新加载似乎无法正常进行.更新测试代码后,是否有更好"的方式运行测试?

But:1. The button selection is not working, anyone an idea what's wrong?2. If I change the html code I have to restart the "Web App Preview" all the time, a reload seems not working. Is there a "better" way to run the tests after updating test code?

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

The app itself is defined as a component, and the main view is a SplitApp xml file that contains nothing than:

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

与此同时,我发现了问题并解决了.我的PropertyStrictEquals语法错误.

Meanwhile I detect the problem and fixed it. My syntax of PropertyStrictEquals was wrong.

(Web App Preview的)重新启动问题仍然存在.

The restart problem (of Web App Preview) still exists.

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

I also detected a helpful example: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

推荐答案

(请查看开发人员指南)

首先,在您的示例中,您正在混合抽象级别.直接在您的 jurney (测试步骤的顺序)中,不应有任何类似waitFor()的代码,因为那是特定于页面的代码.因此,您应该创建页面,在这些页面上进行实际的安排,操作和声明.在陪审团中,您只能给他们打电话.像这样():

First of all, in your example you are mixing the levels of abstraction. Directly in your jurney (the order of steps for your tests) there should not be any code like waitFor(), because that is page specific code. So you should create pages, on where your actual arrangements, actions and assertions take place. In the jurney you only call them. like this (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是您的实际测试步骤,当您搜索对象并触发单击或检查显示的文本时,就可以像这样进行测试:

Those objects onTheWorklistPage and onThePostPage are your actual test steps, wher you search for objects and trigger a click or check the displayed text you create them like that:

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

现在在这些动作和断言中,您将waitFor()放入以获取元素并对其进行处理. API

Now in those actions and assertions you put your waitFor() to get elements and do something with them. This function is described in the API

PS:您的问题非常无章理,如果回答了我的问题,我也不敢回答,否则请发表评论.

PS: Your question is very unstructured and I am not shure if I answered your question, if not, please comment.

这篇关于如何为SAPUI5/OPENUI5应用程序设置测试用例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 03:58