我在项目中使用BDD(Behat)进行功能测试。 现在,在测试具有太多后台作业的功能时,我遇到了问题。例如:
let custom_fields = {
"21": {
"edit": true,
"required": true,
"show": true
},
"22": {
"edit": true,
"required": true,
"show": true
},
"data": [{
"display_name": "Text",
"id": 21,
"name": "Text",
"value": ["TextHere"]
}, {
"display_name": "Text",
"id": 22,
"name": "Text",
"value": ["TextHere"]
}]
};
custom_fields.data.forEach(function(item) {
let obj = custom_fields[item.id];
for (let attr in item)
obj[attr] = item[attr];
});
//Remove the data property
delete custom_fields.data;
console.log(custom_fields);
“ 然后我必须等到它完成 ”包含:
“ 我可以看到文章列表已导入 ”我是否将API调用到服务器以获取该问题的文章列表。
正如您所看到的,因为在导入期间,我们有太多后台作业(使用Resque),所以我必须等到完成后才检查问题状态:
Scenario: Import issue at the first time
Given I have a issue package "1602.zip"
When I upload issue "1602.zip"
Then I have to wait until it is finished
And I can see list of articles are imported
And status of issue is "1"
问题是我不知道我要等多久,因为它取决于问题包的大小,更大的等待时间越长。所以在这种情况下,我该怎么办?
答案 0 :(得分:1)
作为一般做法,您需要使用条件等待来检查您知道的事情(等待几秒钟)。
条件可能是:
- 请求的状态
- 元素显示在页面中
- 不显示页面/元素
提示:您应该避免仅使用
while
循环并使用do-while
循环而不是您需要的2个条件,在您的情况下检查状态,以及如果第一个永远不会像计数一样实现。