【问题标题】:Cucumber vs Capybara黄瓜 vs 水豚
【发布时间】:2019-09-04 21:13:50
【问题描述】:

谁能解释一下这两个平台之间的区别吗?

都是BDD 的一部分,但我为什么要使用一个或另一个,或同时使用两者?

【问题讨论】:

    标签: testing rubygems cucumber capybara bdd


    【解决方案1】:

    Capybara 是一种以人类方式与网站交互的工具(例如访问 URL、单击链接、在表单中输入文本并提交)。它用于模拟用户通过网站的流程。使用 Capybara,您可以编写如下内容:

    describe "the signup process", :type => :feature do
      before :each do
        User.make(:email => 'user@example.com', :password => 'caplin')
      end
    
      it "signs me in" do
        visit '/sessions/new'
        within("#session") do
          fill_in 'Login', :with => 'user@example.com'
          fill_in 'Password', :with => 'password'
        end
        click_link 'Sign in'
        page.should have_content 'Success'
      end
    end
    

    Cucumber 是一种用于编写映射到代码中的人类可读测试的工具。有了它,你可以像这样重写上面的例子:

    Scenario: Signup process
    
    Given a user exists with email "user@example.com" and password "caplin"
    When I try to login with "user@example.com" and "caplin"
    Then I should be logged in successfully
    

    几乎纯文本的解释对于传递非开发人员很有用,但也需要映射到其中的一些代码才能实际工作(步骤定义)。

    通常,如果您正在测试一个网站,您将使用 Capybara,如果您需要与非开发人员共享这些测试,您将使用 Cucumber。这两个条件是独立的,因此您可以使用一个而不使用另一个,或者两者都使用,或者一个都不使用。

    PS: 在代码 sn-p 中也有一些 RSpec。这是必需的,因为 Cucumber 或 Capybara 本身无法测试某些东西。他们依靠 RSpec、Test::Unit 或 minitest 来完成实际的“通过或失败”工作。

    【讨论】:

      【解决方案2】:

      cucumber 是一个 BDD 工具,它以业务可读的特定领域语言表达测试场景。

      capybara 是一种用于 ROR 应用程序的自动化测试工具(经常使用)。

      在 capybara github 页面上,using capybara with cucumber 上有一个示例。

      【讨论】:

      • Capybara 并非特定于 ROR,它可用于测试以任何语言编写的网络应用程序。
      【解决方案3】:

      Cucumber 是一个通用的 BDD 工具。它对网络应用一无所知。因此 Cucumber 步骤定义调用 Capybara 以测试 Web 应用程序。

      【讨论】:

        【解决方案4】:
        |-------------------------------|-------------------------------|
        |      Cucumber                 |     Capybara                  |
        |-------------------------------|-------------------------------|
        | Test cases are more readable  | Test cases are not readable;  |
        | and written in plain english  | Capybara also wraps RSpec and |
        | text as a DSL                 | you follow the same pattern to|
        |                               | write test cases              |
        |-------------------------------|-------------------------------|
        | Easy to iterate data using    | Not easy to iterate data      |
        | tables                        |                               |
        |-------------------------------|-------------------------------|
        | Cucumber has its own runner   | Uses RSpec runner to execute  |
        |                               | tests                         |
        |-------------------------------|-------------------------------|
        | Default HTML reporter         | No default HTML reporter      |
        |-------------------------------|-------------------------------|
        | Need to learn cucumber regex  | No such concept               |
        | pattern to write step-        |                               |
        | definition which is the middle|                               |
        | man for test case and script. |                               |
        | Btw, the regex pattern is not |                               |
        | essential for all cases.      |                               |
        |-------------------------------|-------------------------------|
        | You can use the native        | (Wrapper)/Built on top of     |
        | selenium-webdriver methods    | selenium-webdriver ruby       |
        | while using Cucumber; Cucumber| library when used with        |
        | is just an additional         | selenium; it can also be used |
        | framework to your generic     | with two other drivers.       |
        | automation framework          |                               |
        |-------------------------------|-------------------------------|
        | Pure BDD framework (In theory | Traditional functional test   |
        | BDD sounds great. In practice,| model for end-to-end testing  |
        | product owners and developers |                               |
        | rarely continue to use BDD)   |                               |
        |-------------------------------|-------------------------------|
        

        【讨论】:

        • 这是一个很好的答案,但恐怕大部分都是错误的。例如 cucumber 不使用原生 selenium 组件,capybara 可以不使用 selenium,capybara 与测试用例或页面对象无关,您无需学习正则表达式来编写步骤定义等等等。关于我会建议你撤回这个答案。
        • @diabolist 感谢您的宝贵反馈;我同意几点并调整了答案;此外,还添加了实际上错过的加分。
        • Capybara is itself a wrapper around selenium-webdriver stackoverflow.com/questions/45893060/….
        • Capybara 与 RSpec(测试用例)有关;这是我不同意的两点
        • 希望您知道,您想学习的正则表达式模式很少,可以将黄瓜测试用例与脚本粘合起来。默认情况下你可以生成它,但学习它也很重要coveros.com/regular-expressions-a-setup-for-cucumber-glue-code/…
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-06
        • 2012-01-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-02-24
        • 1970-01-01
        相关资源
        最近更新 更多