简体   繁体   English

我想在黄瓜特征文件中使用变量

[英]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.

相关问题 我想使用 Android studio webview 从本地主机打开一个 .html 文件,但文件名将是一个变量 - I want to use Android studio webview to open an .html file from local host, but the name of the file will be a variable 功能文件无法识别Kotlin中的黄瓜步骤实施 - Cucumber steps implementation in kotlin isn't recognized in feature file 我想使用linkedIn api使用SocialAuth在我的Android应用程序中实现具有链接功能的登录 - I want to use linkedIn api to implement login with linked feature in my android app using SocialAuth “未使用局部变量SoundButton38的值”,但我想使用它吗? - “The value of the local variable SoundButton38 is not used” But I Want To Use It? 我想将 Fragment 类中的变量用于 Home 类 - I want to use variable in Fragment class to Home class 我想使用 LazyVerticalGrid - I want to use LazyVerticalGrid 如何在不同的iOS和Android设备(Appium)上并行执行黄瓜功能文件? - How to execute cucumber feature file parallel on different iOS and Android devices (Appium)? 我想请求一个可变地址 - I want to request a variable address 我想在我的Android应用程序中添加“将图片共享到Facebook”功能吗? - i want to add “share the image to Facebook” feature in my android application? 我想在Android视图中创建此iphone tableview功能吗? - i want to create this iphone tableview feature same in android view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM