我正在尝试从我的Journey文件中的JSON模型中获取值。在页面中获取值是没有问题的,因为我可以很容易地获得我的视图。
问题是,我不知道如何将OPA测试中的值返回到Journey文件中。
旅程的一部分:
opaTest("Should Navigate to all Workflows and Navigate Home", function(Given, When, Then) {
// Arrangements starting the app in Frame
Given.iStartMyApp();
//should return the array length of the model
var iLength = When.onTheLayerPage.getNumberOfLayers();
for (var iPosition = 0; iPosition < iLength; iPosition++) {
When.onTheLayerPage.iSelectListItemAtPosition(iPosition);
var iChildLength = When.onTheLayerPage.getNumberOfWorkflows(iPosition);
for (var iChildPosition = 0; iChildPosition < iChildLength; iChildPosition++) {
When.onTheLayerPage.iSelectChildListItemAtPosition(iPosition, iChildPosition);
Then.onTheWorkflowPage.iShouldSeeThePage();
When.onTheAppPage.iPressHomeButton();
Then.onTheLayerPage.iShouldSeeThePage();
}
}页面的一部分:
getNumberOfLayers: function() {
this.waitFor({
id: sPageId,
viewName: sViewName,
actions: function(oPage) {
var iLenght = oPage.getModel("out").getProperty("/r/data/layers").length;
return iLenght;
}
});
},似乎页面上的waitFor是在我已经在for循环中时触发的(可能是基于Promise),所以iLenght是未定义的。
寻找在循环开始之前返回var的方法。
发布于 2017-09-27 18:30:02
我想我已经找到了你的问题的解决方案,但是你如何去实现它具体取决于你如何在你的应用程序中创建模型。
在编写OPA测试时,您可以准备特定的对象或数据,以便稍后在"module“对象的"setup”方法中使用,并在"teardown“方法中销毁它们。因此,在您的旅程文件中,您可以使用类似以下内容来创建一个变量,并将其分配给测试页面对象:
module("Test page model", {
setup: function() {
this.iLength = models.createModel().getProperty("/r/data/layers").length;
},
teardown: function() {
this.iLength = null;
}
});
然后,在实际的opa测试中,您可以访问变量:
opaTest("Should Navigate to all Workflows and Navigate Home", function(Given, When, Then) {
// Arrangements starting the app in Frame
Given.iStartMyApp();
//should return the array length of the model
//var iLength = When.onTheLayerPage.getNumberOfLayers(); <- don't need this line
for (var iPosition = 0; iPosition < this.iLength; iPosition++) { // Access the previously created variable here
When.onTheLayerPage.iSelectListItemAtPosition(iPosition);
var iChildLength = When.onTheLayerPage.getNumberOfWorkflows(iPosition);
for (var iChildPosition = 0; iChildPosition < iChildLength; iChildPosition++) {
When.onTheLayerPage.iSelectChildListItemAtPosition(iPosition, iChildPosition);
Then.onTheWorkflowPage.iShouldSeeThePage();
When.onTheAppPage.iPressHomeButton();
Then.onTheLayerPage.iShouldSeeThePage();
}
}
models.js文件中用于创建模型的代码为:
createModel: function() {
var oTestModel = new sap.ui.model.json.JSONModel({
"r": {
"data": {
"layers": [
{"dummy": 1},
{"dummy": 2},
{"dummy": 3}
]
}
}
});
return oTestModel;
}
如果你没有在一个单独的文件中的方法中创建你的模型,你需要找出一种在"setup“方法中实例化它的方法,但我认为原理是一样的。该方法在每次启动新的opaTest时都会执行,但是可能有一些替代方法,您可以从源代码中挖掘出来,或者在一些只调用一次的文档中找到。我现在没有时间,但是如果你不能的话,叫一声,我以后可以看一看。希望能有所帮助。
https://stackoverflow.com/questions/46442785
复制相似问题