我正在使用internjs处理Web应用程序的UI自动化,我正在尝试将功能测试的测试报告直接转储到excel文件中。我想做的是:
为了做到这一点,我需要安装第三方库archiver。
现在我陷入了一个非常基本的问题,即我无法将库导入我的自定义记者。那么有些人可以帮我介绍如何导入外部库实习项目。
我使用以下命令安装了archiver:
npm install archiver --save
我的代码如下:
define([
'intern/dojo/node!fs',
'../TestUtils/ExcelUtil',
'../TestUtils/SnapShotUtil',
'archiver' //<= import archiver
], function (fs, ExcelUtil, SnapShotUtil, archiver) {
var Excel = ExcelUtil.instance();
var screenshotDir = 'test-reports/screenshot/';
function TestReporter(config) {
config = config || {};
}
TestReporter.prototype = {
suiteError: function (suite) {
SnapShotUtil.takeSnapShot(suite, suite.name + '-' + suite.error.name)
},
testPass: function (test) {
Excel.addRow([test.parent.name, test.name, 'N/A', 'Pass', 'N/A'])
},
testSkip: function (test) {
var picName = screenshotDir + test.parent.name.replace(/ /g, '') + '-' +
test.name.replace(/ /g, '') + '.png'
Excel.addRow([test.parent.name, test.name, 'N/A', 'Skipped', '=HYPERLINK(' + picName + ',ScreenShot)'])
SnapShotUtil.takeSnapShot(test, picName)
},
testFail: function (test) {
var picName = screenshotDir + test.parent.name.replace(/ /g, '') + '-' +
test.name.replace(/ /g, '') + '-' + test.error.name + '.png'
Excel.addRow([test.parent.name, test.name, test.error.name, 'Failed', '=HYPERLINK(' + picName + ',ScreenShot)'])
SnapShotUtil.takeSnapShot(test, picName)
}
};
return TestReporter;
});
但是我收到了以下错误:
Error: Failed to load module archiver from
D:/Users/sshrestha/Documents/APps/newAuto/advtestautomation/archiver.js
(parent: Automation/ConfigFiles/TestReporter.js)
at ReadFileContext.callback <node_modules\intern\node_modules\dojo\loader.ts:831:119>
at FSReqWrap.readFileAfterOpen [as oncomplete] <fs.js:303:13>
我的文件夹结构如下
有人可以帮忙。
答案 0 :(得分:0)
archiver作为CommonJS模块发布,因此您需要使用dojo / node插件导入它(就像您使用'fs'一样):
intern/dojo/node!archiver