将命令行上的变量传递给 Cucumber 测试 [英] Passing variables on the command line to a Cucumber test

查看:14
本文介绍了将命令行上的变量传递给 Cucumber 测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图让黄瓜项目的用户名和密码不受版本控制.

I'm trying to keep usernames and passwords for a cucumber project out of version control.

有没有办法在命令行上手动将用户名和密码等变量传递给黄瓜脚本?

Is there a way to manually pass variables on the command line like usernames and passwords to a cucumber script?

我的备份计划是将它们放在一个 YML 文件中,然后将该文件添加到 gitignore 中,这样它们就不会被置于版本控制中.

My backup plan was to put them in a YML file and add that file to the gitignore so they aren't put in version control.

推荐答案

所以,我看到你对铁皮人的评论,答案是肯定的.

So, I saw your comments with the Tin Man, and answer is Yes.

cucumber PASSWORD=my_password

PASSWORD 设置为环境变量,您可以通过将其称为 ENV['PASSWORD'] 来使用它的值.例如, browser.text_field(:id => 'pwd').set ENV['PASSWORD']

PASSWORD is set as an environment variable and you can use its value by referring to it as ENV['PASSWORD']. For an example, browser.text_field(:id => 'pwd').set ENV['PASSWORD']

另一种方式是间接的.我过去所做的是传递配置文件名称,该配置文件将执行我想要的操作.因此,例如,我有一个名为 firefox 的配置文件,而 cucumber.yml 中的一个 firefox 配置文件有一个名为 BROWSER_TYPE 的变量,其值分配给了 firefox.我打开浏览器的方法使用了这个变量(BROWSER_TYPE).如果其值为 firefox,则此方法将打开 firefox 浏览器.

Another way is indirect. What I did in past was to pass profile name and that profile will do something that I want. So, for example, I have a profile name as firefox and a firefox profile in cucumber.yml has a variable named BROWSER_TYPE with its value assigned to firefox. And this variable (BROWSER_TYPE) is used by my method that opens the browser. If its value is firefox, than this method opens firefox browser.

所以,我在这里所做的是 -

So, what I did here was -

  1. 传递个人资料.配置文件的名称是 firefox
  2. firefox 配置文件在 cucumber.yml 中定义.您可以使用配置文件进行任何操作,但在这种情况下,我定义了一个名为 BROWSER_TYPE 的变量并将其值指定为 firefox.
  3. 然后我有一个使用 BROWSER_TYPE 变量并使用其值打开浏览器的方法.
  1. Pass a profile. Name of the profile is firefox
  2. firefox profile is defined in cucumber.yml. You can any thing with the profiles, but in this case, I define a variable named BROWSER_TYPE and assign its value as firefox.
  3. Then I have a method that uses BROWSER_TYPE variable and uses its value to open browser.

这些步骤的代码 -

  1. 黄瓜 -p firefox
  2. 我的 cucumber.yml 文件看起来像firefox:BROWSER_TYPE=firefox PLATFORM=beta

我打开浏览器的方法类似于 -

My method to open browser looks similar to -

@browser = Watir::Browser.new ENV['BROWSER_TYPE']

因此,理想情况下,您可以创建一个使用密码设置环境变量的配置文件,并将该配置文件名称传递给 cucumber.

So, ideally you can create a profile that sets an environment variable with password, and pass that profile name to cucumber.

这篇关于将命令行上的变量传递给 Cucumber 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆