Cypress集成ReportPortal和gmail-tester报rp_Log任务未注册如何解决
问题原因
你在plugins/index.js文件中对module.exports进行了两次赋值,第二次导出的插件配置直接覆盖了此前注册ReportPortal插件的逻辑,导致ReportPortal相关的rp_Log、rp_screenshot等内置任务都没有被正确注册,只有你新增的gmail:get-messages任务被识别,所以运行时报错。
修复方案
将ReportPortal的注册逻辑合并到同一个导出的插件函数中即可,修改后的plugins/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. // *********************************************************** // 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, config) => { // 注册ReportPortal插件 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; } }); };
修改完成后重新运行测试,ReportPortal相关任务和gmail获取邮件的任务就可以同时正常工作了。
内容的提问来源于stack exchange,提问作者vaanumalar
相关产品推荐
相关产品推荐

