在非轨道黄瓜测试中使用环境变量
我为运行 java/tomcat/jahia (cms) 的门户创建了一个简单的烟雾测试,该门户以缓存服务器和大 IP 为前端。 Cucumber + Webrat + Mechanize 非常适合对此设置进行简单的冒烟测试。 (而且上手非常容易)。
现在,我已将以下几行硬编码到 /features/support/paths.rb 中:
module NavigationHelpers
#PATH="http://production-environment"
#PATH="http://staging-environment"
#PATH="http://test-environment"
PATH="http://localhost:8080"
#
def path_to(page_name)
case page_name
when /the homepage/
"#{PATH}/"
when [...]
...
end
end
end
World(NavigationHelpers)
现在,当我想测试不同的环境时,我手动切换注释。这里的问题是我想摆脱常量 PATH 并将默认值放入其中一个支持文件中。我还希望能够从命令行向黄瓜提供此环境变量,如下所示:
cucumber ENV=staging
您如何处理这个问题?有什么建议吗?处理这个问题的代码链接?片段?
I created a simple smoketest for a portal running java/tomcat/jahia (cms) fronted by cache servers and big ip. Cucumber + Webrat + Mechanize is a good fit for a simple smoketest of this setup. (and it has been very easy to get started).
Right now I have hardcoded into /features/support/paths.rb the following lines:
module NavigationHelpers
#PATH="http://production-environment"
#PATH="http://staging-environment"
#PATH="http://test-environment"
PATH="http://localhost:8080"
#
def path_to(page_name)
case page_name
when /the homepage/
"#{PATH}/"
when [...]
...
end
end
end
World(NavigationHelpers)
Right now I manually switch the comments when I want to test different environments. The issue here is I'd love to get rid of the constant PATH and put a default value inside one of the support files. And i also want to be able to feed cucumber with this environment variable from the command line like so:
cucumber ENV=staging
How do you cope with this issue? Any suggestions? Links to code that deals with this? Snippets?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将环境变量传递给 Cucumber,就像使用 ENV 一样。每个环境变量都将在 Ruby 的 ENV 常量中可用。更多详细信息请参见Wiki
(我刚刚添加了此页面 - 该功能已大约从 0.3.90 开始,但仅在 History.txt 文件中提到过)。
You can pass environment variables to Cucumber like you have done with ENV. Each environment vriable will then be available in Ruby's ENV constant. More details in the Wiki
(I just added this page - the feature has been around since 0.3.90 but was only ever mentioned in the History.txt file).