javascript - .then 不是函数 - Promise 和 .then 在不同的文件中
问题描述
我正在使用 nightwatch js,并且在从不同的 js 文件中调用 .then 方法时遇到问题。
我有一个 getCount.js 文件。
module.exports.command = function () {
return new Promise((resolve,reject) => {
var localSelector = 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody';
var rowSelector = localSelector + ' > tr';
this.elements('css selector', rowSelector, function (result) {
if (result.status) {
console.log("Inside IF do promise " + result.value.length)
reject(result.status);
} else {
console.log("Inside ELSE do promise " + result.value.length)
resolve(result.value.length);
}
});
});
};
这是我的 home.js,我试图兑现我的承诺。但是低于错误
module.exports = {
url: 'http://localhost:8080/',
elements: {
servicePageTitle :{
selector : 'div.v-card__title > div > span:nth-child(2)'
},
tableBody :{
selector : 'div.flex.mt-4.v-card.v-sheet.theme--light > div > div > table > tbody'
}
},
commands: [{
clickService(selector,serviceName){
return this
.searchTable(selector,serviceName)
},
testPromise(){
this.getCount().then(function(v){
console.log("Total is " + v)
});
}
}]
};
呼叫::
const page = browser.page.home();
page.navigate().testPromise();
现在我的总数未定义..这是输出:
Running: Dashboards:firstTest
Inside ELSE do promise 10
Total is undefined
No assertions ran.
提前致谢!
解决方案
推荐阅读
- spring-boot - gRPC-server(即 Spring Boot 应用程序)将文件上传到 GCS(谷歌云存储)存储桶
- python - UnicodeEncodeError 在终端打印韩文字符
- javascript - 如何添加一个条件来反应 material-ui 元素?
- javascript - 每次打开新模式时,代码中的引导模式都会成倍增加
- handlebars.js - 访问车把中的另一个数组#each 迭代
- javascript - 附加 iframe 时触发 DOMContentLoaded 事件
- php - 使用查询字符串随 PHP 更改 CSS
- php - 在codeigniter的index.php中从数据库中获取数据
- ios - 如何滚动到 ScrollView 中的选定项目?(斯威夫特用户界面)
- swift - SwiftUI + macOS + 基于文档的应用程序问题