我正在使用Protractor和CucumberJS实现E2E测试。我面临的问题是,它只执行第一步,一直等到超时。只有在使用页面对象时才会出现此问题。
这是我的功能文件:
场景:验证添加事件权重给定添加优先级程序并添加事件权重类型用户创建事件然后应正确显示事故重量。
页面对象文件:
var createincidentpage = function(){
this.priorityAdd = function(userdetail, callback) {
browser.ignoreSyncronization = true;
incidentSection.click()
.then(function(){
return PPPage.click();
}).then(function(){
browser.switchtTo().frame(0);
return newElement.click();
}).then(fucntion(){
return newppname.sendkeys("xyz");
}).then(function(){
return fromDatePicker.click();
}).then(function(){
return gotoTodayElement.click();
}).then(function(){
return editableOk.Click();
}).then(function(){
return toDatePicker.click();
}).then(function(){
return selDateinMOnth.click();
}).then(function(){
SubmitButton.click();
return callback();
});
};
module.exports = new createincidentpage();
我的步骤文件:
var createincidentpage = require ('../pages/createincidentpage.js');
Given('priority program add' , function (callback) {
createincidentpage.priorityAdd(function callback(){
callback();
}):
});
因为您没有在priorityAdd()
内部调用callback()
。
为了更清楚,我在下面的代码中重命名了一些变量。
您必须调用来自Given()
的callback()
,否则运行时无法结束Given()
并等待超时。
直接在Given()
中调用callback()
,或者像在嵌套函数中那样将callback
向下传递到嵌套函数中并调用它。
var createincidentpage = function(){
this.priorityAdd = function(userdetail) {
browser.ignoreSyncronization = true;
incidentSection.click()
PPPage.click();
browser.switchtTo().frame(0);
newElement.click();
newppname.sendkeys("xyz");
fromDatePicker.click();
gotoTodayElement.click();
editableOk.Click();
toDatePicker.click();
selDateinMOnth.click();
return SubmitButton.click();
};
module.exports = new createincidentpage();
步骤文件:
var createincidentpage = require ('../pages/createincidentpage.js');
//Option 1, invoke `callback`
Given('priority program add', function(callback) {
createincidentpage.priorityAdd().then(function(){
return callback();
});
});
// Option 2, return a promise like object, recommend to use option 2
Given('adding incident weight type', function(){
return createincidentpage.priorityAdd();
});