0

I'm new to using Cucumber and Capybara. I've set up a test on a webpage, and run into this error when attempting to run.

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'

I'm trying to get it to make sure a box is checked in my webpage. Here is my step definition:

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

My env.rb file:

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

Here is my source code for the checkbox

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

It would also be helpful to know how to set a checkbox to checked if it doesn't pass this test.

Thanks so much to anyone who helps.

Deankh2
  • 1
  • 1

2 Answers2

1

With Capybara, you can check a checkbox like this:

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

Where 'box' can be id, name or label.

Here is the link to Capybara docs for the check method: http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Actions#check-instance_method

Strika
  • 634
  • 7
  • 12
0

if checkbox is checked then it will associate with css. That is checkbox is checked than it will have css "checked" on it.

vijay chouhan
  • 1,012
  • 8
  • 25