0

Cucumber と Capybara を初めて使用します。Web ページでテストをセットアップしましたが、実行しようとするとこのエラーが発生します。

undefined method `locate' for #<Webrat::Session:0x007fdf2ac41c18> (NoMethodError)
  ./Documents/Work:etc./Raster Media/Cucumber/Klinq Testing/1/features/step_definitions/steps.rb:14:in `/^I make sure the (.*) box is checked$/'
  ./Documents/Work:etc./Raster Media/Cucumber/Klinq Testing/1/features/account.feature:16:in `And I make sure the vendor[tos] box is checked'

私のウェブページでボックスがチェックされていることを確認するためにそれを取得しようとしています。これが私のステップ定義です:

When /^I make sure the (.*) box is checked$/ do |box|
locate(:css, 'box').set(true)

私のenv.rbファイル:

require 'rspec/expectations'
require 'test/unit/assertions'
require 'capybara'
require 'webrat'
World(Test::Unit::Assertions)
Webrat.configure do |config|
config.mode = :mechanize
end
World do
session = Webrat::Session.new
session.extend(Webrat::Methods)
session.extend(Webrat::Matchers)
session
end

チェックボックスのソースコードは次のとおりです

<input type="checkbox" name="vendor[tos]" value="1" id="vendor[tos]" class="one left">

また、このテストに合格しない場合にチェックボックスをオンに設定する方法を知っておくと役立ちます。

助けてくれた人に感謝します。

4

2 に答える 2

1

Capybara では、次のようにチェックボックスをオンにできます。

    When /^I make sure the (.*) box is checked$/ do |box|
      check(box)
    end

'box' は ID、名前、またはラベルです。

チェック方法のカピバラドキュメントへのリンクは次のとおりです。

于 2013-02-10T16:40:32.823 に答える
0

チェックボックスがチェックされている場合、それはcssに関連付けられます。これは、cssが「チェック」されるよりもチェックボックスがチェックされていることです。

于 2013-01-22T13:06:45.133 に答える