jasmine - Protractor ExcelJS.Click() 返回 ScriptTimeoutError 并且测试失败
问题描述
在我的测试中,量角器测试脚本单击按钮下载文件。
下面是代码片段:
var today = new Date(),
timeStamp = moment(today).format('MMDDYYYY');
let G = GV;
let file = './downloaded-files/StudentList'+timeStamp+'.xlsx';
let Worksheet = 'StudentList'+timeStamp+'.pdf';
let XL = require('exceljs');
let Workbook = new XL.Workbook();
let RowLength= 0;
=======
G.Excel_Button.click().then(function () {
browser.driver.wait(function () {
return fs.existsSync(file);
}).then(function () {
readExcelFile()
});
function readExcelFile() {
try {
expect(fs.existsSync(file)).toBe(true);
Workbook.xlsx.readFile(file).then(function () {
var worksheet = Workbook.getWorksheet(Worksheet);
worksheet.rowCount.then(function(RC){
console.log('\nTotal rows in the workbook is: ' + RC + '\n');
});
expect(worksheet.actualRowCount).toBe(RowLength + 1);
});
} catch (err) {
reject();
}
}
很明显 G.Excel_Button.click() 导致超时错误
ScriptTimeoutError: script timeout: result was not received in 11 seconds
此外,日志显示以下未处理的承诺拒绝:
(node:33984) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'rowCount' of undefined
at C:\Protractor\specs\TestBed.js:132:23
(node:33984) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 1)
(node:33984) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
(node:33984) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
.(node:33984) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'rowCount' of undefined
at C:\Protractor\specs\TestBed.js:132:23
(node:33984) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not
handled with .catch(). (rejection id: 2)
我花了很多时间来解决超时错误,并尝试了所有我能找到的解决方案,包括https://github.com/angular/protractor/blob/master/docs/timeouts.md,但没有成功。
有没有办法解决这个问题?
解决方案
你能试试这段代码,看看它会产生什么吗?
var today = new Date(),
timeStamp = moment(today).format('MMDDYYYY');
let G = GV;
let file = './downloaded-files/StudentList' + timeStamp + '.xlsx';
let Worksheet = 'StudentList' + timeStamp + '.pdf';
let XL = require('exceljs');
let Workbook = new XL.Workbook();
let RowLength = 0;
G.Excel_Button.click().then(function () {
browser.driver.wait(function () {
return fs.existsSync(file);
}, 10 * 1000, `File path '${file}' did not get created within 10 seconds.`).then(function () {
console.log('File Exists');
Workbook.xlsx.readFile(file).then(function () {
console.log('Reading File');
var worksheet = Workbook.getWorksheet(Worksheet);
worksheet.rowCount.then(function (RC) {
console.log('\nTotal rows in the workbook is: ' + RC + '\n');
expect(RC).toBe(RowLength + 1);
});
});
});
})
推荐阅读
- assembly - 在 x86 程序集中用“equ”更改 bss 部分中定义的标签值
- sql-workbench-j - 启动错误:Java 未能成功启动。请确保您已安装 32 位 Java 8
- python - 获取字典中元组中值最高的元素
- r - 如何在数据框中查找跨多列显示唯一结果的行
- gd - 缺少函数 imagettfbbox()
- c++ - 一个简单可靠的 C++ 基准测试解决方案?
- amazon-s3 - AWS localstack s3 存储桶端点无法连接
- teradata - 在 TERADATA 中的特定列名中选择值
- java - 流式音频不会使用音频标签播放
- android - onResume 在显示透明活动时调用后台活动