Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use Capybara to test that a form element is disabled when using jQuery's prop method?

In my Rails 3 app, I've been using jQuery's attr() method to do things like this:

$('#application_dust_type_id').attr('disabled', 'disabled');

I would use Test/Unit, capybara and capybara-webkit to test this with:

assert page.has_selector? 'select[id=application_dust_type_id][disabled=disabled]'

Now, I'm trying to switch to using the prop method, as jQuery recommends:

$('#application_dust_type_id').prop('disabled', true)

But now the above assertion fails, even though the javascript still works the same in the browser.

How can I make an assertion based on an element's property (instead of an attribute) using capybara?

like image 781
croceldon Avatar asked Dec 19 '12 14:12

croceldon


1 Answers

Try just checking for the existance of a disabled attribute as that is all that is really required to disable an input:

assert page.has_selector? 'select[id=application_dust_type_id][disabled]'

Note that the value of a disabled attribute is moot. You could set disabled="false" or disabled="foobar" and the element would be rendered as disabled.

like image 123
Rory McCrossan Avatar answered Nov 03 '22 01:11

Rory McCrossan