Max Williams
Max Williams

Reputation: 32945

cucumber/webrat: how to test if a submit button is not disabled

Just starting to use cucumber with webrat. I have these feature steps:

When /^I choose a DVD$/ do
  #just click the first one we see
  check("optional-dvds[]")
end

Then /^I should be able to place my order$/ do
  #the place my order button should be clickable
end

The button in question has this html:

<input disabled="disabled" id="submit_button" name="commit" type="submit" value="Please send this DVD">

and, when the user clicks on a dvd, some js runs and removes the disabled attribute from the button. So, the second step needs to check that it doesn't have an attribute "disabled" after doing the previous step. How do i test this? I can think of one way, of using xpath and checking that a disabled commit button doesn't exist on the page, but i'd rather do something more explicit (actually, more jquery-esqu) along the lines of (pseudocode)

$("#submit_button").attr("disabled").should be_false

or something along these lines. I know this is a horrible mashup of jquery and rspec btw :)

Upvotes: 1

Views: 2946

Answers (1)

installero
installero

Reputation: 9786

Try this one

page.should have_no_xpath "//input[@id='submit_button' and @disabled]"

or this one

page.should have_no_selector "#submit_button", :disabled => 'disabled'

Upvotes: 2

Related Questions