我正在使用组件启动器创建OpaTests,我希望按照绑定到组件的i18n模型的文本来匹配按钮。
我的观点如下:
<Button press="handleRemove" text="{i18n>xbut.remove}" width="80px" />
我的测试看起来像:
iPressRemove: function () {
return this.waitFor({
controlType: "sap.m.Button",
viewName: sViewName,
matchers: new PropertyStrictEquals({
name: "text",
value: "<WHAT GOES HERE>"
}),
actions: new Press(),
errorMessage: "Remove Button not found"
});
}
如何确定i18n型号中文本的值?
答案 0 :(得分:1)
加载资源模型如下:
var sapResourceBundle; var oResourceBundle;
QUnit.module("Module name", {
beforeEach: function () {
this.sapResourceBundle = sap.ui.getCore().getLibraryResourceBundle("sap.m");
this.oResourceBundle = new ResourceModel({
bundleUrl: jQuery.sap.getModulePath("your_module", "/i18n/i18n.properties")
}).getResourceBundle();
}
});
然后使用oResourceBundle.getText(&#34; translation_key&#34;) 就像你在控制器中那样
答案 1 :(得分:0)
我想我在测试教程中找到了答案,你可以从Page
获得i18n模型theTitleShouldDisplayTheTotalAmountOfItems: function () {
return this.waitFor({
id: "tableHeader",
viewName: sViewName,
matchers: function (oPage) {
var sExpectedText = oPage.getModel("i18n").getResourceBundle().getText("worklistTableTitleCount", [23]);
return new PropertyStrictEquals({
name: "text",
value: sExpectedText
}).isMatching(oPage);
},
success: function () {
Opa5.assert.ok(true, "The table header has 23 items");
},
errorMessage: "The Table's header does not container the number of items: 23"
});
}
我的解决方案是在加载页面时存储资源包
var oI18nResourceBundle;
thePageShouldBeVisible: function () {
return this.waitFor({
id: "myPage",
viewName: sViewName,
success: function (oPage) {
oI18nResourceBundle = oPage.getModel("i18n").getResourceBundle();
Opa5.assert.ok(true, "Page rendered");
},
errorMessage: "Page not rendered."
});
}
答案 2 :(得分:0)
您可以从视图中获取它:
this.getView().getModel("i18n").getResourceBundle().getText("CHECK_WEBUI");