codeceptjs 如何添加custom helper
- create a custom_steps.js
'use strict';
const fs = require('fs');
let Helper = codecept_helper;
class Custom extends Helper {
countRecords(entity) {
var contents = fs.readFileSync(".\\output\\" + entity + ".json", "utf-8");
console.log(contents);
contents = JSON.parse(contents);
var idCount = 0;
for (var i in contents) {
var Id = contents[i]["Product"]["Id"];
console.log("Id" + Id);
idCount += 1;
}
return idCount;
}
}
module.exports = Custom
- 在codeceptjs helpers: 里面添加extends helper
helpers: {
WebDriver: {
smartWait: 5000,
url: 'http://localhost:8180/',
browser: 'chrome',
windowSize: "maximize",
desiredCapabilities: {
chromeOptions: {
"prefs": {
"profile.default_content_settings.popups": "0",
"download.default_directory": "D:\\automation\\authoring\\workdir\\data-authoring-e2e\\output"
}
}
}
},
Custom: {
require: "./step_definitions/custom_steps.js"
},
- 直接在scenarios 里面引用
let idCount = await I.countRecords(entity);
var assert = require('assert');
assert.equal(idCount, count);