简体   繁体   English

如何使用方案大纲运行相关的黄瓜方案

[英]How to run dependent cucumber scenarios with scenario outline

I want to use Cucumber to test my application which takes snapshots of external websites and logs changes. 我想使用Cucumber测试我的应用程序,该应用程序可以获取外部网站的快照并记录更改。 I already tested my models separatly using RSpec and now want to make integration tests with Cucumber. 我已经使用RSpec分别测试了我的模型,现在想与Cucumber进行集成测试。 For mocking the website requests I use VCR. 为了模拟网站请求,我使用VCR。

My tests usually follow a similar pattern: 我的测试通常遵循类似的模式:
1. Given I have a certain website content (I do this using VCR cassettes) 1.鉴于我有一定的网站内容(我使用VCR盒式磁带执行此操作)
2. When I take a snapshot of the website 2.拍摄网站快照时
3. Then there should be 1 "new"-snapshot and 1 "new"-log messages 3.然后应该有1条“新”快照和1条“新”日志消息

Depending if the content of the website changes, a "new"-snapshot should be created and a "new"-log message should be created. 根据网站内容是否更改,应创建“新”快照,并应创建“新”日志消息。 If the content stays the same, only a "old"-log message should be created. 如果内容保持不变,则仅应创建“旧”日志消息。 This means, that the the application's behaviour depends on the current existing snapshots. 这意味着,应用程序的行为取决于当前现有的快照。
This is why I would like to run the different scenarios without resetting the DB after each row. 这就是为什么我想运行不同的场景而不在每一行之后都重置数据库的原因。

Scenario Outline: new, new, same, same, new
    Given website with state <website_state_1>
    When I take a snapshot
    Then there should be <1> "new"-snapshot and <1> "old"-log messages and <1> "new"-log messages

Examples:
| state | snapshot_new | logmessages_old | logmessages_new |
| VCR_1 |       1      |         0       |         1       |
| VCR_2 |       2      |         0       |         2       |
| VCR_3 |       2      |         1       |         2       |
| VCR_4 |       2      |         2       |         2       |
| VCR_5 |       3      |         2       |         3       |

However, the DB is resetted after each scenario is run. 但是,在每种情况下运行后都会重置数据库。 And I think that scenario outline was never intended to be used like this. 而且我认为该方案大纲绝不打算像这样使用。 Scenarios should be independent from each other, right? 场景应该彼此独立,对吗? Am I doing something wrong trying to solve my problem in this way? 我在尝试以这种方式解决问题时做错了吗? Can/should scenario outline be used for that or is there another elegant way to do this? 可以/应该使用方案大纲吗?还是有另一种优雅的方式来做到这一点?

J. J.

Each line in the Scenario Outline Examples table should be considered one individual Scenario. Scenario Outline Examples表中的每一行都应被视为一个单独的方案。 Scenarios should be independent from each other. 方案应彼此独立。 If you need a scenario to depend on the system being in a certain state, you'll need to set that state in the Given . 如果您需要一个方案来依赖系统处于特定状态,则需要在Given设置该状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 并行运行黄瓜方案大纲 - Running cucumber scenario outline in parallel 具有特殊字符的黄瓜方案大纲 - Cucumber Scenario Outline with Special Characters 如何使黄瓜测试中的“方案大纲”中的“示例”中的多行字符串起作用? - How to get multiline strings in Examples in Scenario Outline in cucumber tests to work? 我如何才能在黄瓜中最好地表达这种与时间相关的情景? - How would I best express this time-dependent scenario in Cucumber? 如何从Ruby黄瓜方案大纲中生成可通过黄瓜报告正确使用的结果? - How to generate results from a Ruby Cucumber Scenario Outline that can be properly consumed by cucumber-reporting? 多变量方案大纲示例的黄瓜转换 - Cucumber Transforms for Multiple Variable Scenario Outline Examples 黄瓜场景大纲输入值中带引号 - Cucumber scenario outline input with quotes in the value 黄瓜方案大纲中的换行符导致错误 - Newline character in cucumber scenario outline causing error 仅在选定的黄瓜方案之后如何运行挂接? - How to run a hook only after selected Cucumber scenarios? 带有示例表的“方案大纲”的黄瓜输出的实时格式 - Realtime formatting of cucumber output for 'Scenario Outline' with example table
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM