首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Typescript/cypress-cucumber-preprocessor :使用动态示例编写脚本大纲

Typescript/cypress-cucumber-preprocessor :使用动态示例编写脚本大纲
EN

Stack Overflow用户
提问于 2021-07-12 22:26:33
回答 1查看 158关注 0票数 0

我的问题和这个非常相似:Behave: Writing a Scenario Outline with dynamic examples。不同的是,我不使用Python。我使用Cypress处理我的小黄瓜场景(通过cypress-cucumber-preprocessor库:https://github.com/TheBrainFamily/cypress-cucumber-preprocessor)。

假设我有这个场景大纲(写在我的Jira中):

代码语言:javascript
运行
复制
Given I provide <a list of numbers> and <another list of numbers>

Then I check wether they are equals

Examples:
| list of numbers  | another list of numbers | 
| 1                | 1                       | 
| 100              | 200                     | 

我想动态设置我的数字,因为我将从REST调用中接收它们。有没有办法做到这一点?

在Python中使用behave,似乎可以使用before_feature()来实现。

场景应该是这样的:

代码语言:javascript
运行
复制
Given I provide <a list of numbers> and <another list of numbers>

Then I check wether they are equals

Examples:
| list of numbers  | another list of numbers | 
| .                | .                       | 

但我不知道如何迭代我的示例来设置它们。有可能吗?

EN

回答 1

Stack Overflow用户

发布于 2021-10-20 00:23:15

理想情况下,测试不应该是复杂的,其结果应该是固定的和预期的。因此,您可以模拟服务调用以根据您的测试返回响应。

但是,对于您的解决方案,您可以使用一些可以在开始测试之前替换的定位符。例如

代码语言:javascript
运行
复制
Given I provide <a list of numbers> and <another list of numbers>

Then I check wether they are equals

Examples:
| list of numbers  | another list of numbers | 
| %A%              | %B%                     | 

编写代码,将持有者的值替换为从REST API调用收到的响应

代码语言:javascript
运行
复制
//..
const contents = fs.readFileSync("path/of/file.feature").toString();
contents.replace("%A%", "23");
//..
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68349098

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档