我编写了使用量角器登录应用程序的功能。
this.login = function(userName, password){
return this.emailAddressInput.sendKeys(userName).then(function(){
return this.nextButton.click().then(function(){
return this.passwordInput.sendKeys(password).then(function(){
this.tibcoLoginButton.click().then(function(){
return require('./tce.apps.js')
})
})
})
我正在我的一个规范文件中调用该函数。
但是我遇到的错误是:
失败:无法读取未定义的属性“点击”。
如果下一个按钮是这个。为什么会这样?
答案 0 :(得分:1)
尝试一下
this.login = function(userName, password){
var self = this;
return self.emailAddressInput.sendKeys(userName).then(function(){
return self.nextButton.click().then(function(){
return self.passwordInput.sendKeys(password).then(function(){
return self.tibcoLoginButton.click().then(function(){
return require('./tce.apps.js')
})
})
})
})
}
并且不必使用嵌套的then()
,但请执行以下操作以提高可读性。
this.login = function(userName, password) {
var self = this;
self.emailAddressInput.sendKeys(userName);
self.nextButton.click();
self.passwordInput.sendKeys(password);
return self.tibcoLoginButton.click().then(function() {
return require('./tce.apps.js')
});
}
答案 1 :(得分:0)
this.nextButton
是不确定的,因为'this'在.then
方法中用词表示是指Promise对象。
答案 2 :(得分:0)
您不需要使用 then 函数来编写登录功能。您可以尝试按照以下步骤创建LoginPage对象页面:
var EC = protractor.ExpectedConditions;
this.getUserInput = function () {
return user_input;
};
this.getPasswordInput = function () {
return password_input;
};
this.setUserInput = function (text) {
user_input.clear().sendKeys(text);
};
this.setPasswordInput = function (text) {
password_input.clear().sendKeys(text);
};
this.getLoginButton = function () {
return login_button;
};
this.clickLogin = function () {
login_button.click();
};
this.login = function(username, password) {
browser.wait(EC.presenceOf(this.getUserInput()));
browser.wait(EC.presenceOf(this.getPasswordInput()));
this.getUserInput().click();
this.setUserInput(username);
this.getPasswordInput().click();
this.setPasswordInput(password);
browser.wait(EC.elementToBeClickable(this.getLoginButton()));
this.clickLogin();
};