插件文件中未处理任务"rp_Log"。已注册以下任务:gmail:get-messages



我正在为我的网站写柏树测试。我已经在我的测试中包含了reportportaljs客户端,我的测试运行没有任何问题。现在我添加了gmail-tester来验证电子邮件。当我运行它时,我得到了错误cy.task('rp_Log')失败,出现以下错误:插件文件中没有处理任务'rp_Log'。以下任务已注册:gmail:get-messages

我的plugin/index.js文件是这样的

/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)
/**
* @type {Cypress.PluginConfig}
*/
// eslint-disable-next-line no-unused-vars
const registerReportPortalPlugin = require('@reportportal/agent-js-cypress/lib/plugin');
const debug = require('debug');
const path = require('path');
const gmail_tester = require('gmail-tester');

module.exports = (on) => registerReportPortalPlugin(on);
module.exports = (on, config) => {
on("before:browser:launch", (browser = {}, launchOptions) => {
if (browser.name === "chrome"&& browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions;
}
});
on("task", {
"gmail:get-messages": async args => {
const messages = await gmail_tester.get_messages(
path.resolve(__dirname, "credentials.json"),
path.resolve(__dirname, "token.json"),
args.options
);
return messages;
}
});
};

我的测试文件看起来像这样

describe('Launch website',() => {
it('Home visit',() => {
cy.visit('http://localhost:3000')
cy.log("Visited the page")
cy.screenshot("Launch_name.png")
cy.rp_screenshot("Launch.png")
})
})

当我运行测试时,我可以看到我的页面正在启动,它也正在打印日志。但是在那之后,它告诉cy.task('rp_log')没有定义,相反,它可以看到gmail收到消息。谁能帮我去掉这个错误?

解决了一个问题。我们不能使用两个模块。导出为index.js文件。答案应该是这样的


module.exports = (on, config) => {
registerReportPortalPlugin(on);
on("before:browser:launch", (browser = {}, launchOptions) => {
if (browser.name === "chrome"&& browser.isHeadless) {
launchOptions.args.push('--disable-gpu');
return launchOptions;
}
});
on("task", {
"gmail:get-messages": async args => {
const messages = await gmail_tester.get_messages(
path.resolve(__dirname, "credentials.json"),
path.resolve(__dirname, "token.json"),
args.options
);
return messages;
}
});
};

相关内容

  • 没有找到相关文章

最新更新