【问题标题】:Matching input tag with Cucumber/Webrat将输入标签与 Cucumber/Webrat 匹配
【发布时间】:2010-10-28 02:05:57
【问题描述】:

我正在学习 Cucumber,但我无法仅匹配输入标签。

我在视图中看到的是

<input type="submit" value="Press!" />

而我在 Cucumber 中尝试的是

Then the "input" field should contain "Press!"
Then the "type" field should contain "submit"

我只想确认具有某些值的输入标签的存在。没有互动。

【问题讨论】:

    标签: ruby-on-rails cucumber webrat


    【解决方案1】:

    试试这个:

    Then I should see "Press!" within "input[type=\"submit\"]"

    【讨论】:

    • 谢谢。对我来说很奇怪,没有一个框架有简单的方法来检查表单元素的存在。
    【解决方案2】:

    webrat 也明确支持它们。即使您在 cucumber 中找不到内置支持,您也可以随时放入自己的步骤定义中。

    来源:http://cheat.errtheblog.com/s/webrat/

    == Assertions
    
       # check for text in the body of html tags
       # can be a string or regexp
      assert_contain("BURNINATOR")
      assert_contain(/trogdor/i)
      assert_not_contain("peasants")
    
      # check for a css3 selector
      assert_have_selector 'div.pagination'
      assert_have_no_selector 'form input#name'
    
    
    == Matchers
    
      # check for text in the body of html tags
      # can be a string or regexp
      # Matchers are verbs used with auxillary verbs should, should_not, etc.
      response.should contain("BURNINATOR")
      response.should contain(/trogdor/i)
      response.should_not contain("peasants")
    
      # check for a css3 selector
      response.should have_selector('div.pagination')
      response.should_not have_selector('form input#name')
    

    【讨论】:

    • 我通过搜索“trogdor”找到了这个。太糟糕了,伙计!
    【解决方案3】:

    你可以使用类似的东西:

    response.should have_xpath("//input[@value='Press!']")
    

    response.should have_selector("input", :type => "submit", :value => "Press!")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-01
      • 1970-01-01
      • 2018-10-13
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2010-11-19
      • 1970-01-01
      相关资源
      最近更新 更多