在非轨道黄瓜测试中使用环境变量

发布于 2024-08-14 23:03:38 字数 738 浏览 3 评论 0原文

我为运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

等你爱我 2024-08-21 23:03:38

您可以将环境变量传递给 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文