cypress - 赛普拉斯:让赛普拉斯检测到您在自定义命令中调用了一个或多个 cy 命令,但返回了不同的值
问题描述
从函数(来自 command.js /Page 对象类)返回任何单个/一组值时,出现错误,因为“赛普拉斯检测到您在自定义命令中调用了一个或多个 cy 命令,但返回了不同的值。”。我搜索了不同的选项,例如“Warp”、“.then”,但没有运气。
以下是详细信息:
我的 Command.js 文件:
Cypress.Commands.add("getconstantvalue", () => {
const todaysDateTime = Cypress.moment().format('MMMDDYYYYSS')
cy.log(todaysDateTime)
return todaysDateTime
})
我想在我的驱动程序/描述西装脚本中使用这个“todaysDateTime”:
describe('The Home Page', function() {
it('successfully loads', function() {
var data = cy.getconstantvalue()
cy.log(data)
})
})
解决方案
这应该有效。您只需要将它链接到您正在使用的命令。
命令.js 文件
Cypress.Commands.add("getconstantvalue", () => {
const todaysDateTime = Cypress.moment().format('MMMDDYYYYSS')
cy.log(todaysDateTime)
return cy.wrap(todaysDateTime)
})
测试文件
describe('The Home Page', function() {
it('successfully loads', function() {
cy.getconstantvalue().then(data => {
cy.log(data);
})
})
})
推荐阅读
- java - 如何在spring boot的多个类中使用@Autowired MongoTemplate
- amazon-redshift - AWS Glue JDBC 爬虫 - 关系不存在
- r - 在 R 中创建一个 2D 网格或栅格,将所有受访者与所有变量进行比较
- javascript - 将 js 组件导入 Angular 5
- xilinx-ise - Xilinx 14.7 许可证配置管理器未运行
- aws-api-gateway - 使用 AWS API Gateway 的两种方式 SSL
- j - J中秩的概念
- oauth - PHP Google Adwords API 获取广告系列
- reactjs - 与 React 一起使用时,FaceBook 评论插件无法正确显示
- unreal-engine4 - 有没有办法将已经制作的蓝图转换为虚幻中另一个 BP 的子类?