Skip to content

Commit

Permalink
Merge pull request #948 from benlovell/add_element_disabled
Browse files Browse the repository at this point in the history
Add element disabled?
  • Loading branch information
jnicklas committed Feb 15, 2013
2 parents 4e7d8e2 + be23d96 commit f17b37b
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 2 deletions.
4 changes: 4 additions & 0 deletions lib/capybara/driver/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def selected?
raise NotImplementedError
end

def disabled?
raise NotImplementedError
end

def path
raise NotSupportedByDriverError
end
Expand Down
10 changes: 10 additions & 0 deletions lib/capybara/node/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,16 @@ def selected?
synchronize { base.selected? }
end

##
#
# Whether or not the element is disabled.
#
# @return [Boolean] Whether the element is disabled
#
def disabled?
synchronize { base.disabled? }
end

##
#
# An XPath expression describing where on the page the element can be found
Expand Down
9 changes: 9 additions & 0 deletions lib/capybara/node/simple.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ def checked?
native[:checked]
end

##
#
# Whether or not the element is disabled.
#
# @return [Boolean] Whether the element is disabled
def disabled?
native[:disabled]
end

##
#
# Whether or not the element is selected.
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/rack_test/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ def selected?
string_node.selected?
end

def disabled?
string_node.disabled?
end

def path
native.path
end
Expand Down
4 changes: 4 additions & 0 deletions lib/capybara/selenium/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ def selected?
selected and selected != "false"
end

def disabled?
!native.enabled?
end

alias :checked? :selected?

def find(locator)
Expand Down
8 changes: 8 additions & 0 deletions lib/capybara/spec/session/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,14 @@
end
end

describe "#disabled?" do
it "should extract disabled node" do
@session.visit('/form')
@session.find('//input[@id="customer_name"]').should be_disabled
@session.find('//input[@id="customer_email"]').should_not be_disabled
end
end

describe "#visible?" do
it "should extract node visibility" do
@session.first('//a').should be_visible
Expand Down
11 changes: 11 additions & 0 deletions lib/capybara/spec/views/form.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,19 @@
<option>Mr</option>
<option>Miss</option>
</select>
</p>

<p>
<label for="customer_name">Customer Name
<input type="text" name="form[customer_name]" value="Blah" id="customer_name" disabled="disabled"/>
</label>
</p>

<p>
<label for="customer_email">Customer Email
<input type="text" name="form[customer_email]" value="ben@ben.com" id="customer_email"/>
</label>
</p>

<p>
<label for="form_other_title">Other title</label>
Expand Down
14 changes: 12 additions & 2 deletions spec/basic_node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
<p>Yes it is</p>
</div>
<form>
<input type="text" name="bleh" disabled="disabled"/>
<input type="text" name="meh"/>
</form>
<div id="footer" style="display: none">
<p>c2010</p>
<p>Jonas Nicklas</p>
Expand Down Expand Up @@ -77,13 +82,18 @@
end

it "allows finding elements and extracting the path" do
string.find('//input').value.should == 'bar'
string.find('//div/input').value.should == 'bar'
string.find('//select').value.should == 'Capybara'
end

it "allows finding elements and checking if they are visible" do
string.find('//h1').should be_visible
string.find('//input').should_not be_visible
string.find('//div/input').should_not be_visible
end

it "allows finding elements and checking if they are disabled" do
string.find('//form/input[@name="bleh"]').should be_disabled
string.find('//form/input[@name="meh"]').should_not be_disabled
end
end
end

0 comments on commit f17b37b

Please sign in to comment.