【问题标题】:Cypress with BDD Cucumber how to create my own data typeCypress 与 BDD Cucumber 如何创建我自己的数据类型
【发布时间】:2022-01-21 22:50:44
【问题描述】:

我将 cypress 与 cucumber-js 一起使用,我需要定义自己的数据类型。我做了与https://github.com/TheBrainFamily/cypress-cucumber-preprocessor#custom-parameter-type-resolves 中描述的完全相同的事情。

这意味着: 赛普拉斯 > 支持 > step_definitions > customParameterTypes.js 我写道:

const blogType = ["sport", "gaming"]

defineParameterType({
    name: "blogType",
    regexp: new RegExp(blogType.join("|"))
})

在我的 BDD .feature 文件中,我有:

Given I have empty blog
And  Blog has default structure for sport

在我的柏树文件中:

Given(' Blog has default structure for {blogType}', blogType => {...})

当我开始测试时,我得到:

The following error originated from your test code, not from Cypress.

  > Undefined parameter type {blogType}

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

【问题讨论】:

  • 在您的defineParameterType() 中,您在steps 上使用.join(),但我没有在您共享的代码中看到steps 声明。
  • @PeaceAndQuiet 啊...抱歉...只是从代码中复制错误...编辑...但它仍然是同样的问题。

标签: cucumber cypress bdd cypress-cucumber-preprocessor user-defined-data-types


【解决方案1】:

由于某些原因,我过去在使用 defineParameterType() 时遇到了问题,现在我在所有 BDD 项目中都使用了正则表达式。

在您的.js 文件中:

Given(/^Blog has default structure for (sport|gaming)$/, blogType => {...});

使用上述方法,您将不需要 customParameterTypes.js 并且您的 .feature 文件保持不变。

【讨论】:

  • 是的..但是当我需要该类型以执行更多步骤并且我不确定该类型将只有 2 个选项时...然后将其写为正则表达式会很烦人一遍又一遍
猜你喜欢
  • 2022-07-28
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 2021-12-27
  • 1970-01-01
  • 2014-08-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多