简体   繁体   English

如何使用正则表达式从黄瓜功能文件中提取特定场景

[英]How to pull a specific scenario from a cucumber feature file using regex

I have a cucumber feature file that contains multiple scenarios and each has a different And. 我有一个包含多个方案的黄瓜功能文件,每个方案都有一个不同的“与”。 I am using Java regex to parse the file and want to pull out a specific scenario based on the text in the And. 我正在使用Java regex解析文件,并希望根据And中的文本提取特定的方案。

For example: 例如:

Feature: testing stuff 功能:测试的东西

Scenario: 场景:

lady swallows fly Given a lady and lady swallows a "fly" then lady lives 燕子飞小姐假定一位女士和一位燕子飞“蝇”,女士就住了

Scenario: 场景:

lady swallows spider Given a lady and lady swallows a "fly","spider" then lady lives 女士吞下蜘蛛假设女士和女士吞下“蝇”,“蜘蛛”,则女士生活

Scenario: 场景:

lady swallows everything Given a lady and lady swallows a "fly","spider","cat","dog","cow" then lady Dies 女士吞下所有东西假设女士吞下了“蝇”,“蜘蛛”,“猫”,“狗”,“牛”,然后女士死了

Scenario: 场景:

lady swallows everything except the dog Given a lady and lady swallows a "fly","spider","cat","cow" then lady Dies 女士吞下除狗以外的所有东西给女士,女士吞下“蝇”,“蜘蛛”,“猫”,“牛”,然后女士死

I want to pull out the scenario that contains dog and dump it in a separate file. 我想拉出包含dog的场景并将其转储到单独的文件中。 In my real life dog=account number and associates to multiple SQL extracts which are auto-loaded into a local database. 在我的现实生活中, dog=account number并且与多个SQL提取关联,这些提取自动加载到本地数据库中。 This is a single scenario, in a single feature file, which is one of hundreds. 这是单个功能文件中的单个方案,该文件是数百个文件中的一个。 So it's not a simple case of using @run at the top of the scenario. 因此,在方案顶部使用@run不是一个简单的情况。 I am actually extracting the scenario and associated files so they can be put in a sandbox. 我实际上是在提取场景和相关文件,以便可以将它们放在沙箱中。

The regex that I have so far is: 到目前为止,我拥有的正则表达式是:

.*?dog.*Scen

but that selects from the first instance of Scenario into the Scenario beyond what I want. 但这会从场景的第一个实例中选择超出我想要的场景。

Instead I want to pull out the group: 相反,我想退出小组:

Scenario: 场景:

lady swallows everything Given a lady and lady swallows a "fly","spider","cat","dog","cow" then lady Dies 女士吞下所有东西假设女士吞下了“蝇”,“蜘蛛”,“猫”,“狗”,“牛”,然后女士死了

Does anyone know how I can pull out that group? 有谁知道我可以退出那个小组吗?

If scenarios are delimited by \\n, try with: 如果方案用\\ n分隔,请尝试:

^[^\n]+\bdog\b[^\n]+

DEMO DEMO

if it is contiuous string, try with: 如果是连续字符串,请尝试:

(?=Scenario).+?\bdog\b.+?(?=Scenario|$)

DEMO DEMO

暂无
暂无

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

相关问题 cucumber:如何从特定功能文件运行标记场景 - cucumber: how to run a tagged scenario from a specific feature file 黄瓜:如何从功能文件运行特定方案 - cucumber: how to run specific scenario from a feature file 如何将 Cucumber 功能文件中的场景名称作为 Cucumber 步骤中的参数传递? - How to pass Scenario name from the Cucumber feature file as a parameter in the Cucumber steps? 如何在运行时使用带有 io.cucumber 的最新黄瓜版本从特征文件中读取黄瓜特征名称 - How to read cucumber feature name from feature file during runtime using latest cucumber version with io.cucumber 如何使用java从黄瓜的场景大纲中获取场景名称 - How to get scenario name from a scenario outline in cucumber using java 如何将特定的java文件与黄瓜中的特定功能文件进行匹配 - How to match a specific java file with specific feature file in cucumber 如何从Jenkins读取Cucumber功能文件 - How to read Cucumber feature file from Jenkins 如何在 Cucumber 特征文件中创建 data.table 以及我的场景的步骤定义 - How to create data table in Cucumber feature file and step definition for my scenario 如何通过Jenkins定位特定的黄瓜功能文件(自动化测试)? - How to target a specific Cucumber Feature File (Automation Test) via Jenkins? 如何从功能文件 FB 的场景 SB 调用功能文件 FA 的场景 SA 中的变量? - How do I call a variable in scenario SA of feature file FA from a scenario SB of a feature file FB?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM