添加到 cypress/plugins/index.js 文件上的 module.exports Cypress

2024-02-28

我正在努力添加第二个 module.export cypress/plugin/index.js

我当前的 cypress/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 { on } = require('events');
const fs = require('fs-extra');
const path = require('path');

function getConfigurationByFile(file) {
  const pathToConfigFile = path.resolve('config', `${file}.json`);

  return fs.readJson(pathToConfigFile);
}

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  const file = config.env.configFile || 'qa';

  return getConfigurationByFile(file);
};

我想将以下内容添加到 cypress/plugin/index.js:

require('cypress-grep/src/plugin')(config)
// make sure to return the config object
// as it might have been modified by the plugin
return config

我相信您可以将配置从您的函数传递到您的require然后返回新的配置。

module.exports = (on, config) => {
  // `on` is used to hook into various events Cypress emits
  // `config` is the resolved Cypress config
  const file = config.env.configFile || 'qa';
  let newConfig = getConfigurationByFile(file);
  
  require('cypress-grep/src/plugin')(newConfig);
  
  return newConfig;
};

自从你的getConfigurationByFile()函数返回一个像原始对象一样的 JSON 对象config,以及cypress-grep插件接受一个 JSON 对象,您可能只需添加解析后的 JSONgetConfigurationByFile而不是提供的标准config.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

添加到 cypress/plugins/index.js 文件上的 module.exports Cypress 的相关文章

  • Cypress 默认请求等待?

    我需要 Cypress 在执行任何操作之前默认等待任何 xhr 请求完成 有没有办法将其设为默认值或任何其他替代方案 因为我正在测试的应用程序速度很慢并且会进行大量 api 调用 编辑 为每个 api 请求编写一条语句会变得混乱且不必要的工
  • 为什么 data-* 属性比普通 ID 属性更适合用于元素选择?

    Cypress https docs cypress io guides references best practices html Selecting Elements和许多其他关于测试 Web 应用程序的帖子建议依赖像这样的数据属性d
  • 如何在 cypress.io 测试中可靠地等待页面空闲

    当使用 cypress io 测试 Angular 网页时 检测页面何时完全加载和空闲的最佳 最可靠方法是什么 不仅仅是 onload 事件 需要包括所有 XHR 请求 完成角度摘要循环以及完成所有渲染 包括完成所有动画 原因是 此时我想测
  • 如何使用 Cypress 检查可能不存在的元素

    我正在编写 Cypress 测试来登录网站 有username and password字段和一个Submit按钮 大多数登录都很简单 但有时首先会出现一个警告对话框 必须将其关闭 我试过这个 cy get login username t
  • Azure DevOps 中“bash exited with code 1”中的 Cypress 测试退出失败

    我已将 Cypress 测试设置为在 Azure DevOps 中运行 我通过 yml 文件中的 CMD 命令运行测试 然后获取测试结果 当测试通过时 一切都按预期工作 并且测试结果显示在摘要中 当测试失败时 CMD 步骤会失败 并显示错误
  • 将cypress测试框架添加到Maven pom.xml

    尝试在 Maven 项目中使用新的 cypress 框架 文档只有一个 npm 模块设置示例 npm install cypress 和一个 package json 使用示例 如何将其转换为 Maven 依赖项中的用法 您也可以直接下载C
  • 比较日期时间函数 cypress

    我有一个表单 允许用户输入日期范围 并且输出将仅包含该特定日期的结果 我可以使用 type 函数将日期输入到表单中 但是 我不确定如何检查结果是否在指定的范围内 例如 如果输入的日期是 17 03 2019 我应该能够使用这样的代码检查表中
  • 使用 Cypress 移动滑块

    我有一个来自 rc slider 的 Slider 组件 我需要 Cypress 来设置它的值
  • 如何设置“npm install”期间使用的环境变量?

    我们的合作网络非常封闭 所以正常的方法是 npm install email protected cdn cgi l email protection 不起作用 因为它被代理阻止 我们需要提供参数CYPRESS INSTALL BINARY
  • cypress 登录后等待重定向

    我正在使用 cypress 测试一个网络应用程序 我登录我的beforeEach功能 然后 在我的不同测试中 我开始cy visit mysite com url 我的问题是登录后 网站重定向到网站的特定页面 此重定向发生在cy visit
  • Cypress:如何等待所有请求完成

    我正在使用 cypress 来测试我们的 Web 应用程序 在某些页面中 有不同的端点请求被执行多次 例如GET A GET B GET A 为了等待所有请求完成并保证页面已完全加载 赛普拉斯的最佳实践是什么 我不想用很多cy wait 命
  • 将 Cypress 与 Typescript 一起使用会给我在文档 JQuery not Defined 的示例中出现“get”的类型错误

    我正在尝试按照此处找到的文档使用 Cypress 设置 Typescript https docs cypress io guides tooling typescript support Configure tsconfig json h
  • Cypress 在请求正文中使用文件进行 HTTP POST 时出错

    我从 Cypress 6 8 0 升级到 7 0 1 升级后 当 Cypress 测试之一调用此函数时 async saveTask task file const requestBody new FormData requestBody
  • Cypress 通过 console.log 和命令日志来输出

    是否可以重定向或捕获赛普拉斯浏览器日志和命令日志以输出 我读了一些 Cypress githubissues https github com cypress io cypress issues 448关于这个话题 但我不知道如何让它发挥作
  • 运行功能文件时出错:无法遍历依赖图

    我已经安装并尝试配置 Cucumber 预处理器包 以将 Cucumber 实现到现有的 cypress 框架中 但是当我去运行我的功能文件时 我收到以下错误 有任何想法吗 错误 无法遍历依赖关系图 无法从 C Source CoreDev
  • Cypress:如何模拟键盘(CTRL/SHIFT)操作

    如图所示 我在树中有这些元素 如果我按键盘中的 CTRL 并单击这些文本 我可以选择多个元素 它会提供执行某些操作的链接 使用 cypress 有什么方法可以实现此目的吗 我知道如果它是选择 我可以使用选择 在我的情况下 这些只是 ul 另
  • 使用 Cypress 进行 Auth0 身份验证

    我正在尝试为 Cypress 创建登录命令 并注意到他们关于如何执行此操作的博客与预期值不匹配Auth0反应SDK https auth0 com docs libraries auth0 react 看来他们使用了自定义的 Express
  • 如何在 Cypress 的 E2E 测试中登录 Auth0?

    我已经开始测试 React Web 应用程序 但我没有走得太远 因为我遇到了登录问题 我在用cypress https www cypress io e2e测试工具 将显示一个带有登录按钮的欢迎页面 该页面会将您重定向到auth0 http
  • 如何引用 Cypress 配置文件中的环境变量?

    我读了赛普拉斯中的环境变量 https www toolsqa com cypress environment variables in cypress 以及有关在 Cypress 运行中传递环境变量的其他文章 但是 如何引用 JSON 配
  • Cypress:在 JSON 响应中存根特定键

    我想在 Cypress 中存根以下响应 专门存根密钥ds version 可能的值为 0 1 或 2 每个值将在 UI 上显示不同的元素 fixtures user json email email protected cdn cgi l

随机推荐