Nightwatch:存在自定义声明检查文件

时间:2019-09-18 03:23:19

标签: javascript testing nightwatch.js

有没有一种方法可以编写我自己的自定义断言来检查文件是否存在? 我已经按照文档所述尝试了所有实现,但似乎不起作用!

这是我的代码:

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`);

即使文件确实存在,结果也始终为假!

0 个答案:

没有答案