有没有一种方法可以编写我自己的自定义断言来检查文件是否存在? 我已经按照文档所述尝试了所有实现,但似乎不起作用!
这是我的代码:
const fs = require('fs');
exports.assertion = function (path) {
this.message = 'Testing if file exists';
this.expected = true;
this.pass = (value) => {
return value === this.expected;
};
this.value = (result) => {
return result;
};
this.command = (callback) => {
return this.api.execute(function (filePath) {
try {
fs.existsSync(filePath);
return true;
} catch (err) {
return false;
}
}, [path],
function (result) {
callback(result.value);
});
};
};
browser
.click('#export-postgres-btn')
.assert.checkFileExists(`~/Downloads/${diagramName}.sql`);
即使文件确实存在,结果也始终为假!