javascript - 在 cypress 中使用机会插件
问题描述
是否可以将机会插件与 cypress.io 一起使用?
我通过 npm 将插件安装到 node_modules\chance 并编辑了 /plugins/index.js 文件,但仍然从 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)
module.exports = on => {
on("task", {
chance: require("chance"),
});
};
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
解决方案
只需使用 npm 安装 chancejs:
npm install chance
然后只需在您的测试中使用它,例如:
/// <reference types="cypress" />
import Chance from 'Chance';
const chance = new Chance();
describe('Testing chance', function (){
const company =chance.company();
it('type company in duckduckgo.com', function () {
cy.visit('https://duckduckgo.com/')
cy.get('#search_form_input_homepage')
.should('be.visible')
.type(company)
})
})
推荐阅读
- html - HTML5 CSS3 在包含图像的单元格上浮动输入文本
- mysql - 创建 Mysql 过程
- node.js - any-db-sqlite3 如何/在哪里将数据库保存到?
- matlab - 未将输出参数分配给子功能程序时如何解决
- android - ObjectAnimator,如何移动对象两次?
- spring - 如何分别为多个控制器在多个文件中编写Spring Boot测试用例
- caching - 创建/更新/删除后如何清除 .Net Core 上的响应缓存?
- angular - Angular 6将行转换为多列
- magento - 导入产品未显示在前端页面上
- angular - 未在 POST 响应中设置标头