[英]I Want to use variable in cucumber feature file
There are scenarios in feature files wherein I've use the text "Foo" and on click its open a new page. 在功能文件中有一些场景,其中我使用了文本“ Foo” ,然后单击它打开一个新页面。 this text sometime changes to "Foo1" or "Foo2" or to something else . 该文本有时会更改为“ Foo1”或“ Foo2”或其他内容 。 to avoid line by line change in feature file for "Foo" to "Foo1" or "Foo2" is there any way that I can globally declare variable in top/bottom of the feature file where I can set the required text in variable on fly and I shall start executing my test instantly? 为了避免在功能文件中从“ Foo”到“ Foo1”或“ Foo2”的逐行更改 ,我有什么办法可以在功能文件的顶部/底部全局声明变量,从而可以在变量中动态设置所需的文本我将立即开始执行测试?
This change exist in many feature files and around 1000 lines in feature file. 此更改存在于许多要素文件中,并且在要素文件中大约有1000行。 To get solution for this, I try on setting environment variables but I couldn't reach all the way till end this issue to solve. 为了获得解决方案,我尝试设置环境变量,但是直到解决此问题之前我一直无法解决。 So can anyone help me on this? 那么有人可以帮我吗?
Thanks in advance 提前致谢
What if you do the replacement in your step implementation instead? 如果您在步骤实现中进行替换怎么办? Then you could have the desired value in a separate file or pass it as arguments. 然后,您可以在单独的文件中获得所需的值,或者将其作为参数传递。 That way you don't need to hard code the values. 这样,您无需对值进行硬编码。
Could scenario outlines help you in any way or is the value only changing depending on external changes? 方案大纲可以以任何方式为您提供帮助吗,还是价值仅根据外部变化而变化?
My first thought was scenario outlines like @homaxto said. 我的第一个想法是场景概述,例如@homaxto。
Then I thought you might want to affect it by which system you are connected to. 然后,我想您可能想通过连接到的系统来影响它。 You can do this through configuration. 您可以通过配置来完成。 I have done this with Fig_Newton . 我已经用Fig_Newton完成了。
You can either set an environment varaible or use one in the commandline. 您可以设置环境变量,也可以在命令行中使用一个。 Or you can use @hook type tags. 或者,您可以使用@hook类型标签。 With a hook tag, you can have a tag at the top of a feature file that you can use to set a variable that affects how the steps operate (but it needs to be handled inside the step). 使用hook标签,您可以在功能文件的顶部放置一个标签,您可以使用该标签设置一个影响步骤操作方式的变量(但需要在步骤内部进行处理)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.